/* ── Tokens ────────────────────────────────────────────────── */
:root {
  --bg:         #f5f1ea;
  --surface:    #fffdf9;
  --surface2:   #f1ece3;
  --surface3:   #e9e2d6;
  --border:     #e2dacd;
  --text:       #211d18;
  --muted:      #776d62;
  --primary:    #b5642a;
  --primary-d:  #964f1d;
  --primary-bg: #f8e9dc;
  --success:    #2f7a4a;
  --success-bg: #e2f2e7;
  --danger:     #b83a3a;
  --danger-bg:  #f9e3e3;
  --warning:    #a56a12;
  --warning-bg: #f8eed6;
  --info-bg:    #e6eef6;
  --info:       #2f5f8a;
  --radius:     10px;
  --radius-lg:  16px;
  --shadow:     0 1px 2px rgba(40,30,20,.06), 0 1px 3px rgba(40,30,20,.08);
  --shadow-lg:  0 14px 34px -8px rgba(40,30,20,.22), 0 4px 10px -4px rgba(40,30,20,.10);
  --transition: 160ms ease;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, sans-serif;
  --serif:      'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --mono:       ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg:         #15120e;
  --surface:    #1d1913;
  --surface2:   #26211a;
  --surface3:   #302a22;
  --border:     #372f26;
  --text:       #ede6da;
  --muted:      #9d9285;
  --primary:    #d98c52;
  --primary-d:  #e9a56f;
  --primary-bg: #33241a;
  --success:    #6fc28c;
  --success-bg: #17301f;
  --danger:     #e07777;
  --danger-bg:  #3a1c1c;
  --warning:    #e3b25a;
  --warning-bg: #352a12;
  --info-bg:    #1a2733;
  --info:       #7fb1dc;
  --shadow:     0 1px 3px rgba(0,0,0,.45);
  --shadow-lg:  0 14px 34px -8px rgba(0,0,0,.65);
  color-scheme: dark;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.6; min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}
img, svg { display: block; max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
.inline { display: inline; }
.hidden, [hidden] { display: none !important; }

/* ── Layout ────────────────────────────────────────────────── */
.wrap    { max-width: 1120px; margin: 0 auto; padding: 0 24px; }
.wrap-xs { max-width: 440px;  margin: 0 auto; padding: 0 24px; }
main.wrap { padding-top: 32px; padding-bottom: 64px; }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar-inner { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; min-height: 60px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--serif); font-weight: 600; font-size: 1.15rem; }
.topbar-brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; }
.brand-mark svg { width: 20px; height: 20px; }
.topbar-context { flex: 1; text-align: center; font-weight: 500; font-size: .95rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 12px; }
.topbar-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.topbar-back { margin-left: -8px; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px;
  border-radius: var(--radius); font-weight: 500; font-size: .875rem;
  border: 1px solid transparent; cursor: pointer; transition: all var(--transition);
  white-space: nowrap; user-select: none; line-height: 1.4; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-sm svg { width: 13px; height: 13px; }
.btn-lg { padding: 13px 24px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
  padding: 8px; border-radius: var(--radius); background: transparent; color: var(--muted);
  border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--transition); text-decoration: none;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-icon svg { width: 17px; height: 17px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.theme-toggle {
  width: 36px; height: 36px; border-radius: 9px; background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
  transition: all var(--transition);
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: none; }

/* ── Badges ────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; line-height: 1.6; white-space: nowrap; }
.badge-admin   { background: var(--primary-bg); color: var(--primary); font-family: var(--font); }
.badge-muted   { background: var(--surface3); color: var(--muted); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }

/* ── Cards ─────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-body { padding: 22px 24px; }
.card-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 1.1rem; }
.card-header .spacer { flex: 1; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-hint { font-size: .78rem; color: var(--muted); margin-top: 5px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 13px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: border var(--transition), box-shadow var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.form-textarea { min-height: 96px; resize: vertical; }
.form-select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23887d70' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.form-check input { width: 16px; height: 16px; accent-color: var(--primary); }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .form-input { flex: 1; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: .875rem; margin-bottom: 16px; border: 1px solid transparent; }
.alert svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 2px; }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-info    { background: var(--info-bg);    color: var(--info); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert code { font-family: var(--mono); background: rgba(0,0,0,.08); padding: 1px 6px; border-radius: 5px; user-select: all; }

/* ── Page header / stats ───────────────────────────────────── */
.page-header { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-title { font-size: 1.9rem; }
.page-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 1.5rem; font-weight: 600; font-family: var(--serif); }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ── Section ───────────────────────────────────────────────── */
.section { margin-bottom: 40px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-title { font-size: 1.35rem; }
.section-count { color: var(--muted); font-size: .85rem; }
.section-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Rows (recordings / documents / people) ────────────────── */
.rows { display: flex; flex-direction: column; gap: 10px; }
.row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; box-shadow: var(--shadow);
}
.row-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-bg); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.row-icon svg { width: 20px; height: 20px; }
.row-icon.doc { background: var(--info-bg); color: var(--info); }
.row-icon.person { background: var(--surface3); color: var(--muted); }
.row-main { flex: 1; min-width: 220px; }
.row-title { font-weight: 600; font-size: .98rem; word-break: break-word; }
.row-title a { color: inherit; }
.row-meta { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.row-meta .dot::before { content: '·'; }
.row-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.row-player { width: 100%; }
.row-player audio { width: 100%; height: 40px; }
.row.inactive { opacity: .6; }

/* ── Dropdown ──────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 40; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px;
  font-size: .85rem; color: var(--text); background: none; border: none; cursor: pointer; text-decoration: none;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface2); text-decoration: none; }
.dropdown-menu svg { width: 15px; height: 15px; color: var(--muted); }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .danger svg { color: var(--danger); }
.dropdown-menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 2px; }

/* ── Empty state ───────────────────────────────────────────── */
.empty { text-align: center; padding: 44px 20px; border: 1px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted); }
.empty svg { width: 36px; height: 36px; margin: 0 auto 10px; opacity: .6; }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty p { font-size: .88rem; }

/* ── Drop zone & upload queue ──────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: 30px 20px; text-align: center;
  background: var(--surface); cursor: pointer; transition: all var(--transition);
}
.dropzone:hover, .dropzone.dragging { border-color: var(--primary); background: var(--primary-bg); }
.dropzone svg { width: 34px; height: 34px; margin: 0 auto 10px; color: var(--primary); }
.dropzone-title { font-weight: 600; }
.dropzone-sub { font-size: .82rem; color: var(--muted); margin-top: 3px; }
.dropzone input { display: none; }
.upload-queue { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.upload-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.upload-item-top { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.upload-item-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-status { color: var(--muted); font-size: .78rem; }
.upload-item-status.done  { color: var(--success); }
.upload-item-status.error { color: var(--danger); }
.progress { height: 5px; background: var(--surface3); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: var(--primary); width: 0; transition: width 200ms ease; }

/* ── Login ─────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 32px; box-shadow: var(--shadow-lg); }
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; }
.login-brand .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
.login-brand .brand-mark svg { width: 24px; height: 24px; }
.login-name { font-family: var(--serif); font-weight: 600; font-size: 1.35rem; }
.login-title { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 24px; }
.login-foot { text-align: center; margin-top: 18px; font-size: .8rem; color: var(--muted); }
.login-theme { position: fixed; top: 16px; right: 16px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,14,8,.55); z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 820px; }
.modal-header { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-title { font-weight: 600; font-size: 1.05rem; flex: 1; font-family: var(--serif); }
.modal-body { padding: 22px; overflow: auto; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.confirm-body { text-align: center; padding: 30px 24px 18px; }
.confirm-title { font-weight: 600; font-size: 1.1rem; font-family: var(--serif); }
.confirm-sub { color: var(--muted); font-size: .88rem; margin-top: 6px; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-size: .85rem; box-shadow: var(--shadow-lg); animation: toast-in 200ms ease; max-width: 340px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── People grid (admin) ───────────────────────────────────── */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.person { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.person-top { display: flex; align-items: center; gap: 12px; }
.person-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--primary-bg); color: var(--primary); display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; flex-shrink: 0; }
.person-name { font-weight: 600; font-size: 1.02rem; }
.person-meta { font-size: .8rem; color: var(--muted); }
.person-stats { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); }
.person-stats strong { color: var(--text); font-weight: 600; }
.person-actions { display: flex; gap: 6px; align-items: center; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--border); }
.person-actions .spacer { flex: 1; }
.person.inactive { opacity: .6; }

/* ── Editor page ───────────────────────────────────────────── */
body.editor-page { display: flex; flex-direction: column; min-height: 100vh; }
.editor-shell { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0; }
.editor-main { min-width: 0; display: flex; flex-direction: column; }
.editor-toolbar-bar {
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 60px; z-index: 30;
}
.editor-head { padding: 14px 28px 6px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.editor-title { flex: 1; min-width: 200px; font-family: var(--serif); font-size: 1.5rem; font-weight: 600; border: none; background: transparent; padding: 4px 6px; margin-left: -6px; border-radius: 6px; color: var(--text); }
.editor-title:hover { background: var(--surface2); }
.editor-title:focus { outline: none; background: var(--surface2); box-shadow: 0 0 0 2px var(--primary-bg); }
.save-status { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.save-status.dirty::before { background: var(--warning); }
.save-status.saving::before { background: var(--info); animation: pulse 1s infinite; }
.save-status.error::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.editor-audio { padding: 8px 28px 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--border); background: var(--surface2); }
.editor-audio audio { flex: 1; min-width: 240px; height: 40px; }
.editor-audio .form-select { width: auto; max-width: 300px; padding: 7px 34px 7px 10px; font-size: .85rem; }
.editor-audio-label { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.editor-body { padding: 28px; flex: 1; }
.editor-paper { max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
#editor { min-height: 60vh; font-size: 1.05rem; line-height: 1.75; }
.ql-toolbar.ql-snow { border: none; border-top: 1px solid var(--border); background: var(--surface); padding: 8px 24px; }
.ql-toolbar.ql-snow .ql-formats { margin-right: 12px; }
.ql-container.ql-snow { border: none; font-family: var(--serif); }
.ql-editor { padding: 34px 44px 60px; }
.ql-editor.ql-blank::before { color: var(--muted); font-style: italic; left: 44px; }
.ql-editor h1, .ql-editor h2, .ql-editor h3 { font-family: var(--serif); margin: 1.1em 0 .4em; }
.ql-editor p { margin-bottom: .55em; }
.ql-editor blockquote { border-left: 3px solid var(--primary); color: var(--muted); padding-left: 16px; margin: .8em 0; }
.ql-editor pre.ql-syntax, .ql-editor .ql-code-block-container { background: var(--surface2); color: var(--text); border-radius: 8px; font-family: var(--mono); font-size: .85em; }
.ql-editor a { color: var(--primary); }
.ql-snow .ql-stroke { stroke: var(--muted); }
.ql-snow .ql-fill { fill: var(--muted); }
.ql-snow .ql-picker { color: var(--muted); }
.ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border) !important; }
.ql-snow .ql-picker-item:hover, .ql-snow .ql-picker-label:hover { color: var(--primary); }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke, .ql-snow .ql-picker-label:hover .ql-stroke, .ql-snow .ql-picker-label.ql-active .ql-stroke, .ql-snow .ql-picker-item.ql-selected .ql-stroke { stroke: var(--primary); }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--primary); }
.ql-snow.ql-toolbar button.ql-active, .ql-snow .ql-picker-label.ql-active { color: var(--primary); }
.ql-snow .ql-tooltip { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-lg); }
.ql-snow .ql-tooltip input[type=text] { background: var(--surface2); border-color: var(--border); color: var(--text); }
.ql-snow .ql-tooltip a.ql-action::after, .ql-snow .ql-tooltip a.ql-remove::before { color: var(--primary); }
.ql-snow .ql-tooltip a.ql-preview { color: var(--primary); }
.ql-snow .ql-tooltip[data-mode=link]::before, .ql-snow .ql-tooltip::before { color: var(--muted); }

.editor-side { border-left: 1px solid var(--border); background: var(--surface); padding: 20px; overflow-y: auto; position: sticky; top: 60px; height: calc(100vh - 60px); }
.side-title { font-size: 1rem; margin-bottom: 4px; }
.side-sub { font-size: .78rem; color: var(--muted); margin-bottom: 14px; }
.side-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.side-actions .btn { justify-content: center; }
.side-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.versions { display: flex; flex-direction: column; gap: 8px; }
.version { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--bg); }
.version-top { display: flex; align-items: center; gap: 8px; }
.version-num { font-weight: 600; font-size: .85rem; }
.version-label { font-size: .85rem; margin-top: 2px; word-break: break-word; }
.version-meta { font-size: .74rem; color: var(--muted); margin-top: 2px; }
.version-actions { display: flex; gap: 2px; margin-top: 6px; flex-wrap: wrap; }
.version-actions .btn-icon { padding: 5px; }
.version-actions .btn-icon svg { width: 15px; height: 15px; }
.version-actions .dropdown-menu { right: auto; left: 0; }
.preview-doc { font-family: var(--serif); line-height: 1.7; font-size: 1rem; }
.preview-doc p { margin-bottom: .55em; }
.preview-doc h1, .preview-doc h2, .preview-doc h3 { margin: 1em 0 .4em; }
.preview-doc blockquote { border-left: 3px solid var(--primary); color: var(--muted); padding-left: 16px; margin: .8em 0; }
.preview-doc pre { background: var(--surface2); padding: 10px 14px; border-radius: 8px; font-family: var(--mono); font-size: .85em; white-space: pre-wrap; }
.preview-doc ul, .preview-doc ol { padding-left: 1.5em; margin-bottom: .6em; }
.preview-doc .ql-indent-1 { margin-left: 1.5em; } .preview-doc .ql-indent-2 { margin-left: 3em; } .preview-doc .ql-indent-3 { margin-left: 4.5em; }

/* ── Utilities ─────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .78rem; }
.text-danger { color: var(--danger); }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 14px; } .mt-4 { margin-top: 20px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 14px; } .mb-4 { margin-bottom: 20px; }
.flex { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.code { font-family: var(--mono); font-size: .85em; background: var(--surface2); padding: 2px 6px; border-radius: 5px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .editor-shell { grid-template-columns: 1fr; }
  .editor-side { position: static; height: auto; border-left: none; border-top: 1px solid var(--border); }
  .editor-body { padding: 16px; }
  .ql-editor { padding: 24px 22px 50px; }
  .ql-editor.ql-blank::before { left: 22px; }
  .editor-head, .editor-audio { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  main.wrap { padding-top: 22px; }
  .topbar-context { display: none; }
  .topbar-nav .btn-sm { padding: 6px 8px; }
  .page-title { font-size: 1.55rem; }
  .row { padding: 12px 14px; }
  .row-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
  .modal-body { padding: 18px; }
}

/* ── Read-along ────────────────────────────────────────────── */
.readalong { white-space: normal; overflow-wrap: anywhere; max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 34px 44px 60px; font-size: 1.05rem; line-height: 1.85; }
.readalong .snt { border-radius: 4px; transition: background var(--transition); }
.readalong .snt:hover { background: var(--surface2); cursor: pointer; }
.readalong .snt-active { background: var(--primary-bg); box-shadow: 0 0 0 2px var(--primary-bg); color: var(--text); }
.readalong .snt-cursor { outline: 2px solid var(--primary); outline-offset: 2px; }
.readalong .snt-time { display: inline-block; font-family: var(--mono); font-size: .68rem; color: var(--primary); background: var(--primary-bg); border-radius: 999px; padding: 0 6px; margin-right: 6px; vertical-align: middle; line-height: 1.6; cursor: pointer; user-select: none; }
.readalong .snt-time:hover { background: var(--primary); color: #fff; }
.ra-toolbar { max-width: 820px; margin: 0 auto 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; font-size: .82rem; }
.ra-count { font-weight: 600; white-space: nowrap; }
.ra-hint { color: var(--muted); }
.ra-toolbar kbd { font-family: var(--mono); font-size: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
#readAlongBtn.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
@media (max-width: 640px) { .readalong { padding: 22px 18px 50px; } .ra-hint { display: none; } }

/* ── Compact recording rows ────────────────────────────────── */
.row.rec { padding: 0; flex-direction: column; align-items: stretch; gap: 0; overflow: hidden; }
.rec-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; background: none; border: none; cursor: pointer; text-align: left; color: inherit; }
.rec-head:hover { background: var(--surface2); }
.rec-head .row-icon { width: 34px; height: 34px; border-radius: 9px; }
.rec-head .row-icon svg { width: 17px; height: 17px; }
.rec-head .row-main { min-width: 0; }
.rec-head .row-title { display: block; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-head .row-meta { margin-top: 0; }
.rec-chevron { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; transition: transform var(--transition); }
.rec.open .rec-chevron { transform: rotate(180deg); }
.rec.open .rec-head { background: var(--surface2); }
.rec-body { padding: 12px 14px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.rec-body audio { width: 100%; height: 40px; }
.rec-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rec-foot .row-actions { margin-left: auto; width: auto; }
.rows-compact { gap: 6px; }
@media (max-width: 640px) {
  .rec-head { padding: 10px 12px; gap: 10px; }
  .rec-foot .row-actions { width: 100%; justify-content: flex-end; }
}

/* ── Phone editor: give the page to the text ───────────────── */
@media (max-width: 900px) {
  body.editor-page .topbar { position: static; }
  .editor-toolbar-bar { top: 0; }
  .editor-head { padding: 8px 12px 6px; gap: 8px; }
  .editor-title { font-size: 1.1rem; min-width: 120px; flex-basis: 100%; order: -1; }
  .editor-head .btn-sm span, .editor-head .badge { display: none; }
  .editor-head .btn-sm { padding: 7px 9px; }
  .editor-head .btn-sm svg { width: 15px; height: 15px; }
  .save-status { font-size: .74rem; }
  .editor-audio { padding: 6px 12px 8px; gap: 8px; }
  .editor-audio .editor-audio-label, .editor-audio .text-xs { display: none; }
  .editor-audio.has-audio .form-select { display: none; }
  .editor-audio .form-select { width: 100%; max-width: none; }
  .editor-audio audio { min-width: 0; height: 36px; }
  .ql-toolbar.ql-snow { padding: 4px 8px; display: flex; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .ql-toolbar.ql-snow::-webkit-scrollbar { display: none; }
  .ql-toolbar.ql-snow .ql-formats { margin-right: 8px; flex-shrink: 0; display: inline-flex; }
  .editor-body { padding: 0; }
  .editor-paper { border: none; border-radius: 0; box-shadow: none; max-width: none; }
  #editor { min-height: calc(100vh - 220px); }
  .ql-editor { padding: 18px 16px 90px; font-size: 1.02rem; }
  .ql-editor.ql-blank::before { left: 16px; }
  .readalong { border: none; border-radius: 0; box-shadow: none; padding: 18px 16px 80px; }
  .ra-toolbar { border-radius: 0; margin: 0; }
  .editor-side { padding: 16px; }
}

/* ── Recorder ──────────────────────────────────────────────── */
.recorder { padding: 16px 18px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.rec-top { display: flex; align-items: center; gap: 10px; }
.rec-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.rec-title svg { width: 18px; height: 18px; color: var(--primary); }
.rec-timer { margin-left: auto; font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.recorder[data-state="recording"] .rec-timer { color: var(--danger); }
.recorder[data-state="recording"] .rec-title svg { animation: pulse 1.2s infinite; color: var(--danger); }
.rec-wave { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); min-height: 74px; overflow: hidden; }
.rec-meta { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: var(--muted); }
.rec-meta .rec-format { margin-left: auto; }
.rec-name-row .form-input { max-width: 420px; }
.rec-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rec-controls .btn svg { width: 14px; height: 14px; }
.rec-btn-record svg { color: #fff; }
.recorder[data-state="recording"] .rec-btn-stop, .recorder[data-state="paused"] .rec-btn-stop { background: var(--danger); }
.recorder.unsupported .rec-wave, .recorder.unsupported .rec-name-row, .recorder.unsupported .rec-controls, .recorder.unsupported .rec-timer { display: none; }
@media (max-width: 640px) {
  .recorder { padding: 14px; }
  .rec-controls .btn { flex: 1; justify-content: center; }
  .rec-controls .rec-btn-discard { flex: 0 0 auto; }
}

/* ── Steps list (shortcut instructions) ────────────────────── */
.steps { padding-left: 1.4em; display: flex; flex-direction: column; gap: 12px; font-size: .93rem; }
.steps li::marker { font-weight: 600; color: var(--primary); }
.steps ul { margin-top: 6px; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .88rem; }
.steps ul li::marker { color: var(--muted); font-weight: 400; }

/* ── Book ──────────────────────────────────────────────────── */
.book-current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.book-current .row-icon { background: var(--primary-bg); color: var(--primary); }

/* ── Book: details, cover, marketing ───────────────────────── */
.details-title { font-size: 1.5rem; margin-bottom: 4px; }
.details-h { font-family: var(--font); font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.details-text { font-family: var(--serif); font-size: 1.02rem; line-height: 1.7; }
.details-links { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.details-links a { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: .85rem; background: var(--surface2); }
.details-links a:hover { border-color: var(--primary); text-decoration: none; }
.cover-grid { display: grid; grid-template-columns: 3fr 0.8fr 3fr; gap: 14px; grid-template-areas: "front spine back" "spread spread spread"; }
.cover-front { grid-area: front; } .cover-spine { grid-area: spine; } .cover-back { grid-area: back; } .cover-spread { grid-area: spread; }
.cover-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); min-width: 0; }
.cover-frame { background: var(--surface2); border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; aspect-ratio: 2 / 3; }
.cover-spine .cover-frame { aspect-ratio: 1 / 6; }
.cover-spread .cover-frame { aspect-ratio: 4.2 / 3; max-height: 520px; }
.cover-frame a { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; }
.cover-frame img { width: 100%; height: 100%; object-fit: contain; }
.cover-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; text-align: center; padding: 10px; }
.cover-empty svg { width: 28px; height: 28px; opacity: .6; }
.cover-spine .cover-empty span { writing-mode: vertical-rl; }
.cover-foot { display: flex; flex-direction: column; gap: 6px; }
.cover-label { font-weight: 600; font-size: .9rem; }
.cover-foot .btn-group { flex-wrap: wrap; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.media-thumb { display: flex; align-items: center; justify-content: center; background: var(--surface2); aspect-ratio: 4 / 3; overflow: hidden; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-ext { font-family: var(--mono); font-weight: 600; color: var(--muted); font-size: 1.1rem; }
.media-body { padding: 10px 12px 12px; }
.media-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) {
  .cover-grid { grid-template-columns: 1fr 1fr; grid-template-areas: "front back" "spine spine" "spread spread"; }
  .cover-spine .cover-frame { aspect-ratio: 6 / 1; }
  .cover-spine .cover-empty span { writing-mode: horizontal-tb; }
}

/* ── Audiobook ─────────────────────────────────────────────── */
.chapters { display: flex; flex-direction: column; gap: 14px; }
.chapter .card-header { gap: 10px; }
.chapter-num { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-bg); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem; font-family: var(--serif); }
.chapter-title { font-size: 1.05rem; }
.chapter-body audio { width: 100%; height: 40px; }
.chapter-uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.dropzone-sm { padding: 16px 14px; }
.dropzone-sm .dropzone-title { font-size: .9rem; }
.form-input-sm { padding: 7px 11px; font-size: .85rem; }
.row-tight { padding: 8px 12px; gap: 10px; }
.row-tight .row-icon { width: 30px; height: 30px; border-radius: 8px; }
.row-tight .row-icon svg { width: 15px; height: 15px; }
.older-versions { margin-top: 14px; }
.older-versions summary { cursor: pointer; font-size: .85rem; color: var(--muted); }
@media (max-width: 700px) { .chapter-uploads { grid-template-columns: 1fr; } .chapter-uploads [style*="margin-top:46px"] { margin-top: 0 !important; } }
