:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --line: #e4e6ea;
  --line-strong: #c2c2c2;
  --accent: #1b64be;
  --accent-ink: #ffffff;
  --accent-soft: #e8f1fc;
  --good: #0a7d1d;   --good-bg: #e6f5e8;
  --warn: #8a5a00;   --warn-bg: #fff4d6;
  --bad: #b42324;    --bad-bg: #fde8e8;
  --muted-bg: #eef0f3;
  --seq-100: #cce3fd; --seq-250: #84b9f3; --seq-400: #338ced; --seq-550: #1b64be; --seq-700: #0e3d7e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11,11,11,.06), 0 1px 0 rgba(11,11,11,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b; --surface: #191919; --ink: #efefef; --ink-2: #9c9c9c;
    --line: #303030; --line-strong: #474747;
    --accent: #338ced; --accent-ink: #0b0b0b; --accent-soft: #14273d;
    --good: #53c556; --good-bg: #13291a; --warn: #fbb315; --warn-bg: #2e2510; --bad: #f27474; --bad-bg: #331616;
    --muted-bg: #242424;
    --seq-100: #14273d; --seq-250: #1757ac; --seq-400: #2370cd; --seq-550: #519ced; --seq-700: #9dc8f7;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--ink-2); }
.pad { padding: 1rem; }
.num { font-variant-numeric: tabular-nums; }

/* sidebar (collapsible; off-canvas on phones) */
:root { --sb-w: 228px; --sb-w-min: 64px; }
.sidebar, .mobilebar, .scrim { display: none; }
body.authed .sidebar { display: flex; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sb-w); flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line); transition: width .18s ease, transform .18s ease; overflow: hidden; }
body.authed .content { margin-left: var(--sb-w); transition: margin-left .18s ease; }
body.authed.sb-collapsed .sidebar { width: var(--sb-w-min); }
body.authed.sb-collapsed .content { margin-left: var(--sb-w-min); }
body.sb-collapsed .sidebar .label, body.sb-collapsed .sidebar .count-text { display: none; }

.sb-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .85rem .75rem .85rem 1rem; border-bottom: 1px solid var(--line); min-height: 58px; }
body.sb-collapsed .sb-head { flex-direction: column; padding: .75rem .5rem; gap: .6rem; }
.brand { font-weight: 700; color: var(--ink); letter-spacing: .02em; display: inline-flex; align-items: center; gap: .55rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--accent); }
.brand .label span { color: var(--accent); }
.brand img { display: block; height: auto; }
.brand-mark { display: none !important; }
body.sb-collapsed .brand-full { display: none; }
body.sb-collapsed .brand-mark { display: block !important; }
.crm-tag { font-size: .72rem; font-weight: 700; letter-spacing: .08em; color: var(--accent) !important; border: 1px solid currentColor;
  border-radius: 5px; padding: 0 .3rem; line-height: 1.5; }
.login-logo { display: block; width: 220px; max-width: 80%; height: auto; margin: 0 auto .5rem; }
.icon-btn { border: 1px solid transparent; background: none; padding: .3rem; border-radius: 8px; color: var(--ink-2); line-height: 0; }
.icon-btn:hover { background: var(--muted-bg); color: var(--ink); border-color: transparent; }
.icon-btn svg { width: 20px; height: 20px; }

#nav { display: flex; flex-direction: column; gap: 2px; padding: .6rem .5rem; flex: 1; overflow-y: auto; }
.navlink { display: flex; align-items: center; gap: .75rem; padding: .55rem .7rem; border-radius: 8px; color: var(--ink-2);
  white-space: nowrap; border: 0; background: none; width: 100%; font: inherit; text-align: left; position: relative; }
.navlink svg { width: 20px; height: 20px; flex: none; }
.navlink:hover { background: var(--muted-bg); color: var(--ink); text-decoration: none; border: 0; }
.navlink.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
body.sb-collapsed .navlink { justify-content: center; padding: .6rem 0; }
.count { display: inline-block; min-width: 1.4em; margin-left: auto; padding: 0 .4em; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: .75rem; text-align: center; font-weight: 600; }
body.sb-collapsed .count { position: absolute; top: 2px; right: 6px; margin: 0; min-width: 1.2em; font-size: .68rem; }
.sb-foot { border-top: 1px solid var(--line); padding: .6rem .5rem; }
.sb-foot .who { color: var(--ink-2); font-size: .85rem; padding: .2rem .7rem .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner { background: var(--warn-bg); color: var(--warn); padding: .45rem 1.25rem; font-size: .88rem; border-bottom: 1px solid var(--line); }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

@media (max-width: 760px) {
  body.authed .content, body.authed.sb-collapsed .content { margin-left: 0; }
  body.authed .mobilebar { display: flex; position: sticky; top: 0; z-index: 10; align-items: center; gap: .6rem;
    padding: .5rem .75rem; background: var(--surface); border-bottom: 1px solid var(--line); }
  /* on phones the menu is a full-width drawer; the desktop collapse state doesn't apply */
  .sidebar, body.sb-collapsed .sidebar { width: min(280px, 85vw); transform: translateX(-100%); box-shadow: 0 0 24px rgba(0,0,0,.2); }
  body.sb-collapsed .sidebar .label { display: inline; }
  body.sb-collapsed .brand-full { display: block; }
  body.sb-collapsed .brand-mark { display: none !important; }
  body.sb-collapsed .sb-head { flex-direction: row; padding: .85rem .75rem .85rem 1rem; }
  body.sb-collapsed .navlink { justify-content: flex-start; padding: .55rem .7rem; }
  body.sb-collapsed .count { position: static; margin-left: auto; }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.35); }
  #collapse { display: none; }
}

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 860px) { .grid.two { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* controls */
button, .btn { font: inherit; cursor: pointer; border-radius: 8px; padding: .45rem .9rem; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; gap: .35rem; }
button:hover, .btn:hover { border-color: var(--ink-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: .45rem .6rem; width: 100%; }
textarea { min-height: 4.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--ink-2); }
label > input, label > select, label > textarea { margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.filters > * { width: auto; min-width: 150px; }
.filters input[type=search] { flex: 1; min-width: 200px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; }
tbody tr:hover { background: var(--muted-bg); }
tr.click { cursor: pointer; }
td.r, th.r { text-align: right; }
.table-wrap { overflow-x: auto; }

/* badges & pills */
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--muted-bg); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.pills { display: flex; gap: .3rem; flex-wrap: wrap; }

/* lead page */
.product { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; }
.product + .product { margin-top: .75rem; }
.product-head { display: flex; justify-content: space-between; gap: .75rem; align-items: center; flex-wrap: wrap; }
.product-head select { width: auto; }
.item { margin-top: .7rem; padding-top: .7rem; border-top: 1px dashed var(--line); }
.item.sub { margin-left: 1rem; padding-left: .8rem; border-left: 3px solid var(--line); border-top: 0; }
.voucher { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .95rem; letter-spacing: .02em;
  background: var(--muted-bg); padding: .15rem .45rem; border-radius: 6px; user-select: all; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .9rem; font-size: .9rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: .82rem; color: var(--ink-2); }
.timeline .details { font-size: .9rem; margin-top: .25rem; }
.dup { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: .5rem .7rem; font-size: .9rem; }
.hist { font-size: .85rem; color: var(--ink-2); margin-top: .35rem; }

/* overview */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.tile .label { font-size: .82rem; color: var(--ink-2); }
.tile .value { font-size: 1.75rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .sub { font-size: .8rem; color: var(--ink-2); }
.tile.alert .value { color: var(--bad); }
.heat td.cell { text-align: center; font-variant-numeric: tabular-nums; border: 2px solid var(--surface); border-radius: 6px; min-width: 3.2rem; }
.heat td.z { color: var(--ink-2); opacity: .5; }
.heat td.s1 { background: var(--seq-100); }
.heat td.s2 { background: var(--seq-250); }
.heat td.s3 { background: var(--seq-400); color: #fff; }
.heat td.s4 { background: var(--seq-550); color: #fff; }
.heat td.s5 { background: var(--seq-700); color: #fff; }
@media (prefers-color-scheme: dark) { .heat td.s4, .heat td.s5 { color: #0b0b0b; } }
.heat th.stage { text-align: center; font-size: .72rem; }
.bar { position: relative; height: 8px; background: var(--muted-bg); border-radius: 4px; min-width: 80px; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--seq-400); border-radius: 4px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.15rem; font-weight: 600; margin-bottom: .2rem; }
.login-card .btn { margin-top: 1rem; justify-content: center; width: 100%; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; background: var(--surface); color: var(--ink); max-width: 460px; width: calc(100% - 2rem); }
dialog::backdrop { background: rgba(0,0,0,.35); }

#toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface);
  padding: .55rem 1rem; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  main { padding: .75rem; }
  .hide-sm { display: none; }
}
