/* ===================================================================
   INDEKS Research Platform — Main Stylesheet
   Editorial research environment: typography-led, calm, trustworthy
   =================================================================== */

/* --- Reset / Normalize ------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -moz-tab-size: 4; tab-size: 4; scroll-behavior: smooth; }
body { line-height: 1.6; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
button { cursor: pointer; border: none; background: none; }

/* --- Custom Properties ------------------------------------------------ */
:root {
  /* Book accent colors */
  --accent-general: #64748b;
  --accent-financial: #166534;
  --accent-medical: #1d4ed8;
  --accent-legal: #1e3a5f;
  --accent-financial-pro: #166534;

  /* Core palette */
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunken: #f5f5f4;
  --color-border: #e7e5e4;
  --color-border-subtle: #f0eeec;
  --color-text: #1c1917;
  --color-text-secondary: #57534e;
  --color-text-muted: #a8a29e;
  --color-text-inverse: #fafaf9;

  /* Semantic */
  --color-primary: #292524;
  --color-primary-hover: #1c1917;
  --color-success: #166534;
  --color-warning: #b45309;
  --color-danger: #b91c1c;
  --color-info: #1d4ed8;

  /* Tier badges */
  --tier-free: #78716c;
  --tier-payg: #2563eb;
  --tier-plus: #7c3aed;
  --tier-pro: #b45309;

  /* Typography */
  --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Menlo', 'Consolas', monospace;
  --font-display: 'Georgia', 'Cambria', 'Times New Roman', serif;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  --leading-tight: 1.25;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;

  --tracking-tight: -0.01em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;

  /* Spacing scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;
  --sp-20: 5rem;
  --sp-24: 6rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(28, 25, 23, 0.06), 0 2px 4px -2px rgba(28, 25, 23, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(28, 25, 23, 0.07), 0 4px 6px -4px rgba(28, 25, 23, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(28, 25, 23, 0.08), 0 8px 10px -6px rgba(28, 25, 23, 0.04);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;

  /* Layout */
  --header-h: 56px;
  --sidebar-w: 240px;
  --content-max: 840px;
  --page-max: 1200px;

  /* Active book accent (set via JS or inline style) */
  --book-accent: var(--accent-general);
}

/* --- Dark mode -------------------------------------------------------- */
[data-theme="dark"] {
  --color-bg: #0c0a09;
  --color-surface: #1c1917;
  --color-surface-raised: #292524;
  --color-surface-sunken: #0c0a09;
  --color-border: #292524;
  --color-border-subtle: #1c1917;
  --color-text: #fafaf9;
  --color-text-secondary: #a8a29e;
  --color-text-muted: #78716c;
  --color-text-inverse: #1c1917;
  --color-primary: #fafaf9;
  --color-primary-hover: #e7e5e4;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.35), 0 4px 6px -4px rgba(0,0,0,0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.4), 0 8px 10px -6px rgba(0,0,0,0.2);
}

/* --- Base -------------------------------------------------------------- */
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Typography -------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

.display-heading {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-center { text-align: center; }

/* --- Layout ------------------------------------------------------------ */
.page-wrap {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

.content-wrap {
  max-width: var(--content-max);
  margin: 0 auto;
}

main {
  flex: 1;
  padding-top: var(--sp-8);
  padding-bottom: var(--sp-16);
}

/* --- Header ------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.92);
}

[data-theme="dark"] .site-header {
  background: rgba(28,25,23,0.92);
}

/* --- Theme toggle ---------------------------------------------------- */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}

.theme-toggle:hover {
  color: var(--color-text);
  background: var(--color-surface-raised);
}

.theme-icon-moon { display: none; }
.theme-icon-sun  { display: block; }

[data-theme="dark"] .theme-icon-moon { display: block; }
[data-theme="dark"] .theme-icon-sun  { display: none; }

.header-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--sp-6);
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.header-brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.header-brand-logo {
  height: 36px;
  width: auto;
}

.header-brand-logo.logo-light { display: block; }
.header-brand-logo.logo-dark  { display: none; }

[data-theme="dark"] .header-brand-logo.logo-light { display: none; }
[data-theme="dark"] .header-brand-logo.logo-dark  { display: block; }

@media (min-width: 768px) {
  .header-brand-logo { height: 40px; }
}

.landing-hero-logo.logo-light { display: block; }
.landing-hero-logo.logo-dark  { display: none; }

[data-theme="dark"] .landing-hero-logo.logo-light { display: none; }
[data-theme="dark"] .landing-hero-logo.logo-dark  { display: block; }

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

/* Book selector (header) */
.book-selector-compact {
  position: relative;
}

.book-selector-compact select {
  appearance: none;
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-1) var(--sp-8) var(--sp-1) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-in-out);
  min-width: 160px;
}

.book-selector-compact select:hover {
  border-color: var(--book-accent, var(--color-text-muted));
}

.book-selector-compact::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-text-muted);
  pointer-events: none;
}

/* Search bar */
.global-search {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.global-search input {
  width: 100%;
  padding: var(--sp-2) var(--sp-4) var(--sp-2) var(--sp-10);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  background: var(--color-surface-sunken);
  color: var(--color-text);
  transition: all var(--duration-normal) var(--ease-out);
}

.global-search input:focus {
  outline: none;
  border-color: var(--book-accent, var(--color-text-muted));
  box-shadow: 0 0 0 3px rgba(100,116,139,0.1);
  background: var(--color-surface);
}

.global-search input::placeholder {
  color: var(--color-text-muted);
}

.global-search-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

/* IDX balance display */
.idx-display {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.idx-display-label {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.idx-display-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* User menu */
.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: background var(--duration-fast) var(--ease-in-out);
}

.user-menu-trigger:hover {
  background: var(--color-surface-sunken);
}

.user-menu-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--duration-normal) var(--ease-out);
  z-index: 200;
}

.user-menu-dropdown.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-menu-dropdown a,
.user-menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-in-out);
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

.user-menu-dropdown .divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--sp-1) 0;
}

/* --- Tier Badge -------------------------------------------------------- */
.tier-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  line-height: 1.5;
}

.tier-badge--free {
  background: #f5f5f4;
  color: var(--tier-free);
  border: 1px solid #d6d3d1;
}

.tier-badge--payg {
  background: #eff6ff;
  color: var(--tier-payg);
  border: 1px solid #bfdbfe;
}

.tier-badge--plus {
  background: #f5f3ff;
  color: var(--tier-plus);
  border: 1px solid #ddd6fe;
}

.tier-badge--pro {
  background: #fffbeb;
  color: var(--tier-pro);
  border: 1px solid #fde68a;
}

[data-theme="dark"] .tier-badge--free { background: #292524; border-color: #44403c; }
[data-theme="dark"] .tier-badge--payg { background: #172554; border-color: #1e40af; }
[data-theme="dark"] .tier-badge--plus { background: #2e1065; border-color: #5b21b6; }
[data-theme="dark"] .tier-badge--pro  { background: #451a03; border-color: #92400e; }

/* --- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  transition: all var(--duration-fast) var(--ease-in-out);
  outline: none;
  border: 1px solid transparent;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--book-accent, var(--color-primary));
}

.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.btn--primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn--primary:active {
  transform: scale(0.98);
}

.btn--accent {
  background: var(--book-accent, var(--accent-general));
  color: #fff;
  border-color: var(--book-accent, var(--accent-general));
}

.btn--accent:hover {
  filter: brightness(1.1);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--secondary:hover {
  background: var(--color-surface-sunken);
  border-color: var(--color-text-muted);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
}

.btn--ghost:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.btn--danger:hover {
  filter: brightness(1.1);
}

.btn--sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
}

.btn--lg {
  padding: var(--sp-3) var(--sp-8);
  font-size: var(--text-base);
  border-radius: var(--radius-lg);
}

.btn--full { width: 100%; }

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Form Elements ----------------------------------------------------- */
.form-group {
  margin-bottom: var(--sp-5);
}

.form-label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--duration-fast) var(--ease-in-out),
              box-shadow var(--duration-fast) var(--ease-in-out);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--book-accent, var(--accent-general));
  box-shadow: 0 0 0 3px rgba(100,116,139,0.12);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2378716c' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: var(--sp-8);
}

.form-hint {
  margin-top: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.form-error {
  margin-top: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--color-danger);
}

/* --- Cards ------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-xs);
}

.card--raised {
  box-shadow: var(--shadow-md);
}

.card--accent-top {
  border-top: 3px solid var(--book-accent, var(--accent-general));
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.card-body {
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--color-text-secondary);
}

/* --- Tabs -------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-6);
}

.tab {
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  transition: all var(--duration-fast) var(--ease-in-out);
  cursor: pointer;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--color-text-secondary);
}

.tab.is-active {
  color: var(--book-accent, var(--color-text));
  border-bottom-color: var(--book-accent, var(--color-text));
}

.tab--loading::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--book-accent, var(--color-text-muted));
  animation: tabPulse 1s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes tabPulse {
  0%, 100% { opacity: .3; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1); }
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

/* --- Tables ------------------------------------------------------------ */
.data-table {
  width: 100%;
  font-size: var(--text-sm);
}

.data-table th {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.data-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--color-border-subtle);
  color: var(--color-text-secondary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--color-surface-sunken);
}

.data-table td:first-child,
.data-table th:first-child {
  padding-left: 0;
}

/* --- Progress Bar ------------------------------------------------------ */
.progress-bar {
  height: 6px;
  background: var(--color-surface-sunken);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--book-accent, var(--accent-general));
  transition: width var(--duration-slow) var(--ease-out);
}

.progress-bar--lg {
  height: 10px;
}

/* --- Progress Ring ----------------------------------------------------- */
.progress-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress-ring svg {
  transform: rotate(-90deg);
}

.progress-ring-track {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 6;
}

.progress-ring-fill {
  fill: none;
  stroke: var(--book-accent, var(--accent-general));
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--duration-slow) var(--ease-out);
}

.progress-ring-label {
  position: absolute;
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Modal ------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-normal) var(--ease-in-out);
}

.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(8px) scale(0.98);
  transition: transform var(--duration-normal) var(--ease-out);
}

.modal-overlay.is-open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6) 0;
}

.modal-title {
  font-size: var(--text-xl);
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: all var(--duration-fast) var(--ease-in-out);
}

.modal-close:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

.modal-body {
  padding: var(--sp-5) var(--sp-6);
}

.modal-footer {
  padding: 0 var(--sp-6) var(--sp-5);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}

/* --- Modal ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--duration-normal, .2s) var(--ease-out, ease-out);
}

.modal-card {
  position: relative;
  width: 92vw;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-surface, #1a1a1a);
  border: 1px solid var(--color-border, #2a2a2a);
  border-radius: var(--radius-lg, 12px);
  padding: var(--sp-6, 1.5rem) var(--sp-5, 1.25rem);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
}

.modal-close {
  position: absolute;
  top: var(--sp-3, .75rem);
  right: var(--sp-3, .75rem);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--color-text-muted, #888);
  cursor: pointer;
  transition: background var(--duration-fast, .1s), color var(--duration-fast, .1s);
}

.modal-close:hover {
  background: var(--color-border, #2a2a2a);
  color: var(--color-text, #eee);
}

/* --- Upgrade Modal ----------------------------------------------------- */
.modal-card--wide {
  max-width: 860px;
  width: 94%;
}

.upgrade-header {
  text-align: center;
  margin-bottom: var(--sp-5);
}

.upgrade-header h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--sp-2);
  color: var(--color-text);
}

.upgrade-header p {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.upgrade-plans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.upgrade-plans--three {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 720px) {
  .upgrade-plans--three { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .upgrade-plans { grid-template-columns: 1fr; }
}

.upgrade-plan {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  position: relative;
}

.upgrade-plan--featured {
  border-color: var(--book-accent, var(--color-accent));
  box-shadow: 0 0 0 1px var(--book-accent, var(--color-accent));
}

.upgrade-plan-badge {
  position: absolute;
  top: calc(-1 * var(--sp-2));
  left: 50%;
  transform: translateX(-50%);
  background: var(--book-accent, var(--color-accent));
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.upgrade-plan-name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--sp-1);
}

.upgrade-plan-price {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--color-text);
  margin-bottom: var(--sp-3);
  line-height: 1.2;
}

.upgrade-plan-price span {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-muted);
}

.upgrade-features {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--sp-4);
  flex: 1;
}

.upgrade-features li {
  position: relative;
  padding-left: 1.4em;
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text-secondary);
}

.upgrade-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--book-accent, var(--color-accent));
  font-weight: 700;
}

.upgrade-footer {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* --- Manage Plan rows -------------------------------------------------- */
.manage-plan-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-in-out);
}

.manage-plan-option:hover {
  border-color: var(--color-text-muted);
}

.manage-plan-option--muted {
  opacity: 0.75;
  margin-top: var(--sp-2);
}

.manage-plan-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.manage-plan-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.manage-plan-price {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.price-dollar {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.price-dollar-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-style: italic;
}

/* --- Toast / Notifications --------------------------------------------- */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + var(--sp-4));
  right: var(--sp-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  pointer-events: auto;
  animation: slideInRight var(--duration-normal) var(--ease-out);
  max-width: 380px;
}

.toast--success { border-left: 3px solid var(--color-success); }
.toast--error   { border-left: 3px solid var(--color-danger); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--info    { border-left: 3px solid var(--color-info); }

.toast.is-exiting {
  animation: slideOutRight var(--duration-normal) var(--ease-in-out) forwards;
}

/* Flash messages (Jinja) */
.flash-messages {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--sp-2) var(--sp-6);
}

.flash {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.flash--success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.flash--error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.flash--warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.flash--info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

[data-theme="dark"] .flash--success { background: #052e16; border-color: #166534; }
[data-theme="dark"] .flash--error   { background: #450a0a; border-color: #b91c1c; }
[data-theme="dark"] .flash--warning { background: #451a03; border-color: #b45309; }
[data-theme="dark"] .flash--info    { background: #172554; border-color: #1d4ed8; }

/* --- Landing Page ------------------------------------------------------ */
.landing-hero {
  text-align: center;
  padding: var(--sp-16) 0 var(--sp-12);
}

.landing-hero-logo {
  display: block;
  margin: 0 auto var(--sp-6);
  width: 220px;
  height: auto;
}

@media (min-width: 768px) {
  .landing-hero-logo { width: 280px; }
}

.landing-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(var(--text-3xl), 5vw, var(--text-4xl));
  font-weight: 400;
  margin-bottom: var(--sp-3);
  letter-spacing: -0.02em;
}

.landing-hero p {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  max-width: 540px;
  margin: 0 auto var(--sp-8);
}

.landing-search {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.landing-search input {
  width: 100%;
  padding: var(--sp-4) var(--sp-6) var(--sp-4) var(--sp-12);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-lg);
  background: var(--color-surface);
  color: var(--color-text);
  transition: all var(--duration-normal) var(--ease-out);
  box-shadow: var(--shadow-sm);
}

.landing-search input:focus {
  outline: none;
  border-color: var(--book-accent, var(--accent-general));
  box-shadow: var(--shadow-md), 0 0 0 4px rgba(100,116,139,0.08);
}

.landing-search-icon {
  position: absolute;
  left: var(--sp-5);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  width: 20px;
  height: 20px;
}

.landing-search-submit {
  position: absolute;
  right: var(--sp-2);
  top: 50%;
  transform: translateY(-50%);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius-full);
  background: var(--book-accent, var(--color-primary));
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--duration-fast) var(--ease-in-out);
}

.landing-search-submit:hover {
  filter: brightness(1.1);
}

.source-disclaimer {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--sp-2);
  opacity: 0.7;
  letter-spacing: 0.01em;
}

/* Book selector pills */
.book-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-8);
}

.book-pill {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  transition: all var(--duration-fast) var(--ease-in-out);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

.book-pill:hover:not(.book-pill--locked) {
  border-color: var(--pill-accent, var(--color-text-muted));
  color: var(--pill-accent, var(--color-text));
}

.book-pill.is-active {
  background: var(--pill-accent, var(--color-primary));
  color: #fff;
  border-color: var(--pill-accent, var(--color-primary));
}

.book-pill--locked {
  opacity: 0.55;
  cursor: pointer;
}
.book-pill--locked:hover {
  opacity: 0.8;
  border-color: var(--pill-accent, var(--color-text-muted));
}

.book-pill--locked .lock-icon {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

/* Trending section */
.trending-section {
  padding: var(--sp-12) 0;
}

.trending-section h2 {
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 500;
  margin-bottom: var(--sp-8);
  color: var(--color-text-secondary);
}

.trending-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-6);
}

.trending-group h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--sp-3);
  padding-left: var(--sp-1);
}

.trending-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.trending-tag {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-in-out);
}

.trending-tag:hover {
  background: var(--color-surface);
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

/* How it works */
.how-it-works {
  padding: var(--sp-12) 0;
  border-top: 1px solid var(--color-border-subtle);
}

.how-it-works h2 {
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 500;
  margin-bottom: var(--sp-8);
  color: var(--color-text-secondary);
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-8);
  max-width: 800px;
  margin: 0 auto;
}

.step {
  text-align: center;
}

.step-number {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-3);
}

.step h3 {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.step p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: var(--leading-relaxed);
}

/* Upgrade CTA */
.upgrade-cta {
  text-align: center;
  padding: var(--sp-10) var(--sp-6);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-xl);
  margin-top: var(--sp-8);
}

.upgrade-cta h3 {
  font-size: var(--text-xl);
  margin-bottom: var(--sp-2);
}

.upgrade-cta p {
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-5);
  font-size: var(--text-sm);
}

/* --- Research Page ------------------------------------------------------ */
.research-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-4);
}

.research-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.research-book-label {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--book-accent, var(--accent-general));
}

.research-term {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: var(--leading-tight);
}

/* Verify toggle */
.verify-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  position: relative;
}
.verify-toggle-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.verify-toggle-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-in-out);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-fast) var(--ease-out);
}

.toggle-switch.is-on {
  background: var(--book-accent, var(--accent-general));
}

.toggle-switch.is-on::after {
  transform: translateX(18px);
}

.verify-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  padding: var(--sp-3);
  background: var(--color-text);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
  line-height: var(--leading-relaxed);
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-fast) var(--ease-in-out);
  pointer-events: none;
  z-index: 50;
}

.verify-toggle:hover .verify-tooltip {
  opacity: 1;
  visibility: visible;
}

.verify-hint {
  font-size: var(--text-xs);
  color: var(--book-accent, var(--color-accent));
  white-space: nowrap;
  visibility: hidden;
  line-height: 1.4;
}

.verify-toggle:has(.toggle-switch.is-on) > .verify-hint {
  visibility: visible;
}

/* Content area */
.research-content {
  line-height: var(--leading-relaxed);
  color: var(--color-text);
  font-size: var(--text-base);
}

.research-content h1,
.research-content h2,
.research-content h3 {
  margin-top: var(--sp-4);
  margin-bottom: var(--sp-2);
}

.research-content p {
  margin-bottom: var(--sp-2);
}

.research-content p:empty,
.research-content br + br {
  display: none;
}

.research-content ul,
.research-content ol {
  margin-top: 0;
  margin-bottom: var(--sp-2);
  padding-left: var(--sp-6);
}

.research-content ul { list-style: disc; }
.research-content ol { list-style: decimal; }

.research-content li {
  margin-bottom: 0.25rem;
}

.research-content li > ul,
.research-content li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.research-content hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--sp-6) 0;
}

.research-content blockquote {
  border-left: 3px solid var(--book-accent, var(--color-border));
  padding: var(--sp-3) var(--sp-5);
  margin: var(--sp-4) 0;
  background: var(--color-surface-sunken);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--color-text-secondary);
}

.research-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-surface-sunken);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}

.research-content a {
  color: var(--book-accent, var(--color-info));
  text-decoration: underline;
  text-underline-offset: 2px;
}

.research-content a:hover {
  text-decoration-thickness: 2px;
}

.toc-heading {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-3);
  padding-left: var(--sp-1);
}

/* Table of Contents */
.toc {
  list-style: none;
  padding: 0;
  counter-reset: toc-counter;
}

.toc-item {
  counter-increment: toc-counter;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-in-out);
  border-radius: var(--radius-md);
}

.toc-item:hover {
  background: var(--color-surface-sunken);
}

.toc-item-number {
  flex-shrink: 0;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
}

.toc-item-number::before {
  content: none;
}

.toc-item-text {
  flex: 1;
  font-size: var(--text-base);
  color: var(--color-text);
}

.toc-item-status {
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.toc-item--delivered .toc-item-number {
  background: var(--book-accent, var(--accent-general));
  color: #fff;
  border-color: var(--book-accent, var(--accent-general));
}

.toc-item--locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.toc-item--locked .lock-icon {
  width: 14px;
  height: 14px;
  color: var(--color-text-muted);
}

/* Research navigation */
.research-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--color-border);
  margin-top: var(--sp-6);
}

.research-nav-left,
.research-nav-right {
  display: flex;
  gap: var(--sp-2);
}

/* Pod-It button */
.btn--pod-it {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
}

.btn--pod-it:hover {
  filter: brightness(1.08);
}

/* Question input */
.question-input-wrap {
  margin-top: var(--sp-6);
  padding: var(--sp-4);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.question-input-wrap label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--sp-2);
  color: var(--color-text-secondary);
}

.question-input-row {
  display: flex;
  gap: var(--sp-2);
}

.question-input-row input {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  background: var(--color-surface);
  color: var(--color-text);
}

.question-input-row input:focus {
  outline: none;
  border-color: var(--book-accent, var(--accent-general));
}

/* --- Verification badge ------------------------------------------------- */
.verify-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--sp-6);
  padding: 4px 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-success, #22c55e);
  border: 1px solid var(--color-success, #22c55e);
  border-radius: 999px;
  opacity: 0.8;
  letter-spacing: 0.02em;
}

.verify-badge svg {
  flex-shrink: 0;
}

.question-input-wrap--locked {
  opacity: 0.45;
  pointer-events: none;
}

.question-input-wrap--locked label {
  color: var(--color-text-muted);
}

.question-input-wrap--locked input {
  cursor: not-allowed;
}

/* Search within topics */
.topic-search-wrap {
  margin-bottom: var(--sp-4);
}

.topic-search-wrap input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-8);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

/* Citation area */
.citations-area {
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--color-border-subtle);
}

.citations-area h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  margin-bottom: var(--sp-3);
}

.citation-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-xs);
  color: var(--book-accent, var(--color-info));
  background: var(--color-surface-sunken);
  border-radius: var(--radius-sm);
  margin-right: var(--sp-2);
  margin-bottom: var(--sp-1);
}

.citation-link:hover {
  text-decoration: underline;
}

/* Disclaimer bar */
.disclaimer-bar {
  margin-top: var(--sp-6);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-warning);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: var(--leading-relaxed);
}

/* IDX cost display */
.idx-cost-display {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
}

/* --- Typewriter cursor ------------------------------------------------- */
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--book-accent, var(--color-text));
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* --- Account Page ------------------------------------------------------ */
.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-6);
  margin-bottom: var(--sp-8);
}

@media (max-width: 768px) {
  .account-grid { grid-template-columns: 1fr; }
}

.idx-balance-large {
  font-size: var(--text-4xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
  line-height: 1;
  margin: var(--sp-4) 0;
}

.idx-balance-unit {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: var(--sp-1);
}

/* Top-up packs */
.topup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
}

.topup-option {
  padding: var(--sp-4);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-in-out);
}

.topup-option:hover {
  border-color: var(--color-text-muted);
}

.topup-option.is-selected {
  border-color: var(--book-accent, var(--color-primary));
  background: var(--color-surface-sunken);
}

.topup-amount {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.topup-price {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* --- Upgrade / Pricing Page -------------------------------------------- */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  margin-top: var(--sp-8);
}

@media (max-width: 1024px) {
  .pricing-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .pricing-grid { grid-template-columns: 1fr; }
}

.pricing-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  transition: all var(--duration-normal) var(--ease-out);
}

.pricing-card:hover {
  box-shadow: var(--shadow-md);
}

.pricing-card--current {
  border-color: var(--book-accent, var(--color-primary));
  border-width: 2px;
  box-shadow: var(--shadow-md);
  position: relative;
}

.pricing-card--current::before {
  content: 'Current Plan';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 12px;
  background: var(--book-accent, var(--color-primary));
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.pricing-card--recommended {
  border-color: var(--color-accent, #6366f1);
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), var(--shadow-md);
  position: relative;
  animation: pulse-outline 2s ease-in-out 1;
}
.pricing-card--recommended::after {
  content: 'Recommended';
  position: absolute;
  top: -12px;
  right: 16px;
  padding: 2px 12px;
  background: var(--color-accent, #6366f1);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
@keyframes pulse-outline {
  0%, 100% { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), var(--shadow-md); }
  50% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.25), var(--shadow-lg); }
}

.pricing-tier-name {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.pricing-price {
  font-size: var(--text-3xl);
  font-weight: 700;
  margin-bottom: var(--sp-4);
}

.pricing-price span {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-muted);
}

.pricing-features {
  flex: 1;
  margin-bottom: var(--sp-6);
}

.pricing-feature {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2) 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.pricing-feature-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--color-success);
  margin-top: 1px;
}

.pricing-feature--unavailable {
  opacity: 0.4;
  text-decoration: line-through;
}

/* --- Auth Pages -------------------------------------------------------- */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-h) - 120px);
  padding: var(--sp-8) var(--sp-4);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  font-size: var(--text-2xl);
  text-align: center;
  margin-bottom: var(--sp-2);
}

.auth-card .auth-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-6);
}

.auth-card .auth-footer {
  text-align: center;
  margin-top: var(--sp-5);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.auth-card .auth-footer a {
  color: var(--color-text);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.auth-error {
  padding: var(--sp-3);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
  text-align: center;
}

[data-theme="dark"] .auth-error { background: #450a0a; border-color: #b91c1c; }

/* --- Admin Panel ------------------------------------------------------- */
.admin-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

@media (max-width: 768px) {
  .admin-layout { grid-template-columns: 1fr; }
}

.admin-sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--sp-4);
}

.admin-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: all var(--duration-fast) var(--ease-in-out);
}

.admin-nav-item:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

.admin-nav-item.is-active {
  background: var(--color-surface-sunken);
  color: var(--color-text);
  font-weight: 500;
}

.admin-main {
  padding: var(--sp-6);
  overflow-x: auto;
}

.admin-panel-section {
  display: none;
}

.admin-panel-section.is-active {
  display: block;
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
}

.stat-card-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  margin-bottom: var(--sp-1);
}

.stat-card-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- Loading / Skeleton ------------------------------------------------ */
/* --- Loading quip -------------------------------------------------------- */
.loading-quip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  min-height: 160px;
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

.loading-quip-message {
  font-family: 'VT323', monospace;
  font-size: 1.35rem;
  line-height: 1.5;
  color: var(--book-accent, var(--color-text-secondary));
  max-width: 520px;
  margin-bottom: var(--sp-4);
  letter-spacing: 0.01em;
}

.loading-explainer {
  margin-top: var(--sp-4);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-text-muted);
  max-width: 480px;
}

.loading-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--book-accent, var(--color-text-muted));
  animation: dotBounce 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotBounce {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-sunken) 25%,
    var(--color-border-subtle) 37%,
    var(--color-surface-sunken) 63%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

.skeleton-line {
  height: 14px;
  margin-bottom: var(--sp-3);
  border-radius: var(--radius-sm);
}

.skeleton-line:last-child {
  width: 65%;
}

.skeleton-heading {
  height: 24px;
  width: 45%;
  margin-bottom: var(--sp-5);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border);
  border-top-color: var(--book-accent, var(--color-text));
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Pagination -------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  margin-top: var(--sp-6);
}

.pagination-btn {
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  transition: all var(--duration-fast) var(--ease-in-out);
}

.pagination-btn:hover {
  background: var(--color-surface-sunken);
  border-color: var(--color-text-muted);
}

.pagination-btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Footer ------------------------------------------------------------ */
.site-footer {
  padding: var(--sp-6) 0;
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.site-footer p {
  margin-bottom: var(--sp-1);
}

.footer-disclaimer {
  max-width: 600px;
  margin: 0 auto;
  line-height: var(--leading-relaxed);
}

/* --- Utility Classes --------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

/* --- Animations -------------------------------------------------------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

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

/* --- Responsive -------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --page-max: 960px;
  }
  .steps-grid { gap: var(--sp-4); }
}

@media (max-width: 768px) {
  :root {
    --header-h: 48px;
    --sp-6: 1rem;
  }

  .header-inner {
    padding: 0 var(--sp-3);
    gap: var(--sp-2);
  }

  .header-brand-logo { height: 28px; }

  .global-search { max-width: 180px; }
  .global-search input { font-size: var(--text-xs); }

  .landing-hero { padding: var(--sp-8) 0 var(--sp-6); }
  .landing-search input { font-size: var(--text-base); padding: var(--sp-3) var(--sp-4) var(--sp-3) var(--sp-10); }

  .steps-grid { grid-template-columns: 1fr; gap: var(--sp-6); }

  .research-header { flex-direction: column; align-items: flex-start; }

  .research-nav { flex-wrap: wrap; }

  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .admin-sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
  }
}

/* --- Print ------------------------------------------------------------- */
@media print {
  .site-header,
  .site-footer,
  .research-nav,
  .verify-toggle,
  .question-input-wrap,
  .btn,
  .toast-container,
  .flash-messages { display: none !important; }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .research-content {
    max-width: 100%;
  }

  .card {
    border: 1px solid #ccc;
    box-shadow: none;
  }

  a { color: #000; text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #666; }
}
