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

/* ── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --bg:          #0e0e11;
  --bg2:         #16161c;
  --bg3:         #1e1e27;
  --surface:     #22222d;
  --border:      #2e2e3d;
  --border-soft: #252532;
  --text:        #e8e8f0;
  --text-2:      #9898b0;
  --text-3:      #5c5c78;
  --accent:      #c8f060;
  --accent-dim:  rgba(200, 240, 96, 0.12);
  --accent-glow: rgba(200, 240, 96, 0.25);
  --red:         #ff6b6b;
  --amber:       #ffcc44;
  --blue:        #7ab8ff;
  --radius:      8px;
  --radius-sm:   5px;
  --shadow:      0 2px 16px rgba(0,0,0,0.5);
  --font-body:   'Fraunces', Georgia, serif;
  --font-mono:   'DM Mono', 'Courier New', monospace;
  --transition:  140ms ease;
  --w:           360px;
}

[data-theme="light"] {
  --bg:          #f5f4ee;
  --bg2:         #eeede6;
  --bg3:         #e6e4dc;
  --surface:     #ffffff;
  --border:      #d8d6cc;
  --border-soft: #e4e2d8;
  --text:        #1a1a22;
  --text-2:      #55556a;
  --text-3:      #9898aa;
  --accent:      #2e7d32;
  --accent-dim:  rgba(46, 125, 50, 0.1);
  --accent-glow: rgba(46, 125, 50, 0.2);
  --shadow:      0 2px 16px rgba(0,0,0,0.12);
}

/* ── Body ─────────────────────────────────────────────────────────────────── */
html, body {
  width: var(--w);
  min-height: 100px;
  max-height: 580px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 8px; }

.logo-mark svg { display: block; }

.logo-text {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.logo-text em {
  font-style: normal;
  color: var(--accent);
}

.header-actions { display: flex; align-items: center; gap: 4px; }

/* ── Icon Buttons ─────────────────────────────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main {
  overflow-y: auto;
  max-height: 538px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.main::-webkit-scrollbar { width: 4px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Panels ───────────────────────────────────────────────────────────────── */
.panel { padding: 14px; }

.hidden { display: none !important; }

/* ── Page Info ────────────────────────────────────────────────────────────── */
.page-info {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.page-favicon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 2px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}
.page-favicon img { width: 100%; height: 100%; object-fit: contain; }

.page-title {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-2);
  line-height: 1.4;
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ── State Blocks ─────────────────────────────────────────────────────────── */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px;
  text-align: center;
}

.state-icon { font-size: 28px; line-height: 1; }

.state-msg {
  font-size: 13px;
  color: var(--text-2);
  max-width: 240px;
  line-height: 1.5;
}

.idle-hint {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.error-msg {
  font-size: 13px;
  color: var(--red);
  max-width: 260px;
  line-height: 1.5;
}

/* ── Loading ──────────────────────────────────────────────────────────────── */
.spinner {
  position: relative;
  width: 36px;
  height: 36px;
}
.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.spinner-ring:nth-child(1) {
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
.spinner-ring:nth-child(2) {
  border-top-color: var(--accent-glow);
  animation: spin 1.5s linear infinite reverse;
  inset: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-msg {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-2);
  letter-spacing: 0.03em;
}

.loading-bar {
  width: 160px;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 400ms ease;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  padding: 7px 14px;
  line-height: 1;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0e0e11;
}
.btn-primary:hover:not(:disabled) {
  background: #d4f570;
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg3);
  border-color: var(--text-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-3);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text-2);
}

.btn-large {
  font-size: 13px;
  padding: 10px 22px;
  gap: 8px;
}

.btn-sm {
  font-size: 11px;
  padding: 5px 10px;
}

/* ── Summary Output ───────────────────────────────────────────────────────── */
.summary-output {
  animation: fadeSlideUp 220ms ease both;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Meta Row ─────────────────────────────────────────────────────────────── */
.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.meta-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-glow);
}

.meta-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

.cache-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--bg3);
  color: var(--text-3);
  border: 1px solid var(--border);
  margin-left: auto;
}

/* ── Sections ─────────────────────────────────────────────────────────────── */
.section {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}
.section:last-of-type { border-bottom: none; }

.section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 7px;
}

.summary-text {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  font-style: italic;
}

/* ── Bullet List ──────────────────────────────────────────────────────────── */
.bullet-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bullet-list li {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  animation: fadeIn 180ms ease both;
}
.bullet-list li::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 6px;
}

/* ── Insight List ─────────────────────────────────────────────────────────── */
.insight-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.insight-list li {
  display: flex;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-2);
  padding: 6px 8px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Action Row ───────────────────────────────────────────────────────────── */
.action-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  flex-wrap: wrap;
}

/* ── Settings Panel ───────────────────────────────────────────────────────── */
.panel-title {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.form-group { margin-bottom: 16px; }

.form-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}

.help-link {
  margin-left: auto;
  font-size: 10px;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0;
}
.help-link:hover { text-decoration: underline; }
.help-link:focus-visible { outline: 1px solid var(--accent); border-radius: 2px; }

.backend-note {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 9px 11px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  line-height: 1.5;
  margin-bottom: 16px;
}
.backend-note svg { flex-shrink: 0; margin-top: 1px; }

/* ── Radio Groups ─────────────────────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-2);
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.radio-label:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.radio-label input { display: none; }

/* ── Settings Actions ─────────────────────────────────────────────────────── */
.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.settings-msg {
  margin-top: 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  min-height: 16px;
  transition: color var(--transition);
}
.settings-msg.success { color: var(--accent); }
.settings-msg.error   { color: var(--red); }
