/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand palette */
  --primary:    #3561de;
  --secondary:  #7a99f3;
  --accent:     #4c79fa;
  --text:       #030408;

  /* Surface scale */
  --bg:         #f9fafd;
  --surface:    #ffffff;
  --surface-2:  #f3f5fb;
  --surface-3:  #eaecf5;
  --surface-4:  #dde2f4;

  /* Borders */
  --border:     #e2e6f3;
  --border-2:   #cdd4eb;
  --border-3:   #b8c2e0;

  /* Accent derivations */
  --accent-dim:   rgba(76, 121, 250, 0.1);
  --accent-glow:  rgba(76, 121, 250, 0.18);
  --accent-text:  #2a4fb8;
  --accent-light: #6b8ef7;

  /* Text scale */
  --text-2:     #4a5270;
  --text-3:     #8890b0;
  --text-4:     #b0b8d0;

  /* Semantic */
  --green:      #059669;
  --green-dim:  #d1fae5;
  --green-text: #065f46;
  --amber:      #d97706;
  --amber-dim:  #fef3c7;
  --red:        #dc2626;
  --red-dim:    #fee2e2;
  --red-text:   #991b1b;

  /* Layout */
  --header-h:   52px;
  --sidebar-w:  220px;
  --threads-w:  300px;
  --radius:     8px;
  --radius-sm:  6px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 3px rgba(53, 97, 222, 0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:     0 4px 16px rgba(53, 97, 222, 0.1), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg:  0 12px 40px rgba(53, 97, 222, 0.14), 0 4px 12px rgba(0,0,0,0.08);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.header-left  { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.header-center { position: absolute; left: 50%; transform: translateX(-50%); }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.logo {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo svg { color: var(--accent); }

.doc-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.doc-meta-divider {
  width: 1px;
  height: 16px;
  background: var(--border-2);
  flex-shrink: 0;
}

.doc-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.badge-version {
  background: var(--accent-dim);
  color: var(--accent-text);
  border: 1px solid rgba(76, 121, 250, 0.2);
}

/* ── Mode toggle ─────────────────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.mode-btn:hover { color: var(--text-2); background: var(--surface-3); }

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 6px rgba(53, 97, 222, 0.3);
}

.mode-kbd {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-2);
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  align-self: center;
  margin-left: 2px;
  cursor: default;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
  box-shadow: 0 1px 6px rgba(53, 97, 222, 0.25);
}
.btn-primary:hover { background: var(--accent); box-shadow: 0 2px 12px rgba(76, 121, 250, 0.35); }
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-3); background: var(--surface-2); }

.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.btn-primary-sm:hover { background: var(--accent); }

.btn-ghost-sm {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.btn-ghost-sm:hover { color: var(--text); background: var(--surface-2); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
  transition: color 0.15s;
}
.link-btn:hover { color: var(--accent); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app-body {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-top {
  flex: 1;
  overflow-y: auto;
  padding: 14px 0 8px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-4);
  text-transform: uppercase;
  padding: 0 14px 10px;
}

.doc-list { display: flex; flex-direction: column; }

.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.doc-item:hover { background: var(--surface-2); }
.doc-item.active { background: var(--accent-dim); }
.doc-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.doc-item-icon { color: var(--text-4); flex-shrink: 0; display: flex; }
.doc-item.active .doc-item-icon { color: var(--primary); }

.doc-item-info { min-width: 0; flex: 1; }
.doc-item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.doc-item.active .doc-item-name { color: var(--primary); }

.doc-item-meta {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 2px;
}
.doc-item-meta .has-open { color: var(--primary); font-weight: 600; }

.doc-item-del {
  background: none;
  border: none;
  color: var(--text-4);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: flex;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
.doc-item:hover .doc-item-del { opacity: 1; }
.doc-item-del:hover { color: var(--red); }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  flex-shrink: 0;
  background: var(--surface-2);
}

.mcp-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 5px;
}

.mcp-badge-btn {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  margin: -4px -6px 1px;
  transition: background 0.1s;
}
.mcp-badge-btn:hover { background: var(--surface-3); }

.mcp-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 5px rgba(5, 150, 105, 0.5);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.mcp-hint { font-size: 10px; color: var(--text-3); line-height: 1.5; }

/* ── Preview panel ───────────────────────────────────────────────────────── */
#preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 30% 40%, rgba(76, 121, 250, 0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 65%, rgba(53, 97, 222, 0.04) 0%, transparent 55%);
}

.empty-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 40px;
  border: 1.5px dashed var(--border-2);
  border-radius: 20px;
  text-align: center;
  max-width: 380px;
  transition: all 0.2s ease;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.empty-content.drag-over {
  border-color: var(--primary);
  background: rgba(76, 121, 250, 0.03);
  box-shadow: 0 0 0 4px rgba(76, 121, 250, 0.1);
}

.empty-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-dim);
  border: 1px solid rgba(76, 121, 250, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 4px;
}

.empty-content h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.empty-content p {
  font-size: 13px;
  color: var(--text-2);
}

.empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}

.chip {
  font-size: 10px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-3);
}

/* ── Preview wrapper ─────────────────────────────────────────────────────── */
#preview-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 1px 0 0 var(--border);
}

#preview-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.comment-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none; /* cursor + click now handled by injected iframe script */
}

#pins-container {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

/* ── Comment pins ────────────────────────────────────────────────────────── */
.pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 2.5px solid #fff;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 2px 8px rgba(53, 97, 222, 0.4), 0 0 0 0 rgba(53, 97, 222, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 1;
  font-family: 'Inter', sans-serif;
}

.pin:hover {
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 4px 16px rgba(53, 97, 222, 0.5), 0 0 0 6px rgba(53, 97, 222, 0.1);
}

.pin.selection-pin {
  border-radius: 6px;
  width: auto;
  min-width: 28px;
  padding: 0 6px;
  height: 22px;
  font-size: 9px;
}

.pin.resolved {
  background: var(--surface-3);
  border-color: var(--border-2);
  color: var(--text-3);
  opacity: 0.45;
  box-shadow: none;
}

.pin-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: 11px;
  color: #fff;
  white-space: normal;
  max-width: 200px;
  pointer-events: none;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 100;
  text-align: left;
  line-height: 1.4;
}

.pin:hover .pin-tooltip { opacity: 1; }

/* ── Comment popup ───────────────────────────────────────────────────────── */
.comment-popup {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 14px;
  width: 260px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.popup-type-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.selection-preview {
  background: var(--surface-2);
  border-left: 2px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.4;
  max-height: 60px;
  overflow: hidden;
  font-style: italic;
}

.comment-popup textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  resize: none;
  padding: 9px 11px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}

.comment-popup textarea:focus { border-color: var(--primary); }
.comment-popup textarea::placeholder { color: var(--text-3); }

.popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

/* ── Selection tooltip ───────────────────────────────────────────────────── */
.selection-tooltip {
  position: absolute;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  border-radius: 99px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.selection-tooltip:hover {
  background: var(--accent);
  box-shadow: 0 4px 16px rgba(76, 121, 250, 0.4);
  transform: translateY(-1px);
}

/* ── Mode hint ───────────────────────────────────────────────────────────── */
.mode-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 7px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}

.mode-hint-icon { color: var(--text-4); display: flex; }

/* ── Threads panel ───────────────────────────────────────────────────────── */
#threads-panel {
  width: var(--threads-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.threads-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.threads-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.thread-count {
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 99px;
  min-width: 24px;
  text-align: center;
}

.thread-count.has-open {
  color: var(--primary);
  background: var(--accent-dim);
  border-color: rgba(76, 121, 250, 0.25);
}

.threads-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.no-threads {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 36px 16px;
  text-align: center;
  color: var(--text-4);
}

.no-threads svg { color: var(--text-4); }
.no-threads p { font-size: 13px; font-weight: 500; color: var(--text-3); }
.no-threads span { font-size: 11px; color: var(--text-3); line-height: 1.6; }

/* ── Thread card ─────────────────────────────────────────────────────────── */
.thread-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.thread-card:hover { border-color: var(--border-3); box-shadow: var(--shadow-sm); }
.thread-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(53, 97, 222, 0.08); }
.thread-card.resolved { opacity: 0.55; }

.thread-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.thread-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  font-family: 'JetBrains Mono', monospace;
}

.thread-card.resolved .thread-num {
  background: var(--surface-3);
  color: var(--text-3);
}

.thread-body { flex: 1; min-width: 0; }

.thread-type-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 4px;
}

.thread-selection-quote {
  font-size: 11px;
  color: var(--text-2);
  font-style: italic;
  background: var(--surface-2);
  border-left: 2px solid var(--secondary);
  border-radius: 0 4px 4px 0;
  padding: 4px 8px;
  margin-bottom: 6px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-note {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}

.thread-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.thread-status.open {
  background: var(--accent-dim);
  color: var(--primary);
  border: 1px solid rgba(53, 97, 222, 0.2);
}

.thread-status.resolved {
  background: var(--green-dim);
  color: var(--green-text);
  border: 1px solid rgba(5, 150, 105, 0.2);
}

.thread-actions {
  display: flex;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.thread-btn {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.thread-btn:hover { color: var(--text-2); background: var(--surface-2); border-color: var(--border); }
.thread-btn.resolve { color: var(--green); }
.thread-btn.resolve:hover { background: var(--green-dim); border-color: rgba(5, 150, 105, 0.2); color: var(--green-text); }
.thread-btn.reopen  { color: var(--amber); }
.thread-btn.reopen:hover { background: var(--amber-dim); }
.thread-btn.delete  { color: var(--text-3); }
.thread-btn.delete:hover { color: var(--red); background: var(--red-dim); border-color: rgba(220, 38, 38, 0.2); }

/* ── Export section ─────────────────────────────────────────────────────── */
.export-section {
  border-top: 1px solid var(--border);
  padding: 14px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--surface-2);
}

.export-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-4);
  text-transform: uppercase;
  margin-bottom: 1px;
}

.btn-export {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  box-shadow: 0 1px 6px rgba(53, 97, 222, 0.25);
}
.btn-export:hover { background: var(--accent); box-shadow: 0 2px 12px rgba(76, 121, 250, 0.35); }
.btn-export:active { transform: scale(0.98); }

.btn-export-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  background: var(--surface);
}
.btn-export-ghost:hover { color: var(--text); border-color: var(--border-3); }

.export-hint {
  font-size: 10px;
  color: var(--text-3);
  line-height: 1.6;
}

.doc-id-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.doc-id-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-4);
}

.doc-id-copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.doc-id-copy-btn:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, transparent);
  background: var(--accent-dim);
}
.doc-id-copy-btn svg { opacity: 0.7; flex-shrink: 0; }

.doc-id-chip {
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--primary);
  font-size: 10px;
  border: 1px solid var(--border);
}

/* ── History modal ───────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 8, 0.35);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fade-in 0.15s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  width: 500px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slide-up 0.2s ease;
}

@keyframes slide-up { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 5px;
  border-radius: var(--radius-sm);
  display: flex;
  transition: all 0.1s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.history-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.1s;
}
.history-item:hover { border-color: var(--border); background: var(--surface-2); }
.history-item.current {
  background: var(--accent-dim);
  border-color: rgba(53, 97, 222, 0.15);
}

.history-ver {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  width: 30px;
  flex-shrink: 0;
}
.history-item.current .history-ver { color: var(--primary); }

.history-info { flex: 1; min-width: 0; }
.history-msg  { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-time { font-size: 10px; color: var(--text-3); margin-top: 2px; }

.history-restore {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}
.history-restore:hover { color: var(--primary); border-color: var(--primary); background: var(--accent-dim); }
.history-item.current .history-restore { opacity: 0; pointer-events: none; }

/* ── MCP Setup Modal ─────────────────────────────────────────────────────── */
.mcp-modal-wide { width: 580px; max-height: 82vh; }

.mcp-setup-body {
  overflow-y: auto;
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.mcp-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.mcp-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.mcp-step-content { flex: 1; min-width: 0; }

.mcp-step-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mcp-step-recommended {
  background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: -2px -4px;
}

.mcp-recommended-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 16px;
  flex-shrink: 0;
}

.mcp-step-desc {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 8px;
  line-height: 1.55;
}

.mcp-code-block {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  padding-right: 60px;
}

.mcp-config-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-all;
  display: block;
}

.mcp-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  font-family: inherit;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.1s;
}
.mcp-copy-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.inline-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--text-2);
}

.mcp-prompt-example {
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-style: italic;
  line-height: 1.55;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--text);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  z-index: 999;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  white-space: nowrap;
}

@keyframes toast-in { from { transform: translateX(-50%) translateY(6px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

.toast.success { background: var(--green); color: #fff; }
.toast.error   { background: var(--red); color: #fff; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-3); }

/* ── Theme toggle button ─────────────────────────────────────────────────── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-3); }

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Mode hint keyboard shortcuts ────────────────────────────────────────── */
.mode-hint-shortcuts {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-4);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  line-height: 1.6;
  box-shadow: 0 1px 0 var(--border-3);
}

/* Alt-key temporary comment mode indicator (visual only; cursor set by iframe script) */

#mode-hint.alt-active #mode-hint-text { color: var(--primary); font-weight: 500; }

/* ── Dark theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #030408;
  --surface:      #070c18;
  --surface-2:    #0b1225;
  --surface-3:    #0f1830;
  --surface-4:    #141e3c;

  --border:       #182040;
  --border-2:     #1e284e;
  --border-3:     #243060;

  --primary:      #214eca;
  --secondary:    #0c2a83;
  --accent:       #0533b3;
  --accent-dim:   rgba(33, 78, 202, 0.2);
  --accent-glow:  rgba(33, 78, 202, 0.3);
  --accent-text:  #7a99f3;
  --accent-light: #4c79fa;

  --text:         #f8f9fc;
  --text-2:       #8898c8;
  --text-3:       #4a5580;
  --text-4:       #2a3360;

  --green:        #10b981;
  --green-dim:    #063a2a;
  --green-text:   #34d399;
  --amber:        #f59e0b;
  --amber-dim:    #3d2200;
  --red:          #ef4444;
  --red-dim:      #3a0a0a;
  --red-text:     #f87171;

  --shadow-sm:    0 1px 4px rgba(0,0,0,0.5);
  --shadow:       0 4px 20px rgba(0,0,0,0.6);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.7);
}

/* Dark-specific overrides (things that can't be expressed via variables alone) */
[data-theme="dark"] .pin-tooltip {
  background: var(--surface-3);
  border: 1px solid var(--border-3);
  color: var(--text);
}

[data-theme="dark"] .toast { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-3); }
[data-theme="dark"] .toast.success { background: var(--green-dim); color: var(--green-text); border-color: rgba(16,185,129,0.25); }
[data-theme="dark"] .toast.error   { background: var(--red-dim); color: var(--red-text); border-color: rgba(239,68,68,0.2); }

[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.75); }

[data-theme="dark"] .selection-tooltip {
  background: var(--surface-3);
  border: 1px solid var(--border-3);
  color: var(--text);
}
[data-theme="dark"] .selection-tooltip:hover { background: var(--primary); color: #fff; }

[data-theme="dark"] #preview-panel { background: var(--bg); }

[data-theme="dark"] .empty-state {
  background-image:
    radial-gradient(ellipse at 30% 40%, rgba(33, 78, 202, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 65%, rgba(5, 51, 179, 0.06) 0%, transparent 55%);
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
