/* ============================================================
   Phantom Scribe v2 — Modern Light Theme
   Accent: warm amber/orange  |  No blues, no purples
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:          #F7F5F2;
  --surface:     #FFFFFF;
  --surface-2:   #F0EDE8;
  --surface-3:   #E8E3DC;
  --border:      #DDD8D0;
  --border-2:    #C8C0B4;

  /* Text */
  --text-1:      #1C1917;
  --text-2:      #57534E;
  --text-3:      #A8A29E;

  /* Accent (warm amber-orange) */
  --accent:      #D97706;
  --accent-2:    #B45309;
  --accent-light:#FEF3C7;
  --accent-hover:#92400E;

  /* Sidebar */
  --sidebar-bg:  #1C1917;
  --sidebar-text:#E7E5E4;
  --sidebar-muted:#A8A29E;
  --sidebar-active:#D97706;
  --sidebar-hover:rgba(255,255,255,0.07);

  /* Status */
  --success:     #16A34A;
  --success-bg:  #DCFCE7;
  --warning:     #D97706;
  --warning-bg:  #FEF3C7;
  --danger:      #DC2626;
  --danger-bg:   #FEE2E2;
  --info:        #0891B2;
  --info-bg:     #CFFAFE;

  /* Misc */
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:   0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);
  --transition:  all .2s ease;

  --sidebar-width:  240px;
  --chat-width:     340px;
  --header-height:  60px;
  --font:           'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Dark Mode ────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #111110;
  --surface:     #1C1917;
  --surface-2:   #242320;
  --surface-3:   #2E2B27;
  --border:      #3D3832;
  --border-2:    #57534E;
  --text-1:      #F5F4F2;
  --text-2:      #A8A29E;
  --text-3:      #57534E;
  --accent-light:#292219;
  --sidebar-bg:  #141312;
  --sidebar-hover:rgba(255,255,255,0.05);
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.6;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

img { max-width: 100%; }

/* ── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4, h5 { font-weight: 600; line-height: 1.3; color: var(--text-1); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p  { color: var(--text-2); }

/* ── Layout Shell ───────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

.app-shell.with-chat {
  grid-template-columns: var(--sidebar-width) 1fr var(--chat-width);
  grid-template-areas:
    "sidebar topbar chat"
    "sidebar main   chat";
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: .75rem; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sidebar-logo .logo-mark {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-weight: 700;
  font-size: .95rem;
  color: var(--sidebar-text);
  letter-spacing: -.01em;
}

.sidebar-logo .logo-sub {
  font-size: .7rem;
  color: var(--sidebar-muted);
}

.sidebar-nav {
  flex: 1;
  padding: .75rem .75rem;
}

.nav-section-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-muted);
  padding: .75rem .5rem .25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 450;
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
  margin-bottom: .1rem;
}

.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-item .nav-icon { width: 18px; opacity: .8; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: .75rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
}
.user-pill:hover { background: var(--sidebar-hover); }

.user-pill .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-pill .user-name {
  font-size: .8rem;
  font-weight: 500;
  color: var(--sidebar-text);
}
.user-pill .user-role {
  font-size: .7rem;
  color: var(--sidebar-muted);
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 2rem;
}

/* ── Chat Panel ────────────────────────────────────────────── */
.chat-panel {
  grid-area: chat;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.chat-header {
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .65rem;
  background: var(--surface);
}

.chat-header .ai-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.chat-header h3 { font-size: .9rem; font-weight: 600; }
.chat-header p { font-size: .75rem; color: var(--text-3); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.chat-bubble {
  max-width: 88%;
  padding: .6rem .85rem;
  border-radius: 12px;
  font-size: .85rem;
  line-height: 1.5;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text-1);
  border-bottom-left-radius: 3px;
}

.chat-bubble.system {
  align-self: center;
  background: var(--accent-light);
  color: var(--accent-2);
  font-size: .78rem;
  border-radius: 20px;
  padding: .3rem .85rem;
  text-align: center;
  max-width: 95%;
}

.chat-bubble .bubble-time {
  font-size: .68rem;
  opacity: .6;
  margin-top: .25rem;
}

.chat-typing {
  align-self: flex-start;
  background: var(--surface-2);
  border-radius: 12px;
  padding: .7rem 1rem;
  display: flex;
  gap: 4px;
  align-items: center;
}
.chat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: bounce .9s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

.chat-input-area {
  padding: .75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-row {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .55rem .8rem;
  font-family: var(--font);
  font-size: .85rem;
  background: var(--surface-2);
  color: var(--text-1);
  min-height: 40px;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color .15s;
}
.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-quick-btns {
  display: flex;
  gap: .35rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}

.quick-btn {
  font-size: .72rem;
  padding: .25rem .6rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 1.25rem 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-body { padding: 1.25rem 1.5rem; }
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Stat cards ────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--accent-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-label { font-size: .8rem; color: var(--text-3); font-weight: 500; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-1); line-height: 1.2; }
.stat-sub { font-size: .75rem; color: var(--text-3); margin-top: .1rem; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .52rem 1.1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

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

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

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

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

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-xl { padding: .9rem 2rem; font-size: 1.05rem; }

.btn-icon {
  width: 34px; height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.form-control {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem;
  background: var(--surface);
  color: var(--text-1);
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217,119,6,.12);
}

textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }

.form-hint { font-size: .77rem; color: var(--text-3); margin-top: .3rem; }
.form-error { font-size: .77rem; color: var(--danger); margin-top: .3rem; }

.form-grid { display: grid; gap: 1.25rem; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-neutral  { background: var(--surface-3); color: var(--text-2); }
.badge-success  { background: var(--success-bg); color: var(--success); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-danger   { background: var(--danger-bg); color: var(--danger); }
.badge-info     { background: var(--info-bg); color: var(--info); }
.badge-accent   { background: var(--accent-light); color: var(--accent-2); }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: .85rem 1.1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}
.alert-success { background: var(--success-bg); border-color: #86EFAC; color: #15803D; }
.alert-warning { background: var(--warning-bg); border-color: #FCD34D; color: #92400E; }
.alert-danger  { background: var(--danger-bg);  border-color: #FCA5A5; color: #991B1B; }
.alert-info    { background: var(--info-bg);    border-color: #A5F3FC; color: #0E7490; }

/* ── Table ──────────────────────────────────────────────────── */
.table-container { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }

table.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  text-align: left;
  padding: .75rem 1rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.data-table tbody td {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  color: var(--text-1);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }

/* ── Progress bar ───────────────────────────────────────────── */
.progress {
  height: 8px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .6s ease;
}
.progress-bar.success { background: var(--success); }
.progress-bar.danger  { background: var(--danger); }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab-btn {
  padding: .65rem 1.25rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  font-family: var(--font);
}
.tab-btn:hover { color: var(--text-1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-lg { max-width: 720px; }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  background: var(--surface-2);
}

/* ── Book cards ─────────────────────────────────────────────── */
.books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.book-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.book-card-title { font-weight: 700; font-size: 1rem; color: var(--text-1); margin-bottom: .1rem; }
.book-card-sub { font-size: .8rem; color: var(--text-3); }
.book-card-meta { display: flex; gap: 1rem; font-size: .78rem; color: var(--text-3); }

.book-card-progress { }
.book-card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: auto; }

/* ── Writer layout ───────────────────────────────────────────── */
.writer-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  height: calc(100vh - var(--header-height));
}

.writer-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.writer-main { overflow-y: auto; padding: 1.5rem; }

.chapter-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  font-size: .85rem;
}
.chapter-item:hover { background: var(--surface-2); }
.chapter-item.active { background: var(--accent-light); color: var(--accent-2); font-weight: 600; }
.chapter-item.complete .ch-num { background: var(--success); color: #fff; }

.ch-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: .72rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Agent status */
.agent-bar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .85rem;
  margin-bottom: 1.25rem;
  transition: var(--transition);
}
.agent-bar.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-2);
}

.agent-pulse {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.agent-bar.active .agent-pulse {
  background: var(--accent);
  animation: apulse 1.8s ease-in-out infinite;
}
@keyframes apulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(217,119,6,.5); }
  50% { box-shadow: 0 0 0 7px rgba(217,119,6,0); }
}

/* Section content display */
.section-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  line-height: 1.8;
  font-size: .95rem;
  color: var(--text-1);
  min-height: 300px;
}
.section-content h2, .section-content h3 { margin: 1.5rem 0 .75rem; }
.section-content p { margin-bottom: 1rem; }

/* ── Activity log ───────────────────────────────────────────── */
.activity-log {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-height: 260px;
  overflow-y: auto;
}

.log-item {
  display: flex;
  gap: .65rem;
  font-size: .8rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.log-time { color: var(--text-3); font-family: monospace; flex-shrink: 0; }
.log-msg { color: var(--text-2); }

/* ── Admin panel ────────────────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-decoration: none;
  transition: var(--transition);
  display: block;
}
.admin-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); color: var(--text-1); }

.admin-card-icon { font-size: 1.75rem; margin-bottom: .75rem; }
.admin-card-title { font-weight: 700; font-size: .95rem; margin-bottom: .25rem; color: var(--text-1); }
.admin-card-desc { font-size: .8rem; color: var(--text-3); }

/* ── Settings page ──────────────────────────────────────────── */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 2rem; }

.settings-nav { display: flex; flex-direction: column; gap: .25rem; }
.settings-nav a {
  padding: .55rem .85rem;
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-2);
  text-decoration: none;
  transition: var(--transition);
  font-weight: 450;
}
.settings-nav a:hover { background: var(--surface-2); color: var(--text-1); }
.settings-nav a.active { background: var(--accent-light); color: var(--accent-2); font-weight: 600; }

.settings-section { max-width: 640px; }
.settings-section h2 { margin-bottom: 1.5rem; }

.settings-divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; }
.page-header p { font-size: .875rem; color: var(--text-3); margin-top: .2rem; }

/* ── Login page ─────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-header {
  background: var(--accent);
  padding: 2rem;
  text-align: center;
  color: #fff;
}

.auth-header h1 { color: #fff; font-size: 1.5rem; }
.auth-header p { color: rgba(255,255,255,.8); font-size: .85rem; margin-top: .25rem; }

.auth-body { padding: 2rem; }

/* ── Wizard ─────────────────────────────────────────────────── */
.wizard-steps {
  display: flex;
  gap: 0;
  margin-bottom: 2rem;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.wizard-step {
  flex: 1;
  padding: .75rem 1rem;
  text-align: center;
  font-size: .8rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-3);
  transition: var(--transition);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
}
.wizard-step:last-child { border-right: none; }
.wizard-step.active { background: var(--accent); color: #fff; font-weight: 600; }
.wizard-step.done { background: var(--success-bg); color: var(--success); }

.wizard-step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  font-size: .7rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.wizard-step.active .wizard-step-num { background: rgba(255,255,255,.3); }
.wizard-step.done .wizard-step-num { background: var(--success); color: #fff; }

/* Template cards */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }

.template-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  background: var(--surface);
}
.template-card:hover { border-color: var(--accent); background: var(--accent-light); }
.template-card.selected { border-color: var(--accent); background: var(--accent-light); }

.template-icon { font-size: 2rem; margin-bottom: .5rem; }
.template-name { font-weight: 700; font-size: .9rem; color: var(--text-1); }
.template-desc { font-size: .75rem; color: var(--text-3); margin-top: .25rem; }

/* ── Toggle switch ──────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition);
}
.toggle-track::before {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::before { transform: translateX(18px); }

/* ── Spinner ────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
.spinner-sm { width: 14px; height: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: .5; }
.empty-state h3 { color: var(--text-2); margin-bottom: .5rem; }
.empty-state p { font-size: .875rem; margin-bottom: 1.5rem; }

/* ── Search bar ─────────────────────────────────────────────── */
.search-bar {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-bar input {
  padding: .5rem .85rem .5rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--surface);
  color: var(--text-1);
  width: 220px;
  transition: var(--transition);
}
.search-bar input:focus { outline: none; border-color: var(--accent); width: 280px; }
.search-bar .search-icon {
  position: absolute;
  left: .7rem;
  color: var(--text-3);
  font-size: .9rem;
  pointer-events: none;
}

/* ── Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--text-3);
  margin-bottom: 1.5rem;
}
.breadcrumb a { color: var(--text-3); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { color: var(--border-2); }
.breadcrumb .current { color: var(--text-2); font-weight: 500; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: 500;
  padding: .35rem;
  display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  font-size: .875rem;
  color: var(--text-1);
  border-radius: 5px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-bg); }
.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: .25rem; }

/* ── Utilities ──────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.w-full { width: 100%; }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .72rem; }
.text-muted { color: var(--text-3); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-accent  { color: var(--accent); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.p-4 { padding: 1rem; }
.grid { display: grid; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.gap-grid { gap: 1.25rem; }
.rounded { border-radius: var(--radius); }
.hidden { display: none !important; }

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

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell.with-chat { grid-template-columns: var(--sidebar-width) 1fr; grid-template-areas: "sidebar topbar" "sidebar main"; }
  .chat-panel { display: none; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { position: fixed; left: -240px; width: 240px; transition: left .25s; z-index: 9000; }
  .sidebar.open { left: 0; }
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .main-content { padding: 1rem; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: 1fr; }
  .writer-layout { grid-template-columns: 1fr; }
  .writer-sidebar { display: none; }
}

/* ── Notification toast ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 260px;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--accent); }
