* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.4;
  max-width: 800px;
  margin: 0 auto;
  padding: 12px;
  background: #f5f5f5;
  color: #333;
}

header {
  text-align: center;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
}

h1 a {
  color: inherit;
  text-decoration: none;
}

h1 a:hover {
  text-decoration: underline;
}

.subtitle {
  color: #666;
  margin: 5px 0 0;
}

.hidden {
  display: none !important;
}

/* Landing form */
#gist-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 500px;
  margin: 0 auto;
}

#gist-form label {
  font-weight: 500;
}

#gist-form input {
  padding: 12px;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

#gist-form button {
  padding: 12px 20px;
  font-size: 1rem;
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#gist-form button:hover {
  background: #0055aa;
}

.help-text {
  text-align: center;
  color: #666;
  font-size: 0.9rem;
  margin-top: 20px;
}

.help-text code {
  background: #e0e0e0;
  padding: 2px 6px;
  border-radius: 3px;
}

/* Loading */
#loading {
  text-align: center;
  padding: 40px;
  color: #666;
}

/* Error */
#error {
  text-align: center;
  padding: 40px;
}

.error-message {
  color: #cc0000;
  margin-bottom: 20px;
}

/* Viewer header */
.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.viewer-actions {
  display: flex;
  gap: 8px;
}

.filter-toggle {
  font-size: 0.75rem;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  user-select: none;
  margin: 0;
  padding: 0;
}

.filter-toggle input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
}

#gist-link,
#copy-url,
.annotate-toggle {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: #e0e0e0;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

#gist-link:hover,
#copy-url:hover,
.annotate-toggle:hover {
  background: #d0d0d0;
}

/* Annotation mode toggle button */
.annotate-toggle.active {
  background: #ff9800;
  color: white;
}

.annotate-toggle.active:hover {
  background: #f57c00;
}

/* Conversation */
#conversation {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.message-label {
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 45px;
  flex-shrink: 0;
  padding-top: 2px;
}

.message-bubble {
  flex: 1;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.code-block {
  display: block;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.85em;
  background: rgba(0,0,0,0.04);
  padding: 4px 6px;
  border-radius: 3px;
  margin: 4px 0;
}

/* Tables in markdown */
.message-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.9em;
  width: 100%;
}

.message-bubble th,
.message-bubble td {
  border: 1px solid #ddd;
  padding: 6px 10px;
  text-align: left;
}

.message-bubble th {
  background: #f5f5f5;
  font-weight: 600;
}

.message-bubble tr:nth-child(even) {
  background: #fafafa;
}

/* Inline code */
.message-bubble code:not(.code-block) {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.9em;
}

/* Pre blocks for fenced code */
.message-bubble pre {
  margin: 8px 0;
  padding: 0;
  background: none;
}

/* User messages */
.message-row.user .message-label {
  color: #1565c0;
}

.message-row.user .message-bubble {
  background: #e3f2fd;
}

/* Assistant messages */
.message-row.assistant .message-label {
  color: #2e7d32;
}

.message-row.assistant .message-bubble {
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Hide Claude output when filter is active */
#conversation.hide-claude .message-row.assistant,
#conversation.hide-claude .tool-block {
  display: none;
}

/* Selected state for keyboard nav */
.message-row.selected .message-bubble,
.tool-block.selected {
  outline: 2px solid #0066cc;
  outline-offset: 1px;
}

/* Tool blocks */
.tool-block {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.tool-summary {
  padding: 4px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #666;
  font-size: 0.8rem;
}

.tool-summary:hover {
  background: #f0f0f0;
}

.tool-toggle {
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.tool-block.expanded .tool-toggle {
  transform: rotate(90deg);
}

.tool-details {
  display: none;
  padding: 8px;
  border-top: 1px solid #ddd;
  background: #fff;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

.tool-block.expanded .tool-details {
  display: block;
}

/* Snip markers */
.snip {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 4px;
  font-size: 0.8rem;
}

/* Footer */
footer {
  text-align: center;
  padding: 40px 0;
  margin-top: 40px;
  font-size: 0.85rem;
}

footer a {
  color: #aaa;
  text-decoration: none;
}

footer a:hover {
  color: #888;
}

.footer-sep {
  color: #ccc;
  margin: 0 8px;
}

/* Annotation styles */
.selectable {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.selectable:hover {
  background-color: rgba(255, 235, 59, 0.1);
}

.selecting {
  background-color: rgba(255, 235, 59, 0.3) !important;
  border-left: 3px solid #ffc107 !important;
}

.annotated {
  border-left: 3px solid #ff9800;
  background-color: rgba(255, 152, 0, 0.08);
}

.annotated.message-row .message-bubble {
  background-color: rgba(255, 152, 0, 0.12);
}

.annotation-block {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-left: 4px solid #ff9800;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 4px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.annotation-content {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
}

.annotation-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.annotation-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.9rem;
  color: #5d4037;
  line-height: 1.4;
}

.annotation-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.annotation-actions button {
  padding: 2px 8px;
  font-size: 0.75rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
  color: #666;
}

.annotation-actions button:hover {
  background: #f5f5f5;
  border-color: #999;
}

.annotation-edit:hover {
  color: #1565c0;
}

.annotation-delete:hover {
  color: #c62828;
}

/* Annotation input form */
.annotation-input-container {
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 4px;
  padding: 12px;
  margin: 6px 0;
}

.annotation-input-container textarea {
  width: 100%;
  padding: 8px;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
  font-family: inherit;
}

.annotation-input-container textarea:focus {
  outline: none;
  border-color: #ff9800;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.2);
}

.annotation-input-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.annotation-btn {
  padding: 6px 16px;
  font-size: 0.85rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.annotation-btn.save {
  background: #ff9800;
  color: white;
}

.annotation-btn.save:hover {
  background: #f57c00;
}

.annotation-btn.cancel {
  background: #e0e0e0;
  color: #333;
}

.annotation-btn.cancel:hover {
  background: #d0d0d0;
}

/* Responsive */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .message-label {
    width: 38px;
    font-size: 0.65rem;
  }

  .message-bubble {
    padding: 4px 6px;
  }

  /* Hide annotation toggle on mobile (view-only) */
  .annotate-toggle {
    display: none;
  }
}
