/* =====================================================================
   Reliquary Backroom — single stylesheet.

   THEMING: three states, deliberately.
     1. :root                    -> the complete light palette
     2. prefers-color-scheme:dark, guarded :root:not([data-theme="light"])
                                 -> system dark, unless the user forced light
     3. :root[data-theme="dark"] -> an explicit toggle wins in both directions

   No colour is ever defined ONLY inside a media query or [data-theme] block.
   ===================================================================== */

:root {
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f0f2f5;
  --border:        #dfe3e8;
  --border-strong: #c6ccd4;
  --text:          #1a1d21;
  --text-muted:    #616b76;
  --text-faint:    #8b95a1;
  --accent:        #2f6f4f;
  --accent-hover:  #275c42;
  --accent-soft:   #e4f0ea;
  --accent-text:   #ffffff;
  --danger:        #b3261e;
  --danger-soft:   #fbe9e7;
  --warning:       #8a6100;
  --warning-soft:  #fdf3dd;
  --success:       #1e6b43;
  --success-soft:  #e3f3ea;
  --info-soft:     #e6eefb;
  --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg:     0 10px 30px rgba(16, 24, 40, .16);

  --radius:    10px;
  --radius-sm: 6px;
  --maxw:      1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #14161a;
    --surface:       #1c1f24;
    --surface-2:     #23272e;
    --border:        #2e343c;
    --border-strong: #3d444e;
    --text:          #e6e9ed;
    --text-muted:    #a0a8b4;
    --text-faint:    #79828f;
    --accent:        #5fbf8c;
    --accent-hover:  #74cf9d;
    --accent-soft:   #1d3329;
    --accent-text:   #0f1a14;
    --danger:        #f2837a;
    --danger-soft:   #3a1f1d;
    --warning:       #e0b357;
    --warning-soft:  #352a14;
    --success:       #63c48d;
    --success-soft:  #1a3326;
    --info-soft:     #1c2738;
    --shadow:        0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg:     0 10px 30px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg:            #14161a;
  --surface:       #1c1f24;
  --surface-2:     #23272e;
  --border:        #2e343c;
  --border-strong: #3d444e;
  --text:          #e6e9ed;
  --text-muted:    #a0a8b4;
  --text-faint:    #79828f;
  --accent:        #5fbf8c;
  --accent-hover:  #74cf9d;
  --accent-soft:   #1d3329;
  --accent-text:   #0f1a14;
  --danger:        #f2837a;
  --danger-soft:   #3a1f1d;
  --warning:       #e0b357;
  --warning-soft:  #352a14;
  --success:       #63c48d;
  --success-soft:  #1a3326;
  --info-soft:     #1c2738;
  --shadow:        0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg:     0 10px 30px rgba(0, 0, 0, .55);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* Explicit token background: a transparent body borrows the host's theme. */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

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

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 640; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- Header / nav ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.site-header__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 14px; min-height: 56px;
}
.brand {
  font-weight: 700; font-size: 1.02rem; color: var(--text);
  letter-spacing: -.01em; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand__dot { color: var(--accent); }

.site-nav { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; }
.nav-link {
  color: var(--text-muted); padding: 8px 11px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 520; white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent); }

.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* Pure-CSS mobile nav toggle. Visually hidden but still focusable — a
   display:none checkbox drops out of the tab order entirely. */
.nav-toggle {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; opacity: 0; pointer-events: none;
}
.nav-toggle-label { display: none; }

/* ---------- Layout blocks ---------- */

main { padding: 22px 0 64px; }

.page-head {
  display: flex; align-items: flex-start; gap: 12px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.page-head__text { flex: 1; min-width: 0; }
.page-head p { margin: 2px 0 0; color: var(--text-muted); font-size: .92rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card__title {
  margin: 0 0 14px; font-size: 1rem; font-weight: 640;
  display: flex; align-items: center; gap: 8px;
}

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 15px 16px; }
.stat__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
               color: var(--text-faint); font-weight: 600; }
.stat__value { font-size: 1.65rem; font-weight: 680; margin-top: 4px;
               letter-spacing: -.02em; }
.stat__hint  { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }

/* ---------- Forms ---------- */

.form-row { margin-bottom: 15px; }
.form-row--split { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row--split > * { flex: 1; min-width: 180px; }

label.field-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .86rem; font-weight: 600; color: var(--text);
  margin-bottom: 5px;
}
.field-hint { font-size: .82rem; color: var(--text-muted); margin-top: 4px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=search], input[type=url],
select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: .93rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; min-height: 40px;
  font: inherit; font-size: .9rem; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; background: var(--accent); color: var(--accent-text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn--secondary:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger); filter: brightness(.92); }
.btn--sm { padding: 5px 10px; min-height: 32px; font-size: .84rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.form-actions {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ---------- Tables ---------- */

/* Wide data tables don't reflow well at any breakpoint — scroll them
   inside their own container instead of breaking the page layout. */
.table-responsive { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td {
  text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); font-weight: 650; white-space: nowrap;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .88em; }

/* ---------- Badges, flashes, empty states ---------- */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .76rem; font-weight: 620; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge--accent  { background: var(--accent-soft);  color: var(--accent);  border-color: transparent; }
.badge--success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge--warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge--danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }

.flash {
  padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px;
  font-size: .92rem; border: 1px solid transparent;
}
.flash--info    { background: var(--info-soft);    color: var(--text); }
.flash--success { background: var(--success-soft); color: var(--success); }
.flash--error   { background: var(--danger-soft);  color: var(--danger); }
.flash--warning { background: var(--warning-soft); color: var(--warning); }

.empty {
  text-align: center; padding: 44px 20px; color: var(--text-muted);
}
.empty h3 { color: var(--text); }

/* ---------- Help bubble + drawer ---------- */

.help-bubble {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; flex: 0 0 17px;
  border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text-muted);
  font-size: 11px; font-weight: 700; font-style: italic;
  font-family: Georgia, serif; line-height: 1; cursor: pointer;
  text-decoration: none; user-select: none;
}
.help-bubble:hover {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent); text-decoration: none;
}
.help-bubble:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.help-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .42);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity .16s;
}
.help-backdrop.is-open { opacity: 1; pointer-events: auto; }

.help-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(430px, 100%);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 91;
  transform: translateX(100%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.help-drawer.is-open { transform: translateX(0); }
.help-drawer__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.help-drawer__title { font-weight: 660; font-size: .98rem; flex: 1; }
.help-drawer__close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 22px; line-height: 1; padding: 4px 8px; border-radius: var(--radius-sm);
}
.help-drawer__close:hover { background: var(--surface-2); color: var(--text); }
.help-drawer__body { padding: 16px; overflow-y: auto; flex: 1 1 auto; font-size: .92rem; }
.help-drawer__body h3 { margin-top: 18px; font-size: .95rem; }
.help-drawer__body h3:first-child { margin-top: 0; }
.help-drawer__body ul, .help-drawer__body ol { padding-left: 19px; margin: 8px 0; }
.help-drawer__body li { margin-bottom: 5px; }
.help-drawer__body table { width: 100%; border-collapse: collapse; margin: 10px 0;
                           font-size: .87rem; }
.help-drawer__body th, .help-drawer__body td {
  border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top;
}
.help-drawer__body th { background: var(--surface-2); font-weight: 620; }
.help-drawer__body code {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
}
.help-note {
  background: var(--info-soft); border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: var(--radius-sm); margin: 12px 0;
}
.help-warn {
  background: var(--warning-soft); border-left: 3px solid var(--warning);
  padding: 10px 12px; border-radius: var(--radius-sm); margin: 12px 0;
}

/* The full /help manual page */
.help-index__section { margin-bottom: 26px; }
.help-index__section h2 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); border-bottom: 1px solid var(--border);
  padding-bottom: 6px; margin-bottom: 10px;
}
.help-index__links { display: grid; gap: 4px; }

/* ---------- Auth ---------- */

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; background: var(--bg);
}
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand__name { font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; }
.auth-brand__sub  { color: var(--text-muted); font-size: .88rem; margin-top: 2px; }

/* ---------- Theme picker ---------- */

.theme-picker { display: inline-flex; border: 1px solid var(--border-strong);
                border-radius: var(--radius-sm); overflow: hidden; }
.theme-picker button {
  background: var(--surface); color: var(--text-muted); border: none;
  padding: 6px 10px; font: inherit; font-size: .8rem; cursor: pointer;
  min-height: 32px;
}
.theme-picker button + button { border-left: 1px solid var(--border); }
.theme-picker button:hover { background: var(--surface-2); color: var(--text); }
.theme-picker button.is-active { background: var(--accent-soft); color: var(--accent);
                                 font-weight: 620; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border); margin-top: 40px; padding: 18px 0;
  color: var(--text-faint); font-size: .84rem;
}
.site-footer__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0 16px;
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}

/* ---------- Utilities ---------- */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 16px; } .mb-2 { margin-bottom: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  body { font-size: 15px; }
  .site-header__inner { flex-wrap: wrap; min-height: 52px; padding: 8px 16px; }
  .header-spacer { display: none; }

  /* 44x44 real tap target — not a thin decorative bar. */
  .nav-toggle-label {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-left: auto; cursor: pointer;
    border-radius: var(--radius-sm); color: var(--text);
  }
  .nav-toggle-label::before {
    content: ""; display: block; width: 19px; height: 2px;
    background: currentColor; border-radius: 2px;
    /* the other two bars, no extra markup needed */
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
  }
  .nav-toggle:focus-visible + .nav-toggle-label { outline: 2px solid var(--accent); }
  .nav-toggle-label:hover { background: var(--surface-2); }

  .site-nav {
    display: none; width: 100%; flex-direction: column;
    gap: 2px; padding: 8px 0 4px; align-items: stretch;
  }
  .nav-toggle:checked ~ .site-nav { display: flex; }
  /* Touch has no hover state to reveal a background, so show it at rest. */
  .site-nav .nav-link {
    background: var(--surface-2); min-height: 44px;
    display: flex; align-items: center; font-size: .95rem;
  }
  .header-actions { width: 100%; padding-bottom: 6px; }
  .nav-toggle:not(:checked) ~ .header-actions { display: none; }

  .grid--stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .card { padding: 15px; }
  .table-responsive { margin: 0 -15px; padding: 0 15px; }
  .form-row--split { gap: 0; }
  .form-row--split > * { min-width: 100%; margin-bottom: 15px; }
  .btn { min-height: 44px; }
  .form-actions .btn { flex: 1; }

  /* Full-height sheet rather than a side panel */
  .help-drawer { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
