/* ============================================================================
   SBI LEDGER — theme.css
   ONE token file. Light default (paper/ink + Bushido gold), optional dark.
   No hardcoded hexes in components; everything reads these custom properties.
   ============================================================================ */
:root {
  --bg: #f7f7f5;
  --bg-elev: #ffffff;
  --bg-sunken: #efefec;
  --ink: #14161a;
  --ink-2: #3f4650;
  --muted: #6b7280;
  --line: rgba(20, 22, 26, 0.10);
  --line-strong: rgba(20, 22, 26, 0.18);
  --gold: #a97f1f;
  --gold-ink: #6f5310;
  --gold-soft: rgba(169, 127, 31, 0.12);
  --live: #0e7c4a;
  --live-soft: rgba(14, 124, 74, 0.10);
  --warn: #a16207;
  --warn-soft: rgba(161, 98, 7, 0.12);
  --breach: #b3261e;
  --breach-soft: rgba(179, 38, 30, 0.10);
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --transition: 180ms cubic-bezier(.16,1,.3,1);
}
html.dark {
  --bg: #0a0a0c;
  --bg-elev: #121319;
  --bg-sunken: #070709;
  --ink: #f3f4f6;
  --ink-2: #c6ccd8;
  --muted: #8b93a1;
  --line: rgba(255,255,255,.09);
  --line-strong: rgba(255,255,255,.16);
  --gold: #e8c15a;
  --gold-ink: #f5d378;
  --gold-soft: rgba(232,193,90,.13);
  --live: #34d399;
  --live-soft: rgba(52,211,153,.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251,191,36,.12);
  --breach: #f87171;
  --breach-soft: rgba(248,113,113,.12);
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 12px 32px rgba(0,0,0,.55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold-ink); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }

/* --------------------------------------------------------------- shell --- */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 30px; height: 30px; }
.brand b { font-size: 15px; letter-spacing: .12em; }
.brand small { display: block; color: var(--muted); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 7px 11px; border-radius: var(--radius); color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.nav a:hover { background: var(--bg-sunken); }
.nav a.on { background: var(--gold-soft); color: var(--gold-ink); box-shadow: inset 0 -2px 0 var(--gold); }
.topRight { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.presence { display: inline-flex; align-items: center; gap: 6px; font: 11px var(--mono); color: var(--live); border: 1px solid color-mix(in srgb, var(--live) 35%, transparent); background: var(--live-soft); padding: 4px 9px; border-radius: var(--radius); }
.presence i { width: 6px; height: 6px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); }
.main { max-width: 1280px; margin: 0 auto; padding: 22px 18px 60px; }
.pageHead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.pageHead h1 { margin-right: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- controls --- */
.btn, button {
  font: 600 12.5px var(--font); color: var(--ink-2); background: var(--bg-elev);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 12px;
  min-height: 34px; cursor: pointer; transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.btn:hover, button:hover { border-color: var(--gold); color: var(--ink); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
html.dark .btn.primary { color: #14161a; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--breach); border-color: color-mix(in srgb, var(--breach) 45%, transparent); }
input, select, textarea {
  font: 13px var(--font); color: var(--ink); background: var(--bg-elev);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px; min-height: 34px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft);
}
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: .06em;
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 3px 8px; color: var(--ink-2); background: var(--bg-sunken); }
.chip.st-active { color: var(--live); border-color: color-mix(in srgb, var(--live) 40%, transparent); background: var(--live-soft); }
.chip.st-at_risk { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }
.chip.st-suspended, .chip.st-swept { color: var(--breach); border-color: color-mix(in srgb, var(--breach) 40%, transparent); background: var(--breach-soft); }
.chip.st-on_leave, .chip.st-removed { color: var(--muted); }

/* --------------------------------------------------------------- surfaces --- */
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card .cardBody { padding: 14px 16px; }
.card h3 { margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .grid.cols-4 { grid-template-columns: 1fr; } }

.metric { padding: 14px 16px; }
.metric .k { font: 600 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.metric .v { font: 700 26px var(--mono); margin-top: 4px; }
.metric .d { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* --------------------------------------------------------------- table --- */
.tableWrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { font: 600 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); background: var(--bg-sunken); position: sticky; top: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--gold) 4%, transparent); }
td.num { font-family: var(--mono); text-align: right; }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line-strong); background: var(--bg-sunken); }
.avatar.ph { display: inline-flex; align-items: center; justify-content: center; font: 700 14px var(--font); color: var(--gold-ink); }
.person { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.person b { font-size: 13px; }
.person small { display: block; color: var(--muted); font-size: 11px; }

/* --------------------------------------------------------------- contact card --- */
.cardOverlay { position: fixed; inset: 0; z-index: 90; background: rgba(8,9,12,.45); display: flex; align-items: center; justify-content: center; padding: 18px; }
.cardFrame { width: min(420px, 100%); height: min(520px, 82vh); border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow); background: transparent; }
@media (max-width: 560px) {
  .cardOverlay { align-items: flex-end; padding: 0; }
  .cardFrame { width: 100%; height: 70vh; border-radius: 16px 16px 0 0; }
}
body.cardBody { background: transparent; }
.contactCard { background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); padding: 16px; color: var(--ink); }
.ccTop { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.ccPhoto { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line-strong); }
.ccPhoto.ph { display: flex; align-items: center; justify-content: center; font: 700 24px var(--font); color: var(--gold-ink); background: var(--bg-sunken); }
.ccHandle { font-size: 18px; font-weight: 800; }
.ccRow { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.ccActions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ccActions .btn { min-height: 40px; }

/* --------------------------------------------------------------- misc --- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(8,9,12,.45); display: flex; align-items: center; justify-content: center; padding: 18px; }
.modalCard { width: min(560px, 100%); max-height: 88vh; overflow: auto; background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 18px; }
.modalCard h2 { margin-bottom: 12px; }
.formGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .formGrid { grid-template-columns: 1fr; } }
.formGrid .full { grid-column: 1 / -1; }
.modalActions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 120; background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: var(--radius); font-size: 12.5px; box-shadow: var(--shadow); }
.toast.err { background: var(--breach); color: #fff; }
.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }
.pillRow { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.tabs button { border: 0; border-radius: 0; background: var(--bg-elev); }
.tabs button.on { background: var(--gold-soft); color: var(--gold-ink); box-shadow: inset 0 -2px 0 var(--gold); }
.split { display: grid; grid-template-columns: 1.3fr .7fr; gap: 14px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.statbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.check input { min-height: 0; }
.btnRow { display: flex; gap: 8px; flex-wrap: wrap; }
.weekNav { display: inline-flex; align-items: center; gap: 6px; }
.cellInput { width: 88px; text-align: right; font-family: var(--mono); }
.reportTable { max-height: 420px; overflow: auto; }

/* auth */
body.auth { display: grid; place-items: center; background: var(--bg-sunken); }
.authWrap { width: 100%; padding: 20px; display: flex; justify-content: center; }
.authCard { width: min(380px, 100%); background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow); text-align: center; }
.authLogo { width: 84px; height: 84px; margin-bottom: 10px; }
.authCard h1 { letter-spacing: .16em; font-size: 18px; }
.authCard form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; text-align: left; }
.authCard label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.authCard .btn { margin-top: 6px; min-height: 40px; }
.err { color: var(--breach); font-size: 12px; min-height: 16px; }
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; animation-duration: .01ms !important; } }

/* --------------------------------------------------------- mobile shell ---
   Keep the topbar to two compact rows: brand+utilities, then a horizontally
   scrollable nav. No tall wrapped columns; primary controls stay reachable. */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .brand img { width: 26px; height: 26px; }
  .brand b { font-size: 13px; letter-spacing: .10em; }
  .brand small { font-size: 9px; letter-spacing: .10em; }
  .nav {
    order: 3; width: 100%; display: flex; flex-wrap: nowrap; gap: 2px;
    overflow-x: auto; overflow-y: hidden; padding-bottom: 2px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 8px 10px; white-space: nowrap; font-size: 12px; flex: 0 0 auto; }
  .topRight { margin-left: auto; gap: 6px; }
  #who { display: none; }
  .presence { font-size: 10px; padding: 3px 7px; }
  .main { padding: 14px 12px 44px; }
  .pageHead h1 { width: 100%; font-size: 18px; }
  .pageHead { gap: 8px; }
  .toolbar { width: 100%; }
  .toolbar input, .toolbar select { flex: 1 1 130px; min-width: 0; }
  .toolbar .btn { flex: 0 0 auto; min-height: 38px; }
  .split { gap: 10px; }
  .modalActions .btn { flex: 1 1 auto; }
  .ccActions .btn { flex: 1 1 40%; text-align: center; justify-content: center; }
}


/* ------------------------------------------------- 2026-11-08 additions ---
   Login theme switch, bulk selection/amount bars, Instagram chips, in-place
   session re-auth. Tokens only, so light/dark both stay correct. */
.authTheme {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 14px;
  z-index: 5; min-height: 38px; min-width: 38px; font-size: 15px; line-height: 1;
}
.filterBar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin: 0 0 10px; padding: 8px 10px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.filterBar input, .filterBar select { min-height: 32px; }
.filterBar input { flex: 1 1 200px; min-width: 0; }
.bulkBar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin: 0 0 10px; padding: 8px 10px; background: var(--gold-soft);
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  border-radius: var(--radius-lg);
}
.bulkBar #dCount, .bulkBar #bulkCount { font: 700 13px var(--mono); color: var(--gold-ink); }
.bulkBar input[type="number"] { width: 96px; min-height: 32px; }
.amountBtn.on { background: var(--gold); border-color: var(--gold); color: #fff; }
html.dark .amountBtn.on { color: #14161a; }
.amountPick { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.amountPick input { width: 110px; }
.selCol { width: 34px; text-align: center; }
.selCol input { min-height: 0; width: 16px; height: 16px; }
tr[hidden] { display: none !important; }
.igWrap { display: inline-flex; gap: 4px; margin-left: 6px; }
.igBtn {
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 9.5px var(--mono); letter-spacing: .06em; line-height: 1;
  padding: 4px 6px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  color: var(--ink-2); background: var(--bg-sunken);
}
.igBtn:hover { border-color: var(--gold); color: var(--gold-ink); }
.btn.tiny { padding: 2px 7px; min-height: 26px; font-size: 11px; }
.reauthHost { z-index: 300; }
.cardBody .ccActions .btn.ig { border-color: color-mix(in srgb, var(--gold) 45%, transparent); }

/* hidden attribute must win over author display rules (bulk bars, rows) */
[hidden] { display: none !important; }
.check { white-space: nowrap; }
.igMore { font: 700 9.5px var(--mono); color: var(--muted); align-self: center; }

/* ------------------------------------- contact-card photo + photo viewer ---
   The card photo is a button that asks the parent for a full-screen viewer;
   the viewer supports wheel, pinch, drag and double-tap zoom. */
.ccPhotoBtn {
  position: relative; padding: 0; border: 0; background: none; border-radius: 50%;
  line-height: 0; cursor: zoom-in; flex: 0 0 auto; min-height: 0;
}
.ccPhotoBtn:hover .ccPhoto { border-color: var(--gold); }
.ccPhotoBtn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ccZoom {
  position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--bg-elev); border: 1px solid var(--line-strong);
  color: var(--ink-2); font: 700 10px/18px var(--font); text-align: center;
}
.photoViewer {
  position: fixed; inset: 0; z-index: 400; display: flex; flex-direction: column;
  background: rgba(3, 4, 6, 0.985);
}
.pvStage {
  flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden;
  touch-action: none; cursor: grab; padding: 12px;
}
.pvStage:active { cursor: grabbing; }
.pvImg {
  max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center center;
  user-select: none; -webkit-user-drag: none; will-change: transform;
}
.pvBar {
  display: flex; gap: 8px; align-items: center; justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  border-top: 1px solid var(--line);
}
.pvScale { font: 600 12px var(--mono); color: var(--muted); min-width: 48px; text-align: center; }
body.pvLock { overflow: hidden; }
@media (max-width: 560px) { .pvBar .btn { min-height: 42px; } }

/* ------------------------------------------------- iOS / PWA standalone ---
   Installed from Safari ("Add to Home Screen"): standalone window, no Safari
   chrome, notch/status-bar safe areas respected so the top bar never clips. */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: contain; -webkit-tap-highlight-color: transparent; }
.topbar { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
.main { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
body.auth {
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
body.cardBody {
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
@media (max-width: 760px) {
  .topbar { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
}
@media (display-mode: standalone) {
  body { min-height: 100dvh; }
  /* Opaque header while installed: no page content bleeding behind the notch. */
  .topbar { background: var(--bg-elev); }
}
