:root {
  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #f0eef8;
  --border: #e3e0ef;
  --text: #1c1a29;
  --muted: #6b6880;
  --accent: #6d4aff;
  --accent-strong: #5a36f0;
  --accent-soft: #ece7ff;
  --danger: #c4314b;
  --highlight: #fff4d6;
  --shadow: 0 1px 2px rgba(28, 26, 41, 0.05), 0 6px 24px rgba(28, 26, 41, 0.05);
  --radius: 14px;
  --font: 'Inter', 'Hind Siliguri', 'Nirmala UI', system-ui, sans-serif;
  --badge-active-bg: #dcf5e7; --badge-active: #13703f;
  --badge-pending-bg: #fff1cc; --badge-pending: #8a5a00;
  --badge-disabled-bg: #fde2e6; --badge-disabled: #a3243b;
  --success: #13803f;
  color-scheme: light;
}

/* Dark theme: chosen explicitly (data-theme="dark"), or by the system when the user
   picked "Auto" (no data-theme). The two blocks must stay identical. */
:root[data-theme='dark'] {
  --bg: #121118;
  --surface: #1b1a24;
  --surface-2: #24222f;
  --border: #2f2d3c;
  --text: #ecebf3;
  --muted: #9a97ad;
  --accent: #8f75ff;
  --accent-strong: #a18bff;
  --accent-soft: #2a2545;
  --danger: #ff7b8f;
  --highlight: #3a3220;
  --shadow: none;
  --badge-active-bg: #173b28; --badge-active: #7fe0a8;
  --badge-pending-bg: #3d3214; --badge-pending: #ffd36b;
  --badge-disabled-bg: #43202a; --badge-disabled: #ff9aac;
  --success: #6fdc9b;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #121118;
    --surface: #1b1a24;
    --surface-2: #24222f;
    --border: #2f2d3c;
    --text: #ecebf3;
    --muted: #9a97ad;
    --accent: #8f75ff;
    --accent-strong: #a18bff;
    --accent-soft: #2a2545;
    --danger: #ff7b8f;
    --highlight: #3a3220;
    --shadow: none;
    --badge-active-bg: #173b28; --badge-active: #7fe0a8;
    --badge-pending-bg: #3d3214; --badge-pending: #ffd36b;
    --badge-disabled-bg: #43202a; --badge-disabled: #ff9aac;
    --success: #6fdc9b;
    color-scheme: dark;
  }
}

/* Theme switch */
.theme-switch { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.theme-switch button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: none; color: var(--muted); padding: 6px 4px; border-radius: 7px; font: 500 12px var(--font); cursor: pointer;
}
.theme-switch button svg { width: 15px; height: 15px; }
.theme-switch button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.theme-toggle svg { width: 18px; height: 18px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 0; }
.setting-row .label { margin-bottom: 2px; color: var(--text); font-size: 14px; }
.setting-row .hint { margin-top: 0; }
.setting-row .theme-switch { min-width: 260px; }
.auth-theme { position: fixed; top: 16px; right: 16px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* Bangla glyphs read better in Hind Siliguri at a slightly larger size */
:lang(bn), textarea, .script { font-family: 'Inter', 'Hind Siliguri', 'Nirmala UI', sans-serif; }

h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 14px; }
code { background: var(--surface-2); padding: 0 5px; border-radius: 4px; font-size: 0.92em; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 11px var(--font); background: var(--surface); }
.muted { color: var(--muted); }
svg { fill: currentColor; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 25;
}

/* Export popover in the header */
.export-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16); padding: 18px;
}
.export-panel .btn.block:first-of-type { margin-top: 4px; }
.export-panel .hint { margin: 10px 0 0; text-align: center; }
.format-chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.format-chips button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 40px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  font: 600 12px var(--font); cursor: pointer; padding: 6px 4px;
}
.format-chips button small { font-size: 10px; font-weight: 500; color: var(--muted); }
.format-chips button:hover { border-color: var(--accent); }
.format-chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.format-chips button.on small { color: rgba(255, 255, 255, 0.8); }

/* Import script modal */
.modal.import-modal { width: min(760px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head .modal-title { margin: 0; }
.import-step { padding: 20px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  min-height: 320px; border: 2px dashed var(--border); border-radius: 12px; background: var(--bg); padding: 24px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone > svg { width: 52px; height: 52px; color: var(--accent); margin-bottom: 8px; }
.dropzone p { margin: 0; }
.dropzone .muted { font-size: 12px; margin-bottom: 14px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { gap: 14px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.import-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.import-meta strong { overflow-wrap: anywhere; }
#importPreview {
  min-height: 260px; max-height: 50vh; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 15px; line-height: 1.7; background: var(--bg);
}
.import-step .hint { margin-top: 6px; }
.import-step .modal-actions { flex-wrap: wrap; }
.spacer { flex: 1; }
.import-error { margin: -8px 20px 18px; }

/* API integrations (admin) */
.integrations-intro { margin: -6px 0 16px; }
.provider-seg { max-width: 420px; }
.integration-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.integration { border: 1px solid var(--border); border-radius: 12px; padding: 16px; transition: border-color 0.15s, box-shadow 0.15s; }
.integration.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.integration-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.integration .hint { margin: 0 0 12px; }
.integration-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.remove-key { font-size: 12px; color: var(--muted); font-weight: 500; }
.remove-key:hover { color: var(--danger); }
.integration-result { margin: 10px 0 0; font-size: 13px; min-height: 1em; }
.integration-result.ok { color: var(--success); }
.integration-result.fail { color: var(--danger); }

/* Audio history */
.history-card { padding: 0; }
.history-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: 0; }
.history-item.latest { background: var(--accent-soft); }
.history-item .icon-btn.playing { background: var(--accent); border-color: var(--accent); color: #fff; }
.history-main { flex: 1; min-width: 0; }
.history-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
.history-title .muted { font-weight: 400; }
.history-preview { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.history-actions .menu-list { min-width: 230px; }
.history-empty { margin: 0; padding: 18px; font-size: 13px; color: var(--muted); }
.history-progress { height: 3px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.history-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
@media (max-width: 560px) {
  .history-item { flex-wrap: wrap; }
  .history-actions { width: 100%; justify-content: flex-end; }
}

/* Import from Image/Book */
.ocr-pick-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ocr-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 14px; max-height: 300px; overflow-y: auto; }
.ocr-page { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.ocr-page img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.ocr-page .ocr-page-label { display: block; font-size: 11px; color: var(--muted); padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ocr-page .ocr-page-no { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.ocr-page .ocr-remove { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer; font-size: 15px; line-height: 1; }
.ocr-page .ocr-noprev { display: grid; place-items: center; aspect-ratio: 3 / 4; font-size: 12px; color: var(--muted); }
.ocr-option { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.ocr-option input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.ocr-progress { width: min(320px, 80%); }
#ocrPreview { min-height: 260px; max-height: 50vh; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 15px; line-height: 1.7; background: var(--bg); }
.notice.warn { background: var(--highlight); }
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: rgba(109, 74, 255, 0.12); border: 3px dashed var(--accent);
}
.drop-overlay div { background: var(--accent); color: #fff; font-weight: 600; padding: 14px 24px; border-radius: 12px; font-size: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand svg { width: 34px; height: 34px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { stroke: #fff; stroke-width: 2.4; stroke-linecap: round; fill: none; }
.brand strong { display: block; font-size: 16px; }
.brand span { font-size: 12px; color: var(--muted); }
.topbar-hint { font-size: 12px; color: var(--muted); }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px;
  max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px;
}
.workspace { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.settings { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}

/* Editor */
.editor-card { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
textarea {
  display: block; width: 100%; min-height: 340px; resize: vertical; border: 0; outline: none;
  padding: 16px 18px; background: transparent; color: var(--text); font-size: 16px; line-height: 1.75;
}
.editor-foot { display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px;
  font: 600 14px var(--font); cursor: pointer; transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  color: var(--text); background: var(--surface-2);
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 11px; font-size: 13px; font-weight: 500; border-radius: 8px; }
.btn.lg { padding: 13px 26px; font-size: 15px; border-radius: 12px; }
.btn.lg svg { width: 20px; height: 20px; }
.btn.block { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
.link.reset { display: block; margin: 14px auto 0; font-size: 12px; color: var(--muted); font-weight: 500; }
.link.reset:hover { color: var(--danger); }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.play { width: 46px; height: 46px; background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.play:hover { background: var(--accent-strong); }
.icon-btn.play svg { width: 22px; height: 22px; }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.loading { opacity: 0.5; pointer-events: none; }

/* Menu */
.menu { position: relative; }
.menu-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 10; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12); padding: 4px;
}
.menu-list button, .menu-list a { display: block; text-decoration: none; box-sizing: border-box; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; color: var(--text); font: 13px var(--font); border-radius: 6px; cursor: pointer; }
.menu-list button:hover, .menu-list a:hover { background: var(--surface-2); }

/* Generate */
.generate-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; font-size: 13px; color: var(--muted); }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }
.error { color: var(--danger); margin: 0; font-weight: 500; flex-basis: 100%; }

/* Player */
.player-card { padding: 0; overflow: hidden; }
.stale { background: var(--highlight); padding: 9px 18px; font-size: 13px; border-bottom: 1px solid var(--border); }
.player { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.time { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); min-width: 36px; text-align: center; }
.seek { position: relative; flex: 1; height: 28px; cursor: pointer; display: flex; align-items: center; }
.seek-track { width: 100%; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.seek-track span { display: block; height: 100%; width: 0; background: var(--accent); }
#seekMarks span { position: absolute; top: 9px; width: 2px; height: 10px; background: var(--border); border-radius: 1px; pointer-events: none; }
.player select { width: auto; padding: 5px 8px; }

.script { list-style: none; margin: 0; padding: 6px; max-height: 420px; overflow-y: auto; counter-reset: line; }
.script li {
  display: flex; gap: 12px; align-items: baseline; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 15px;
  counter-increment: line;
}
.script li::before { content: counter(line); font-size: 11px; color: var(--muted); min-width: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.script li:hover { background: var(--surface-2); }
.script li.active { background: var(--accent-soft); color: var(--text); }
.script li .t { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Settings controls */
.field { display: block; margin-bottom: 14px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.label, .slider span { display: flex; justify-content: space-between; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.slider { display: block; margin-bottom: 12px; }
.slider span span { display: inline; margin: 0; }
.slider output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type='range'] { width: 100%; accent-color: var(--accent); margin: 0; }
select, input[type='text'], input[type='email'], input[type='password'], input[type='number'], input[type='search'] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: 14px var(--font);
}
select:focus, input:not([type='checkbox']):not([type='range']):focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.segmented { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { flex: 1; border: 0; background: none; color: var(--muted); padding: 6px 4px; border-radius: 7px; font: 500 13px var(--font); cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.voice-box { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.voice-head { display: flex; align-items: center; gap: 8px; }
.lang-tag { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.voice-nature { font-size: 12px; color: var(--muted); margin: 6px 0 10px; }
.voice-box .slider:last-child { margin-bottom: 0; }
.voice-box.disabled { opacity: 0.45; }
.ai-box .lang-tag { background: linear-gradient(135deg, #6d4aff, #c04bff); color: #fff; }
#aiVoicePanel .chips { margin: -4px 0 12px; }
.ai-note { margin: 0 0 4px; }
#engineSeg button[data-value='ai'].on { color: var(--accent); }
#engineSeg button:disabled { opacity: 0.45; cursor: not-allowed; }
.slider.disabled { opacity: 0.45; pointer-events: none; }
.notice.info { background: var(--accent-soft); margin: 0; flex-basis: 100%; }
.quota-choice { flex-basis: 100%; background: var(--highlight); border-radius: 12px; padding: 12px 14px; }
.quota-choice p { margin: 0 0 10px; font-weight: 500; }
.quota-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quota-actions .btn { background: var(--surface); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; font: 500 12px var(--font); cursor: pointer; }
.chips button:hover { border-color: var(--accent); }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.checks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; font-size: 13px; }
.checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checks input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500; z-index: 20;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar-hint { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 12px; }
  .project-title input[type='text'] { width: 100%; }
  #exportBtn { padding: 9px 12px; }
  #exportBtn span { display: none; }
  .export-panel { position: fixed; top: 64px; left: 12px; right: 12px; width: auto; }
  .format-chips { grid-template-columns: repeat(4, 1fr); }
  .dropzone { min-height: 240px; }
  .player { flex-wrap: wrap; }
  .seek { order: 10; flex-basis: 100%; }
  textarea { min-height: 260px; }
}

/* ================= App shell (dashboard, profile, admin) ================= */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 248px; flex: none;
  display: flex; flex-direction: column; gap: 22px; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto;
}
.sidebar .brand { padding: 4px 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .sidebar nav button {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px;
  color: var(--text); text-decoration: none; font: 500 14px var(--font); border: 0; background: none; cursor: pointer; text-align: left;
}
.sidebar nav svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.sidebar nav a:hover, .sidebar nav button:hover { background: var(--surface-2); }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a.active svg { color: #fff; }
.sidebar nav em { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; background: var(--danger); color: #fff; border-radius: 999px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.usage { background: var(--surface-2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.usage span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.usage strong { font-size: 14px; }
.usage small { font-size: 12px; color: var(--muted); }
.meter { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter span { display: block; height: 100%; background: var(--accent); }
.meter.warn span { background: var(--danger); }
.meter.small { height: 4px; max-width: 140px; }
.me { display: flex; align-items: center; gap: 10px; padding: 4px; min-width: 0; }
.me div { min-width: 0; }
.me strong { display: block; font-size: 13px; }
.me small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px; text-decoration: none;
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: center; gap: 14px; padding: 22px 32px 6px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; flex: 1; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-actions input[type='search'] { width: 230px; }
.page-body { padding: 18px 32px 48px; display: flex; flex-direction: column; gap: 18px; }
.page-body.narrow { max-width: 640px; }
.menu-toggle { display: none; }
.btn svg { width: 18px; height: 18px; }
.btn.danger { background: var(--danger); color: #fff; }
.danger-text { color: var(--danger) !important; }
.menu-list.right { left: auto; right: 0; min-width: 170px; }

/* Project cards */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.project-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.project-link { display: flex; flex-direction: column; gap: 8px; padding: 18px 54px 16px 18px; color: inherit; text-decoration: none; min-height: 150px; }
.project-link h2 { font-size: 17px; font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.project-preview {
  margin: 0; font-size: 13px; color: var(--muted); white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; flex: 1;
}
.project-meta { margin: 0; font-size: 12px; color: var(--muted); }
.project-card .menu { position: absolute; top: 12px; right: 12px; }
.empty { text-align: center; padding: 60px 20px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.empty svg { width: 48px; height: 48px; color: var(--accent); }
.empty h2 { font-size: 18px; margin: 10px 0 6px; }
.empty p { color: var(--muted); margin: 0 0 18px; }

/* Project editor top bar */
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-left { flex: 1; }
.project-title { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; }
.project-title input[type='text'] { width: 320px; max-width: 100%; }
.project-title .crumb { font-size: 11px; color: var(--muted); text-decoration: none; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.project-title .crumb:hover { color: var(--accent); }
.project-title input[type='text'] {
  border: 1px solid transparent; background: transparent; font-size: 17px; font-weight: 600; padding: 2px 6px; margin-left: -7px; border-radius: 6px;
}
.project-title input[type='text']:hover { border-color: var(--border); }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state[data-state='error'] { color: var(--danger); }
.usage-pill { font-size: 12px; background: var(--surface-2); border-radius: 999px; padding: 4px 10px; color: var(--muted); white-space: nowrap; }
.usage-pill.warn { color: var(--danger); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat strong { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.attention { border-color: var(--danger); }
.stat.attention strong { color: var(--danger); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Admin */
.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-row h3 { margin: 0; }
.segmented.compact button { padding: 5px 10px; font-size: 12px; }
.table-wrap { overflow-x: auto; margin: 0 -18px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell strong { display: block; font-weight: 600; }
.user-cell small { display: block; color: var(--muted); font-size: 12px; }
.user-cell strong small { display: inline; font-weight: 400; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.row-actions { display: inline-flex; align-items: center; gap: 6px; }
.row-actions .menu-list { text-align: left; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.active { background: var(--badge-active-bg); color: var(--badge-active); }
.badge.pending { background: var(--badge-pending-bg); color: var(--badge-pending); }
.badge.unverified { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.email-card .integration-head { margin-bottom: 4px; }
.email-card .integration-head h3 { margin: 0; }
.email-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; margin-top: 4px; }
.email-actions { justify-content: flex-start; margin-top: 4px; }
.badge.disabled { background: var(--badge-disabled-bg); color: var(--badge-disabled); }
.badge.admin { background: var(--accent-soft); color: var(--accent); }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.spaced { margin-top: 22px; }
.label small { font-weight: 400; }

/* Modal */
.modal { border: 0; border-radius: 16px; padding: 0; width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25); }
.modal::backdrop { background: rgba(15, 12, 30, 0.45); }
.modal form { padding: 22px; }
.modal-title { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); margin-bottom: 16px; }
.modal-body p { margin: 0 0 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-error { margin-top: 4px; }

.toast.error { background: var(--danger); color: #fff; }

/* Auth page */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1000px 500px at 10% -10%, var(--accent-soft), transparent), var(--bg);
}
.auth-wrap { display: grid; grid-template-columns: 1fr 400px; gap: 56px; align-items: center; max-width: 960px; width: 100%; }
.auth-intro h1 { font-size: 34px; line-height: 1.2; letter-spacing: -0.02em; margin: 28px 0 18px; }
.auth-intro ul { padding: 0; margin: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; color: var(--muted); }
.auth-intro li::before { content: '\2713'; color: var(--accent); font-weight: 700; margin-right: 10px; }
.auth-card { padding: 24px; }
.auth-card .segmented { margin-bottom: 18px; }
.auth-card .btn.block { margin-top: 4px; padding: 11px; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 0 0 16px; }
.success { color: var(--success); font-weight: 500; margin: 12px 0 0; }
.auth-card .error { margin-top: 12px; }
.verify-title { font-size: 20px; margin: 4px 0 6px; }
.verify-intro { margin: 0 0 16px; color: var(--muted); overflow-wrap: anywhere; }
.verify-intro strong { color: var(--text); }
#otpInput { text-align: center; font-size: 26px; font-weight: 700; letter-spacing: 10px; padding: 12px 8px; font-variant-numeric: tabular-nums; }
#otpInput::placeholder { letter-spacing: 10px; opacity: 0.35; }
.verify-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.verify-links .link { font-size: 13px; }
.verify-links .link:disabled { color: var(--muted); cursor: not-allowed; }

@media (max-width: 1500px) {
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2); }
  body.nav-open .sidebar { transform: none; }
  .menu-toggle { display: inline-grid; }
  .page-head { padding: 16px 16px 4px; }
  .page-head h1 { font-size: 22px; }
  .page-body { padding: 14px 16px 40px; }
  .page-actions { width: 100%; }
  .page-actions input[type='search'] { flex: 1; width: auto; min-width: 0; }
  .auth-wrap { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .auth-intro h1 { font-size: 24px; margin: 18px 0 10px; }
  .auth-intro ul { display: none; }
  .stat-row { grid-template-columns: 1fr; }
  .usage-pill, .save-state { display: none; }
}
