/* bible admin — a thin layer on top of Bootstrap; the reader's tokens and themes (light / sepia / dark) */

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f5f5f8; --surface: #ffffff; --surface-2: #f4f4f7; --surface-3: #eaeaf0;
  --text: #16161a; --muted: #63636f; --border: #e6e6ec; --border-strong: #d5d5de;
  --accent: #7c3aed; --accent-hover: #6d28d9; --accent-soft: #ede9fe; --accent-text: #6d28d9; --accent-ring: rgba(124,58,237,.22);
  --ok: #166534; --ok-soft: #dcfce7; --warn: #92400e; --warn-soft: #fef3c7; --danger: #b91c1c; --danger-soft: #fee2e2;
  --r-sm: 9px; --r: 12px; --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16,16,32,.06);
  --shadow: 0 1px 2px rgba(16,16,32,.04), 0 10px 26px -14px rgba(16,16,32,.18);
  --shadow-lg: 0 16px 48px -16px rgba(16,16,32,.28);
  --head-h: 102px;   /* the sticky header: brand row + tab row; sticky panes and scrollIntoView clear it */
}
html[data-theme="sepia"] {
  --bg: #f4ecd8; --surface: #fdf6e3; --surface-2: #f1e7cf; --surface-3: #e8dcc0;
  --text: #5b4636; --muted: #8b7d6b; --border: #e5d8b8; --border-strong: #d8c9a3;
  --accent: #8b5a2b; --accent-hover: #74491f; --accent-soft: #efe0c4; --accent-text: #74491f; --accent-ring: rgba(139,90,43,.22);
  --shadow-sm: 0 1px 2px rgba(91,70,54,.08);
  --shadow: 0 1px 2px rgba(91,70,54,.06), 0 10px 26px -14px rgba(91,70,54,.22);
  --shadow-lg: 0 16px 48px -16px rgba(91,70,54,.3);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f12; --surface: #1a1a1f; --surface-2: #24242b; --surface-3: #2f2f38;
  --text: #f2f2f4; --muted: #a0a0ab; --border: #2c2c35; --border-strong: #3a3a46;
  --accent: #8b5cf6; --accent-hover: #7c3aed; --accent-soft: #2b1f4d; --accent-text: #c4b5fd; --accent-ring: rgba(139,92,246,.3);
  --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --warn-soft: #3a2a0d; --danger: #f87171; --danger-soft: #3d1414;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 26px -14px rgba(0,0,0,.7);
  --shadow-lg: 0 16px 48px -16px rgba(0,0,0,.8);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  background-image: radial-gradient(900px 420px at 100% -10%, var(--accent-soft), transparent 65%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent-text); }
a:hover { color: var(--accent-hover); }
.sp { flex: 1; }
.ok { color: var(--ok); } .bad { color: var(--danger); }
.hint { color: var(--muted); font-size: .9rem; line-height: 1.6; margin: 12px 0 0; }
.linkbtn { border: none; background: none; color: var(--accent-text); padding: 0; font: inherit; cursor: pointer; }
.linkbtn:hover { color: var(--accent-hover); }

/* ---------- Bootstrap pieces follow the tokens ---------- */
/* background-color, never the `background` shorthand: .form-select carries its arrow as a background-image */
.card, .panel, .table, .pin-box { background-color: var(--surface); color: var(--text); border-color: var(--border); }
.form-control, .form-select {
  background-color: var(--surface); color: var(--text); border-color: var(--border-strong); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus { background-color: var(--surface); color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.form-control::placeholder { color: var(--muted); opacity: .65; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.form-check-input { border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
/* the checkboxes sit inside their label rather than in a .form-check wrapper */
.form-check-label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.form-check-label > .form-check-input { flex: none; margin: 0; }
.form-text, .text-muted { color: var(--muted) !important; }
.form-text.ok { color: var(--ok) !important; } .form-text.bad { color: var(--danger) !important; }
.alert-danger { background-color: var(--danger-soft); color: var(--danger); border-color: transparent; border-radius: var(--r); font-size: .92rem; }

.btn { font-weight: 600; border-radius: var(--r-sm); transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .08s; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn-primary { background-color: var(--accent); border-color: var(--accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active { background-color: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-primary { background-color: var(--surface); color: var(--accent-text); border-color: var(--border-strong); }
.btn-outline-primary:hover, .btn-outline-primary:focus, .btn-outline-primary:active { background-color: var(--accent); border-color: var(--accent); color: #fff; }
.btn-light { background-color: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-light:hover, .btn-light:focus { background-color: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
/* the wells and the filter strip are themselves surface-2, so a light button needs to step back up */
.form-well .btn-light, .meta-row .btn-light, .filters .btn-light { background-color: var(--surface); }
.form-well .btn-light:hover, .meta-row .btn-light:hover, .filters .btn-light:hover { background-color: var(--surface-2); border-color: var(--border-strong); }
.btn-outline-danger { background-color: var(--surface); color: var(--danger); border-color: var(--border-strong); }
.btn-outline-danger:hover, .btn-outline-danger:focus { background-color: var(--danger); border-color: var(--danger); color: #fff; }

/* ---------- login ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.pin-box { width: 100%; max-width: 440px; padding: 32px 30px; border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); }
.auth-mark { width: 48px; height: 48px; border-radius: 12px; margin-bottom: 14px; }
.pin-box h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 6px; }
.pin-box .sub { color: var(--muted); font-size: .95rem; margin: 0 0 20px; }
.pin-box label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.pin-box .form-check { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.pin-box .form-check-label { display: inline; margin: 0; font-weight: 500; color: var(--muted); cursor: pointer; }
.pin-box .btn-primary { padding: 10px; font-size: 1rem; }
.pin-box .hint { font-size: .85rem; }
.modes { display: flex; gap: 4px; margin-bottom: 20px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.modes .mode { flex: 1; border: none; background: transparent; color: var(--muted); border-radius: 999px; padding: 9px 12px; font: inherit; font-weight: 600; cursor: pointer; transition: background-color .15s, color .15s; }
.modes .mode:hover { color: var(--text); }
.modes .mode.on { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.pin-input { font-size: 1.5rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; padding: 12px; }

/* ---------- admin shell: one sticky header holding the brand row and the tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar .inner { max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; }
.topbar .brand img { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-store { font-size: .98rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name { font-size: .72rem; font-weight: 600; color: var(--muted); letter-spacing: .03em; }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.topbar .who .pill { background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; padding: 3px 10px; margin-right: 6px; font-size: .75rem; font-weight: 700; }
#whoLine { display: inline-flex; align-items: center; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* the header's own buttons: theme, language, reader, sign out */
.tb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.tb-btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.tb-btn.icon { width: 34px; padding: 0; }
.tb-btn.danger:hover { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.theme-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--r-sm); width: 34px; height: 34px; font: inherit; cursor: pointer; }

.tabs { max-width: 1200px; margin: 0 auto; padding: 0 20px; display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; border: none; background: none; color: var(--muted);
  padding: 10px 2px 11px; font: inherit; font-size: .95rem; font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: color .15s;
}
.tabs button::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px 2px 0 0; background: transparent; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--accent-text); }
.tabs button.on::after { background: var(--accent); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 20px 80px; }

/* ---------- panels ---------- */
.panel { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-head h2, .panel h2 { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.panel-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
/* the filter strip above a table or the chapter grid */
.filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); }
.filters .form-select { min-width: 190px; }
.chip-info { display: inline-block; padding: 4px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: .8rem; font-weight: 600; }
/* a form that opens in place reads as an editing surface, not as more page */
.form-well, .meta-row { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; margin-bottom: 16px; animation: wellIn .18s ease; }
.form-well { border-left: 3px solid var(--accent); }
.form-well.row, .meta-row.row { margin-left: 0; margin-right: 0; }
@keyframes wellIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.toolbar > b { font-size: .8rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.toolbar label.small { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-weight: 600; cursor: pointer; }
.filters .form-check-label { color: var(--muted); font-weight: 600; }

/* ---------- tables ---------- */
.table { margin-bottom: 0; }
.table > :not(caption) > * > * { background-color: transparent; color: inherit; border-color: var(--border); }
.table thead th { padding: 8px .5rem 10px; font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.table td, .table th { vertical-align: middle; }
.table tbody td { padding-top: 10px; padding-bottom: 10px; }
.table tbody tr:hover td { background-color: var(--surface-2); }
.table tbody tr:last-child td { border-bottom-color: transparent; }
/* narrow screens scroll the table sideways rather than squeezing the date into three lines */
.table-responsive .table { min-width: 660px; }
.table-responsive #schedTable { min-width: 920px; }
.table-responsive #catTable { min-width: 780px; }
#schedTable tbody td:first-child { white-space: nowrap; }
.table .refs { display: inline-block; padding: 2px 8px; border-radius: 7px; background: var(--surface-2); font-family: ui-monospace, Menlo, monospace; font-size: .85rem; white-space: nowrap; }
.table .refs.bad { background: var(--danger-soft); color: var(--danger); cursor: help; outline: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); }
.table .plain { color: var(--muted); }
.table tr.past td { color: var(--muted); }
.table tr.past .refs { opacity: .7; }
.table tr.today td, .table tr.today:hover td { background-color: var(--accent-soft); }
.table tr.today td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
code { padding: 2px 7px; border-radius: 7px; background: var(--surface-2); color: var(--accent-text); font-size: .85rem; }
.form-well code, .meta-row code, .filters code { background: var(--surface); }
.pin-cell { font-family: ui-monospace, Menlo, monospace; letter-spacing: .08em; }
/* row actions stay quiet until the row is under the cursor */
.table tbody .btn-light { opacity: .7; transition: opacity .15s, background-color .15s, border-color .15s, color .15s; }
.table tbody tr:hover .btn-light, .table tbody .btn-light:focus-visible { opacity: 1; }
.table [data-act="del"] { color: var(--muted); }
.table [data-act="del"]:hover { background-color: var(--danger-soft); border-color: transparent; color: var(--danger); }
.panel > .hint { padding: 12px 14px; background: var(--surface-2); border-radius: var(--r); }
/* it sits beside Save; checkRefs() rewrites its class, so the spacing has to live here */
#fRefsCheck { margin: 0; }
#schedEmpty { margin: 8px 0 0; padding: 28px 16px; border: 1px dashed var(--border-strong); border-radius: var(--r); text-align: center; }

.acwrap { position: relative; }
.acwrap .ac {
  display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto;
}
.acwrap.ac-open .ac, .acwrap .ac:not(.hidden) { display: block; }
.acwrap .ac.hidden { display: none; }
.acrow { display: flex; align-items: baseline; gap: 8px; padding: 8px 12px; cursor: pointer; font-size: .9rem; }
.acrow + .acrow { border-top: 1px solid var(--border); }
.acrow.on, .acrow:hover { background: var(--accent-soft); }
.acrow b { font-weight: 700; }
.acrow .alt { color: var(--muted); font-size: .85rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acrow .acn, .acinfo { color: var(--muted); font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.acinfo { margin: 0; padding: 8px 12px; }
.acinfo b { color: var(--text); font-weight: 600; }
/* the reference box, plus the two dropdowns the "pick a book" link folds out beside it */
.ref-row { display: flex; gap: 8px; align-items: center; }
.ref-row .acwrap { flex: 1; min-width: 0; }
.ref-row #fRefBook { flex: 0 1 11rem; }
.ref-row #fRefCh { flex: 0 0 5.5rem; }

.cat-chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-soft { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-draft { background: var(--warn-soft); color: var(--warn); }
.badge-pub { background: var(--ok-soft); color: var(--ok); }

/* ---------- notes: book → chapters → editor ---------- */
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 8px; }
.chapters button {
  position: relative; min-height: 46px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s, box-shadow .15s;
}
.chapters button:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.chapters button.has { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.chapters button.draft { border: 1px dashed var(--accent); }
.chapters button.cur { outline: 2px solid var(--accent); outline-offset: 2px; }
.chapters button .n { position: absolute; top: 3px; right: 5px; font-size: .62rem; font-weight: 700; color: var(--accent-text); }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.editor textarea { font-family: ui-monospace, Menlo, monospace; font-size: .875rem; line-height: 1.7; min-height: 420px; border-radius: var(--r); resize: vertical; }
.preview { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r); background: var(--surface-2); padding: 16px 18px; min-height: 420px; line-height: 1.75; }
.preview h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 10px; }
.preview h4 { font-size: 1rem; font-weight: 600; margin: 16px 0 4px; }
.preview h5 { font-size: .95rem; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
.preview p { margin: 6px 0; }
.preview ul, .preview ol { margin: 6px 0; padding-left: 1.5em; }
.preview li { margin: 4px 0; }
.preview .vref { border: none; background: transparent; padding: 0; font: inherit; color: var(--accent-text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; cursor: default; }
.preview .draft { display: inline-block; margin-left: 8px; padding: 2px 9px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: .75rem; font-weight: 600; vertical-align: middle; }
.editor-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.editor-delete-ask { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--warn, #b45309); font-size: .95rem; }
#nEditor { scroll-margin-top: calc(var(--head-h) + 16px); }
@media (min-width: 901px) {
  /* the preview follows the writer down a long note: pinned to the viewport, scrolling inside itself */
  .editor > div:last-child {
    position: sticky; top: calc(var(--head-h) + 16px); align-self: start;
    max-height: calc(100vh - var(--head-h) - 32px); display: flex; flex-direction: column;
  }
  .editor > div:last-child .preview { flex: 1; min-height: 0; overflow-y: auto; }
}
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .editor textarea, .preview { min-height: 280px; }
}

/* ---------- toast ---------- */
.toast-box {
  position: fixed; left: 50%; bottom: 28px; z-index: 60;
  transform: translate(-50%, 10px); background: #16161a; color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: .9rem; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast-box.show { opacity: 1; transform: translate(-50%, 0); }
html[data-theme="dark"] .toast-box { background: #f2f2f4; color: #16161a; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  :root { --head-h: 128px; }
  .topbar .inner { padding: 10px 14px; }
  .brand-name { display: none; }
  .topbar .who { width: 100%; margin-left: 0; }
  #whoLine { max-width: 100%; flex: 1; }
  .tabs { padding: 0 14px; gap: 18px; }
  .wrap { padding: 16px 14px 72px; }
  .panel { padding: 16px; border-radius: var(--r); }
  .panel-actions { margin-left: 0; width: 100%; }
  .filters .form-select { min-width: 0; flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
