/* =========================================================
   SmartSlides AI — stylesheet
   Design language: "studio desk" — a calm paper-toned workspace
   with one confident cobalt accent and a warm amber for highlights.
   Headings use Fraunces (a display serif with real character),
   body/UI text uses Inter.
   ========================================================= */

:root {
  /* ---- palette (light) ---- */
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --ink: #1C1B22;
  --ink-soft: #5B5967;
  --border: #E4E0D6;
  --accent: #3457FF;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EBFF;
  --highlight: #E8A33D;
  --danger: #C9432F;
  --success: #2E8B57;

  /* ---- layout ---- */
  --sidebar-w: 248px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-card: 0 1px 2px rgba(28,27,34,0.06), 0 8px 24px rgba(28,27,34,0.05);

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
  --bg: #131218;
  --surface: #1B1A22;
  --surface-raised: #201F29;
  --ink: #F1EFEA;
  --ink-soft: #A6A3B2;
  --border: #34323E;
  --accent: #7C93FF;
  --accent-ink: #14131C;
  --accent-soft: #262A4A;
  --highlight: #E8B563;
  --danger: #E17361;
  --success: #6FC493;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 0.4em;
  color: var(--ink);
}

button {
  font-family: var(--font-ui);
}

code {
  background: var(--accent-soft);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 24px;
  transition: transform 0.25s ease;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 10px;
}
.brand-mark {
  color: var(--accent);
  font-size: 1.1rem;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.brand-name-accent { color: var(--accent); }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--accent-soft); color: var(--ink); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-item:disabled { opacity: 0.4; cursor: not-allowed; }
.nav-item:disabled:hover { background: transparent; color: var(--ink-soft); }
.nav-icon { width: 1.1em; text-align: center; }

.sidebar-footer { margin-top: auto; }

.token-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}
.dot.is-connected { background: var(--success); }

/* ---------- MAIN COLUMN ---------- */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar-title {
  font-size: 1.05rem;
  margin: 0;
  flex: 1;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.icon-btn:hover { background: var(--accent-soft); }
.only-mobile { display: none; }

.content {
  padding: 28px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* =========================================================
   VIEWS
   ========================================================= */
.view { display: none; }
.view.is-active { display: block; animation: fade-in 0.2s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Dashboard hero ---------- */
.hero-card {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 65%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  margin-bottom: 32px;
}
.eyebrow {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.82rem;
  margin: 0 0 10px;
}
.hero-text h2 {
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  max-width: 20ch;
  margin-bottom: 12px;
}
.hero-sub {
  color: var(--ink-soft);
  max-width: 60ch;
  line-height: 1.55;
  margin: 0 0 22px;
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-row h3, .section-row h2 { margin: 0; font-size: 1.05rem; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  text-align: center;
  color: var(--ink-soft);
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease;
}
.deck-card:hover { transform: translateY(-2px); }
.deck-card h4 { margin: 0 0 6px; font-size: 0.98rem; font-family: var(--font-ui); font-weight: 600; }
.deck-card p { margin: 0; font-size: 0.8rem; color: var(--ink-soft); }
.deck-card .deck-card-actions { margin-top: 10px; display: flex; gap: 8px; }

/* ---------- Panels / forms ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-card);
}
.panel-narrow { max-width: 560px; }
.panel-title { font-size: 1.3rem; }
.panel-sub { color: var(--ink-soft); margin: 0 0 22px; line-height: 1.5; max-width: 62ch; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
}
.field-wide { grid-column: 1 / -1; }
.field-hint { font-weight: 400; opacity: 0.8; }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  font-family: var(--font-ui);
  font-size: 0.94rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.5; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.hint { font-size: 0.78rem; color: var(--ink-soft); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.12s ease, background 0.12s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-secondary:hover { filter: brightness(0.97); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Outline view ---------- */
.outline-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.outline-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg);
}
.outline-item .handle { color: var(--ink-soft); cursor: grab; }
.outline-item input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  padding: 4px 6px;
}
.outline-item input:focus { box-shadow: none; border-bottom: 1px solid var(--accent); }
.outline-item .icon-btn { width: 30px; height: 30px; font-size: 0.85rem; }

/* ---------- Editor layout ---------- */
.editor-layout {
  display: grid;
  grid-template-columns: 168px 1fr 320px;
  gap: 18px;
  align-items: start;
}

.thumb-rail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  padding-right: 4px;
}
.thumb {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  aspect-ratio: 16/9;
  padding: 8px;
  cursor: pointer;
  font-size: 0.6rem;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  text-align: left;
}
.thumb strong { font-size: 0.62rem; color: var(--ink); font-family: var(--font-ui); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thumb.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thumb .thumb-index { font-weight: 700; color: var(--accent); }

.canvas-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--ink-soft);
  flex-wrap: wrap;
  gap: 8px;
}
.canvas-toolbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-picker { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
.theme-picker select { padding: 6px 8px; font-size: 0.8rem; }

.slide-canvas {
  aspect-ratio: 16/9;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
}

.canvas-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.regen-detail select { padding: 7px 10px; font-size: 0.8rem; }

.edit-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 88px;
}
.edit-panel h3 { font-size: 0.95rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.presentation-name-row input { width: 100%; }
.export-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Library ---------- */
/* reuses .grid-cards / .deck-card */

/* ---------- Settings ---------- */
.security-note {
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.5;
  margin-top: 14px;
}

/* =========================================================
   LOADING + TOASTS
   ========================================================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(19,18,24,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.loading-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-card);
}
.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow-card);
  max-width: 320px;
  animation: fade-in 0.2s ease;
}
.toast.is-error { background: var(--danger); color: #fff; }
.toast.is-success { background: var(--success); color: #fff; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 980px) {
  .editor-layout {
    grid-template-columns: 120px 1fr;
  }
  .edit-panel {
    grid-column: 1 / -1;
    position: static;
  }
}

/* =========================================================
   PRINT (used for PDF export — see export.js)
   ========================================================= */
#print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block;
    position: absolute;
    top: 0; left: 0;
    width: 100%;
  }
  .print-slide {
    width: 100%;
    height: 100vh;
    page-break-after: always;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 60px 70px;
    box-sizing: border-box;
    font-family: var(--font-ui);
  }
  .print-slide h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 22px;
  }
  .print-slide ul { font-size: 1.1rem; line-height: 1.7; padding-left: 1.2em; }
}

@media (max-width: 720px) {
  .only-mobile { display: flex; }
  .sidebar {
    position: fixed;
    z-index: 40;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 0 0 0 2000px rgba(0,0,0,0);
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 2000px rgba(0,0,0,0.35); }
  .form-grid { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .thumb-rail { flex-direction: row; overflow-x: auto; max-height: none; }
  .thumb { min-width: 110px; }
  .content { padding: 18px; }
  .panel { padding: 22px; }
}

/* Fix: hide loading overlay until needed */
.loading-overlay[hidden] {
  display: none !important;
}
