/* SA Hub — a working ledger for the Shop Assistant team.
   One bold idea: the lists live in a sheet-tab strip at the bottom, like the
   Google Sheet the team already knows. Everything else stays quiet and dense. */
:root {
  --paper: #f4f6fa;
  --surface: #ffffff;
  --ink: #1b2232;
  --ink-2: #4a5468;
  --ink-3: #7a8499;
  --rule: #d9dfe9;
  --rule-2: #e8ecf3;
  --blaze: #e4570f;
  --blaze-ink: #ffffff;
  --blaze-soft: #fdeee5;
  --focus: #2f6fe0;
  --ok: #1f8f4e;      --ok-soft: #e3f4ea;
  --bad: #c93c3c;     --bad-soft: #fbe7e7;
  --info: #2f6fd0;    --info-soft: #e5eefb;
  --warn: #b7790a;    --warn-soft: #fbf1db;
  --muted-soft: #eef1f6;
  --row-hover: #f7f9fc;
  --sel: #fff4ec;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-s: 4px; --r-m: 7px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151a24; --surface: #1c2230; --ink: #e8ecf4; --ink-2: #b4bdcf; --ink-3: #8590a6;
    --rule: #2e3646; --rule-2: #252c3a; --blaze: #f26a26; --blaze-soft: #3a2418;
    --ok: #4cc283; --ok-soft: #173326; --bad: #ef7070; --bad-soft: #3a1f22; --info: #6ea2f2; --info-soft: #1b2a44;
    --warn: #e2b04c; --warn-soft: #3a2f17; --muted-soft: #252c3a; --row-hover: #212839; --sel: #33251c; --focus: #6ea2f2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151a24; --surface: #1c2230; --ink: #e8ecf4; --ink-2: #b4bdcf; --ink-3: #8590a6;
  --rule: #2e3646; --rule-2: #252c3a; --blaze: #f26a26; --blaze-soft: #3a2418;
  --ok: #4cc283; --ok-soft: #173326; --bad: #ef7070; --bad-soft: #3a1f22; --info: #6ea2f2; --info-soft: #1b2a44;
  --warn: #e2b04c; --warn-soft: #3a2f17; --muted-soft: #252c3a; --row-hover: #212839; --sel: #33251c; --focus: #6ea2f2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--focus); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: .01em; }
.muted { color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- app frame ---------- */
#app { height: 100%; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); }
.top { display: flex; align-items: center; gap: 18px; padding: 0 18px; height: 50px; background: var(--surface); border-bottom: 1px solid var(--rule); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; text-decoration: none; color: var(--ink); }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { padding: 6px 11px; border-radius: var(--r-s); color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--muted-soft); color: var(--ink); }
.nav a.on { color: var(--ink); background: var(--muted-soft); }
.who { display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.who b { color: var(--ink); font-weight: 600; }

main { overflow: auto; min-height: 0; }
.page { padding: 22px 26px 40px; max-width: 1180px; }
.page.wide { max-width: none; }
h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.02em; margin: 0; font-weight: 700; }
h2 { font-size: 17px; margin: 28px 0 10px; letter-spacing: -.01em; }
.lede { color: var(--ink-2); margin: 6px 0 0; max-width: 70ch; }

/* ---------- sheet tabs (the signature) ---------- */
.sheets { display: flex; align-items: stretch; gap: 0; background: var(--paper); border-top: 1px solid var(--rule); overflow-x: auto; padding: 0 10px; min-height: 44px; scrollbar-width: thin; }
.sheets .grp { display: flex; align-items: stretch; padding-right: 10px; margin-right: 10px; border-right: 1px solid var(--rule); }
.sheets .grp:last-child { border-right: 0; }
.sheets .gl { align-self: center; color: var(--ink-3); font-size: 12px; padding: 0 8px 0 4px; white-space: nowrap; }
.sheet { position: relative; display: flex; align-items: center; gap: 7px; padding: 0 13px; margin-top: -1px; color: var(--ink-2); text-decoration: none; white-space: nowrap; font-weight: 500; border: 1px solid transparent; border-top: 0; border-radius: 0 0 var(--r-m) var(--r-m); }
.sheet:hover { color: var(--ink); background: var(--muted-soft); }
.sheet.on { background: var(--surface); color: var(--ink); border-color: var(--rule); box-shadow: inset 0 3px 0 var(--blaze); }
.sheet .n { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--muted-soft); color: var(--ink-2); font-size: 11.5px; font-weight: 600; text-align: center; line-height: 18px; }
.sheet.on .n, .sheet .n.hot { background: var(--blaze-soft); color: var(--blaze); }

/* ---------- list header + toolbar ---------- */
.lhead { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.lhead .meta { color: var(--ink-2); padding-bottom: 3px; }
.lhead .meta b { color: var(--ink); }
.lhead .grow { flex: 1; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0 10px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-m); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--paper); }
.field, select.field, input.field { height: 32px; border: 1px solid var(--rule); border-radius: var(--r-m); background: var(--surface); padding: 0 9px; }
textarea.field { height: auto; padding: 8px 9px; resize: vertical; width: 100%; line-height: 1.45; }
input.search { width: 210px; }
.btn { height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: var(--r-m); border: 1px solid var(--rule); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--blaze); border-color: var(--blaze); color: var(--blaze-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.spacer { flex: 1; }

.bulk { display: flex; gap: 8px; align-items: center; padding: 7px 10px; margin-bottom: 8px; border-radius: var(--r-m); background: var(--sel); border: 1px solid var(--blaze-soft); }
.bulk b { margin-right: 6px; }

/* ---------- grid ---------- */
.gridwrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: start; }
.gridwrap > div { min-width: 0; }
.actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.btn[aria-pressed="true"] { background: var(--muted-soft); border-color: var(--ink-3); }
.counts { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--ink-2); padding-bottom: 3px; }
.counts b { color: var(--ink); font-variant-numeric: tabular-nums; }
.tablebox { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); overflow: auto; max-height: calc(100vh - 290px); min-height: 160px; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
.grid th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 600; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; font-size: 12.5px; }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { color: var(--ink); }
.grid th .dir { color: var(--blaze); margin-left: 3px; }
.grid td { padding: 0 10px; height: 34px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; max-width: 280px; white-space: nowrap; }
.grid tr:hover td { background: var(--row-hover); }
.grid tr.sel td { background: var(--sel); }
.grid td.chk, .grid th.chk { width: 34px; padding: 0 0 0 12px; }
.grid td.ed { cursor: text; }
.grid td.ed:hover { box-shadow: inset 0 0 0 1px var(--rule); }
.grid td .clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid td.editing { padding: 2px 4px; }
.grid td.editing input, .grid td.editing select { width: 100%; height: 28px; border: 1px solid var(--focus); border-radius: var(--r-s); padding: 0 6px; background: var(--surface); }
.ref { font-family: var(--mono); font-size: 12.5px; cursor: copy; border: 0; background: none; padding: 2px 0; color: var(--ink); }
.ref:hover { color: var(--blaze); }
.warnflag { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: 6px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 700; cursor: help; vertical-align: 1px; }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.pager { display: flex; align-items: center; gap: 10px; padding: 9px 2px; color: var(--ink-2); }

/* pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; line-height: 19px; white-space: nowrap; }
.s-todo { background: var(--muted-soft); color: var(--ink-2); }
.s-claimed { background: var(--blaze-soft); color: var(--blaze); }
.s-sent { background: var(--info-soft); color: var(--info); }
.s-skipped { background: transparent; color: var(--ink-3); box-shadow: inset 0 0 0 1px var(--rule); }
.r-engaged { background: var(--ok-soft); color: var(--ok); }
.r-declined { background: var(--bad-soft); color: var(--bad); }
.r-seen { background: var(--info-soft); color: var(--info); }
.r-none { background: var(--warn-soft); color: var(--warn); }

/* ---------- templates drawer ---------- */
.drawer { width: 330px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); padding: 14px 15px; max-height: calc(100vh - 290px); overflow: auto; position: sticky; top: 0; }
.drawer h3 { margin: 0 0 4px; font-size: 14px; }
.drawer .marks { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }
.tpl { border-top: 1px solid var(--rule-2); padding: 11px 0; }
.tpl:first-of-type { border-top: 0; }
.tpl .th { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.tpl .th span { flex: 1; }
.tpl p { margin: 0; white-space: pre-wrap; color: var(--ink-2); font-size: 13px; line-height: 1.5; }

/* ---------- forms, modals, toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 22, 33, .45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; width: 560px; max-width: 100%; box-shadow: 0 18px 50px rgba(10, 15, 25, .25); }
.modal.wide { width: 900px; }
.modal header { display: flex; align-items: center; padding: 15px 18px 0; }
.modal header h2 { margin: 0; flex: 1; font-size: 17px; }
.modal .body { padding: 12px 18px 4px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
label.f { display: block; margin: 12px 0 5px; font-weight: 600; font-size: 13px; }
.hint { color: var(--ink-3); font-size: 12.5px; margin: 5px 0 0; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.err { color: var(--bad); margin: 8px 0 0; min-height: 18px; }
.toasts { position: fixed; right: 18px; bottom: 58px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--paper); padding: 9px 14px; border-radius: var(--r-m); box-shadow: 0 8px 24px rgba(10, 15, 25, .25); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }
.secret { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.secret input { flex: 1; font-family: var(--mono); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login form { width: 340px; max-width: 100%; }
.login h1 { font-size: 30px; display: flex; align-items: center; gap: 10px; }
.login h1 svg { width: 30px; height: 30px; }
.login .btn { width: 100%; justify-content: center; margin-top: 16px; height: 38px; }
.login input.field { width: 100%; height: 38px; }

/* ---------- dashboard ---------- */
.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 16px 0 6px; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 18px 0 4px; font-size: 15px; color: var(--ink-2); }
.totals b { font-size: 24px; color: var(--ink); letter-spacing: -.02em; margin-right: 6px; font-variant-numeric: tabular-nums; }
table.plain { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); overflow: hidden; }
.plain th, .plain td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--rule-2); font-variant-numeric: tabular-nums; }
.plain th { color: var(--ink-2); font-weight: 600; font-size: 12.5px; background: var(--surface); }
.plain td.num, .plain th.num { text-align: right; }
.plain tr:last-child td { border-bottom: 0; }
.meter { display: inline-block; vertical-align: middle; width: 120px; height: 7px; border-radius: 4px; background: var(--muted-soft); overflow: hidden; margin-right: 8px; }
.meter i { display: block; height: 100%; background: var(--ok); }
.days { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding: 10px 12px 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); }
.days .d { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 14px; }
.days .d i { display: block; width: 100%; max-width: 34px; background: var(--blaze); border-radius: 3px 3px 0 0; min-height: 2px; }
.days .d span { font-size: 11px; color: var(--ink-3); padding-bottom: 6px; }

/* ---------- rules / lists editor ---------- */
.rules { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); padding: 18px 22px; line-height: 1.6; max-width: 80ch; }
.editor { display: grid; grid-template-columns: 230px 1fr; gap: 22px; margin-top: 18px; }
.editor nav { display: flex; flex-direction: column; gap: 2px; }
.editor nav button { text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: var(--r-s); cursor: pointer; color: var(--ink-2); }
.editor nav button.on { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); }
.editor nav button.off { text-decoration: line-through; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); padding: 6px 18px 18px; }
.rowedit { display: grid; grid-template-columns: 120px 1fr 110px 1fr 30px; gap: 8px; align-items: center; margin: 6px 0; }
.tplrow { border: 1px solid var(--rule-2); border-radius: var(--r-m); padding: 10px; margin: 8px 0; }
.tplrow .top2 { display: flex; gap: 8px; margin-bottom: 6px; }
.tplrow .top2 input { flex: 1; }
.marksel { display: flex; flex-wrap: wrap; gap: 4px 16px; }

@media (max-width: 900px) {
  .gridwrap { grid-template-columns: minmax(0, 1fr); }
  .drawer { width: auto; position: static; max-height: none; }
  .editor { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .rowedit { grid-template-columns: 1fr 1fr; }
  .top { flex-wrap: wrap; height: auto; padding: 8px 16px 0; row-gap: 4px; }
  .top .brand { order: 1; }
  .top .who { order: 2; margin-left: auto; }
  .top .who .muted { display: none; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 6px; }
  .nav a { white-space: nowrap; }
  .actions { margin-left: 0; }
  input.search { width: 100%; }
  .tablebox { max-height: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* recently contacted rows, admin link, row action, template picker, extension page */
.grid tr.hot td { background: var(--warn-soft); }
.grid tr.hot.sel td { background: var(--sel); }
.refcell { display: flex; align-items: center; gap: 6px; }
.refcell .ext { color: var(--ink-2); text-decoration: none; font-size: 12px; padding: 0 3px; border-radius: 4px; }
.refcell .ext:hover { color: var(--ink); background: var(--row-hover); }
.contacted { color: var(--warn); font-size: 11.5px; font-weight: 600; margin-top: 2px; white-space: nowrap; }
.tpl.on { box-shadow: inset 3px 0 0 var(--focus); padding-left: 10px; margin-left: -10px; }
.tpl .pick { display: flex; align-items: center; gap: 7px; flex: 1; cursor: pointer; }
.small { font-size: 12.5px; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-m); padding: 16px 18px; margin: 8px 0 20px; max-width: 680px; }
.extrow { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.upload { border-top: 1px solid var(--rule-2); margin-top: 14px; padding-top: 12px; display: grid; gap: 8px; }
.steps { padding-left: 20px; line-height: 1.7; max-width: 680px; }
