/* Monarch Search. System fonts only: the page works offline and loads nothing from elsewhere. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e6e8ee;
  --line-strong: #d3d7e0;
  --text: #1b1f2a;
  --muted: #687083;
  --faint: #9aa1b1;
  --brand: #14213d;
  --accent: #3d5afe;
  --accent-soft: #e8ecff;
  --accent-text: #2a3fd1;
  --pos: #16803c;
  --warn-bg: #fff6d6;
  --warn: #8a5a00;
  --pend-bg: #f1e9ff;
  --pend: #7442d6;
  --danger-bg: #ffeceb;
  --danger: #b42318;
  --hit: #fff1a8;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 16%);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b23;
    --panel-2: #1c212b;
    --line: #262c38;
    --line-strong: #333b4a;
    --text: #e6e9ef;
    --muted: #9aa3b5;
    --faint: #6b7385;
    --brand: #c9d3ff;
    --accent: #7b8cff;
    --accent-soft: #232b4d;
    --accent-text: #aab6ff;
    --pos: #4ccf7c;
    --warn-bg: #3a2e0c;
    --warn: #f3c45b;
    --pend-bg: #2e2346;
    --pend: #c4a6ff;
    --danger-bg: #3d1a18;
    --danger: #ff8a80;
    --hit: #5b4a00;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 50%);
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
code, kbd { font-family: var(--mono); font-size: 12px; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); background: var(--panel); }

/* ----- top bar ----- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--brand); font-size: 16px; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; stroke: none; color: var(--accent); }
.brand b { font-weight: 700; }
.searchbox {
  flex: 1; max-width: 760px;
  display: flex; align-items: center; gap: 10px;
  height: 42px; padding: 0 12px;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 12px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.searchbox:focus-within { background: var(--panel); border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.searchbox input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--text); }
.searchbox input::-webkit-search-cancel-button { display: none; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
select {
  height: 36px; padding: 0 30px 0 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  appearance: none; cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel); box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { box-shadow: none; }
.btn.small { height: 30px; font-size: 13px; }
.btn .count { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--line); color: var(--text); }
.link { border: 0; background: none; color: var(--accent-text); cursor: pointer; padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }
.filters-toggle { display: none; }

.help {
  position: fixed; top: 64px; right: 20px; z-index: 40; width: min(460px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 16px 18px;
}
.help h3 { margin: 0 0 10px; font-size: 15px; }
.help table { border-collapse: collapse; width: 100%; }
.help td { padding: 5px 0; vertical-align: top; border-top: 1px solid var(--line); }
.help td:first-child { width: 42%; padding-right: 10px; }
.help code { background: var(--accent-soft); color: var(--accent-text); padding: 1px 5px; border-radius: 4px; }
.help p { margin: 12px 0 0; color: var(--muted); }

/* ----- layout ----- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; padding: 20px; max-width: 1680px; margin: 0 auto; }
main { min-width: 0; }

/* ----- filters ----- */
.filters {
  position: sticky; top: 86px; align-self: start;
  max-height: calc(100vh - 106px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.filters-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 650; }
.filters-head .link { margin-left: auto; }
.close-drawer { display: none; }
.filters section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.filters h4 { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 10px; font-size: 12px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.filters h4 .sel { text-transform: none; letter-spacing: 0; color: var(--accent-text); font-weight: 600; }
.chipset { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 13px; }
.chip small { color: var(--faint); }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.on small { color: #fffc; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.pair label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.pair input, .mini {
  width: 100%; height: 32px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel-2);
}
.pair input:focus, .mini:focus { outline: 0; border-color: var(--accent); background: var(--panel); }
.mini { margin-bottom: 8px; }
.segmented { display: flex; padding: 3px; gap: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 6px; padding: 5px 4px; cursor: pointer; font-size: 13px; color: var(--muted); }
.segmented button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.checklist { max-height: 260px; overflow-y: auto; margin: 0 -6px; scrollbar-width: thin; }
.checklist .group { position: sticky; top: 0; background: var(--panel); padding: 6px 6px 2px; font-size: 11px; font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.check:hover { background: var(--panel-2); }
.check input { accent-color: var(--accent); margin: 0; }
.check .name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; overflow: hidden; }
.check .name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check .name > .keep-end { flex: 0 1 auto; }
.check small { flex: 1 1 0; }
.check small { color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check .n { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.check.dim { opacity: .55; }
.toggle { display: flex; align-items: center; gap: 8px; margin-top: 10px; cursor: pointer; }
.toggle input { accent-color: var(--accent); margin: 0; }
.footnote { margin: 0; padding: 12px 16px 16px; color: var(--faint); font-size: 12px; }

/* ----- category colours: a stable hue per category name ----- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c); }
.h0 { --c: #e5484d; } .h1 { --c: #f76b15; } .h2 { --c: #e2a336; } .h3 { --c: #8db600; }
.h4 { --c: #30a46c; } .h5 { --c: #12a594; } .h6 { --c: #0894b3; } .h7 { --c: #3e63dd; }
.h8 { --c: #6e56cf; } .h9 { --c: #ab4aba; } .h10 { --c: #d6409f; } .h11 { --c: #8d8d86; }

/* ----- summary ----- */
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(280px, 1.6fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: opacity .2s;
}
.summary > * { background: var(--panel); padding: 14px 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--faint); }
.pos { color: var(--pos); }
.cats { display: flex; flex-direction: column; gap: 3px; }
.cats .label { margin-bottom: 4px; }
.bar { display: grid; grid-template-columns: minmax(90px, 1.1fr) 1.3fr auto; align-items: center; gap: 10px; border: 0; background: none; padding: 2px 4px; margin: 0 -4px; border-radius: 6px; cursor: pointer; text-align: left; font-size: 13px; }
.bar:hover { background: var(--panel-2); }
.bar-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--c); opacity: .85; }
.bar-amt { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 72px; text-align: right; }
.bar-amt.pos { color: var(--pos); }

.active { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 13px; font-weight: 500; }
.pill button { border: 0; background: none; color: inherit; cursor: pointer; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; opacity: .7; }
.pill button:hover { opacity: 1; background: color-mix(in srgb, var(--accent) 18%, transparent); }
.banner { margin-top: 14px; padding: 10px 14px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); }

/* ----- results ----- */
.results {
  margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: opacity .2s;
}
.busy { opacity: .55; }
.head, .row {
  display: grid; grid-template-columns: 128px minmax(0, 2.4fr) minmax(0, 1.1fr) minmax(0, 1fr) 128px;
  gap: 14px; align-items: center; padding: 0 18px;
}
.head {
  position: sticky; top: 67px; z-index: 5; height: 38px;
  background: var(--panel-2); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.r { text-align: right; }
.month {
  position: sticky; top: 105px; z-index: 4;
  padding: 6px 18px; background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; color: var(--brand); letter-spacing: .02em;
}
.row { min-height: 37px; padding-top: 2px; padding-bottom: 2px; line-height: 1.2; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .1s; }
.row:hover { background: var(--panel-2); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.item.open .row { background: var(--accent-soft); border-bottom-color: transparent; }
.date { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.date .tag { margin-top: 0; }
.merchant { min-width: 0; display: flex; flex-direction: column; }
.merchant b, .merchant small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merchant b { font-weight: 600; }
.merchant small { color: var(--muted); font-size: 12px; }
.strong { font-weight: 700; color: var(--text); }
.em { font-style: italic; }
.under { text-decoration: underline; }
.hit { background: var(--hit); border-radius: 3px; box-shadow: 0 0 0 1px var(--hit); }
.flags { display: flex; flex-wrap: wrap; gap: 4px; }
.flags:empty { display: none; }
.tag { display: inline-block; margin-top: 1px; padding: 0 6px; line-height: 16px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.pending { background: var(--pend-bg); color: var(--pend); border-color: transparent; }
.tag.review { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag.gone { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.tag.user { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.note { margin-top: 1px; color: var(--faint); font-size: 12px; }
.category { display: flex; align-items: center; gap: 7px; min-width: 0; }
.category span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Long account names lose their middle, never the last 6 characters, where the account number
   usually is: "Mary Prosperity Che….2505)". */
.keep-end { display: flex; min-width: 0; white-space: nowrap; }
.keep-end .ke-start { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.keep-end .ke-end { flex: none; white-space: pre; }
.account { color: var(--muted); }
.amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.removed .merchant b, .item.removed .amount { text-decoration: line-through; color: var(--faint); }

.detail { padding: 4px 18px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--line); cursor: default; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; padding: 14px 16px; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); }
.detail dl { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.detail .dl-pair { display: contents; }
.detail dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail .pre { white-space: pre-wrap; }
.history h5 { margin: 0 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.history ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history li { font-size: 13px; }
.history time { color: var(--faint); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.history .old { color: var(--faint); text-decoration: line-through; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.muted { color: var(--muted); }

.skeleton { padding: 8px 18px; }
.bone { height: 38px; margin: 8px 0; border-radius: 6px; background: linear-gradient(90deg, var(--panel-2) 25%, var(--line) 50%, var(--panel-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 56px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--faint); }
.empty p { margin: 0 0 8px; font-size: 15px; }
.sentinel { height: 1px; }
.tail { display: flex; justify-content: center; padding: 16px; color: var(--muted); font-size: 13px; }
.spinner { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scrim { display: none; }

/* ----- narrower screens: filters become a drawer ----- */
@media (max-width: 1180px) {
  .summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cats { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .filters-toggle, .close-drawer { display: inline-flex; }
  .filters {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(340px, 88vw); max-height: none;
    border-radius: 0 var(--radius) var(--radius) 0; transform: translateX(-105%); transition: transform .22s ease;
  }
  .filters.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgb(10 14 22 / 45%); }
  .head, .row { grid-template-columns: 88px minmax(0, 1fr) minmax(0, .8fr) 110px; }
  .head span:nth-child(4), .row .account { display: none; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .brand span { display: none; }
  .searchbox { order: 3; flex-basis: 100%; }
  .summary { grid-template-columns: 1fr 1fr; }
  .head { display: none; }
  .row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "m a" "d c"; gap: 2px 10px; padding: 10px 14px; }
  .row .merchant { grid-area: m; } .row .amount { grid-area: a; } .row .date { grid-area: d; font-size: 12px; }
  .row .category { grid-area: c; justify-self: end; font-size: 12px; color: var(--muted); }
  .month { top: 108px; }
}

/* ----- approval page (gate.html) ----- */
.gate-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate {
  width: 100%; max-width: 420px; padding: 28px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.gate h1 { margin: 22px 0 6px; font-size: 19px; }
.gate-note { margin: 0 0 18px; color: var(--muted); }
.gate form { display: grid; gap: 8px; }
.gate label { font-size: 12px; font-weight: 650; color: var(--muted); }
.gate input {
  height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--panel-2);
}
.gate input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn.primary { justify-content: center; margin-top: 8px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { color: #fff; filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.gate-error { margin: 14px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); }
.gate-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: gate-spin 0.9s linear infinite;
}
@keyframes gate-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .gate-spinner { animation: none; } }
.gate.revoke { max-width: 560px; }
.device-list { list-style: none; margin: 0 0 12px; padding: 0; }
.device-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.device-list li div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.device-list small { color: var(--muted); font-size: 12px; }
.device-list .tag { align-self: flex-start; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); }
.gate a { color: var(--accent-text); }
