/* Nexus Sleep brand: sand #BAB29D, black, white */
:root {
  color-scheme: light;
  --brand: #BAB29D;
  --brand-ink: #0B0B0B;
  --brand-logo: #FFFFFF;
  --page: #F5F3EE;
  --surface: #FFFFFF;
  --ink: #0B0B0B;
  --ink-2: #5A564C;
  --muted: #8E897D;
  --grid: #ECE8DF;
  --axis: #D3CDC0;
  --ring: rgba(11, 11, 11, 0.09);
  --wash: #EFEBE2;
  --series-1: #1F1D19;                         /* actual sales, positive margins, meter */
  --series-1-wash: rgba(186, 178, 157, 0.38);  /* sand fill under the line */
  --bar: #9C937A;                              /* cost breakdown bars (deep sand) */
  --negative: #D03B3B;
  --target-line: #A39E92;
  --band: rgba(186, 178, 157, 0.30);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --chip-good-bg: rgba(12, 163, 12, 0.10);
  --chip-warn-bg: rgba(250, 178, 25, 0.16);
  --chip-crit-bg: rgba(208, 59, 59, 0.10);
  --seg-on-bg: #0B0B0B;
  --seg-on-ink: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #000000; --brand-ink: #FFFFFF; --brand-logo: #FFFFFF;
    --page: #0B0B0B; --surface: #161512; --ink: #FFFFFF; --ink-2: #C9C3B5; --muted: #8E897D;
    --grid: #2A2823; --axis: #3A3730; --ring: rgba(255, 255, 255, 0.09); --wash: #23211C;
    --series-1: #CDB98A; --series-1-wash: rgba(205, 185, 138, 0.14); --bar: #A39A80;
    --negative: #E66767; --target-line: #6E6A60; --band: rgba(186, 178, 157, 0.16);
    --good-text: #0ca30c; --chip-good-bg: rgba(12, 163, 12, 0.18); --chip-crit-bg: rgba(208, 59, 59, 0.22);
    --seg-on-bg: #BAB29D; --seg-on-ink: #0B0B0B;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #000000; --brand-ink: #FFFFFF; --brand-logo: #FFFFFF;
  --page: #0B0B0B; --surface: #161512; --ink: #FFFFFF; --ink-2: #C9C3B5; --muted: #8E897D;
  --grid: #2A2823; --axis: #3A3730; --ring: rgba(255, 255, 255, 0.09); --wash: #23211C;
  --series-1: #CDB98A; --series-1-wash: rgba(205, 185, 138, 0.14); --bar: #A39A80;
  --negative: #E66767; --target-line: #6E6A60; --band: rgba(186, 178, 157, 0.16);
  --good-text: #0ca30c; --chip-good-bg: rgba(12, 163, 12, 0.18); --chip-crit-bg: rgba(208, 59, 59, 0.22);
  --seg-on-bg: #BAB29D; --seg-on-ink: #0B0B0B;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }

.page { max-width: 1240px; margin: 0 auto; padding: 24px 24px 48px; display: grid; gap: 16px; }

/* header + controls */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.top h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.sub, .sync { color: var(--ink-2); font-size: 13px; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--wash); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--seg-on-bg); color: var(--seg-on-ink); font-weight: 600; }
.seg-small button { padding: 4px 10px; font-size: 13px; }
.nav { display: flex; align-items: center; gap: 8px; }
.period-label { min-width: 170px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.icon-btn, .ghost {
  border: 0; background: var(--surface); box-shadow: 0 0 0 1px var(--ring);
  border-radius: 8px; cursor: pointer; height: 32px;
}
.icon-btn { width: 32px; font-size: 20px; line-height: 1; }
.ghost { padding: 0 12px; color: var(--ink-2); }
.icon-btn:hover, .ghost:hover { background: var(--wash); }
button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--chip-warn-bg); border-radius: 10px; padding: 10px 14px; color: var(--ink);
}
.banner svg { flex: none; margin-top: 2px; }
.banner[hidden], .tooltip[hidden], .channels[hidden] { display: none; }

/* tiles */
.tiles { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 16px; }
.tile, .card { background: var(--surface); border-radius: 14px; box-shadow: 0 0 0 1px var(--ring); }
.tile { padding: 18px 20px; display: grid; gap: 6px; align-content: start; }
.tile-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.hero { font-size: 48px; font-weight: 650; line-height: 1.05; letter-spacing: -0.02em; }
.value { font-size: 30px; font-weight: 650; line-height: 1.1; letter-spacing: -0.01em; }
.tile-note { color: var(--ink-2); font-size: 13px; }
.meter { position: relative; height: 8px; background: var(--wash); border-radius: 4px; margin: 6px 0 2px; overflow: hidden; }
/* Sales-vs-target bar: red at the start, amber halfway, green at 100% of target.
   The gradient is sized to the whole track, so the end of the fill shows how close you are. */
.meter-fill {
  height: 100%; width: 0; border-radius: 4px; transition: width .3s ease, background-size .3s ease;
  background-image: linear-gradient(90deg, #D03B3B 0%, #E8A317 50%, #0CA30C 100%);
  background-repeat: no-repeat;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.chip svg { flex: none; }
.chip-good { background: var(--chip-good-bg); color: var(--good-text); }
.chip-warn { background: var(--chip-warn-bg); color: var(--ink); }
.chip-crit { background: var(--chip-crit-bg); color: var(--ink); }

/* cards */
.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
.card { padding: 18px 20px 20px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-sub { color: var(--ink-2); font-size: 13px; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; color: var(--ink-2); font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.key-line { background: var(--series-1); }
.key-target { background: var(--target-line); }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.end-label-2 { fill: var(--ink-2); font-size: 12px; }

/* horizontal bars */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: 128px 1fr minmax(118px, auto); align-items: center; gap: 10px; font-size: 13px; }
.hbar-label { color: var(--ink-2); }
.hbar-track { position: relative; height: 14px; }
.hbar-fill { position: absolute; top: 0; height: 14px; border-radius: 0 4px 4px 0; background: var(--bar); min-width: 2px; }
.hbar.total .hbar-fill:not(.neg) { background: var(--series-1); }
.hbar-fill.neg { background: var(--negative); border-radius: 4px 0 0 4px; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.hbar-value span { color: var(--ink-2); }
.hbar.total { border-top: 1px solid var(--grid); padding-top: 10px; }
.hbar.total .hbar-label { color: var(--ink); font-weight: 600; }
.hbar.total .hbar-value { font-weight: 600; }

/* diverging bars */
.dbars { display: grid; gap: 12px; }
.dbar { display: grid; grid-template-columns: 210px 1fr 64px; align-items: center; gap: 12px; font-size: 13px; }
.dbar-label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbar-track { position: relative; height: 18px; }
.dbar-band { position: absolute; top: -6px; bottom: -6px; background: var(--band); }
.dbar-zero { position: absolute; top: -6px; bottom: -6px; width: 1px; background: var(--axis); }
.dbar-fill { position: absolute; top: 2px; height: 14px; background: var(--series-1); }
.dbar-fill.pos { border-radius: 0 4px 4px 0; }
.dbar-fill.neg { background: var(--negative); border-radius: 4px 0 0 4px; }
.dbar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dbar-axis { display: grid; grid-template-columns: 210px 1fr 64px; gap: 12px; }
.dbar-axis .ticks { position: relative; height: 16px; }
.dbar-axis .ticks span { position: absolute; transform: translateX(-50%); color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.band-note { color: var(--ink-2); font-size: 12px; display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.band-swatch { width: 14px; height: 10px; background: var(--band); border-radius: 2px; box-shadow: 0 0 0 1px var(--ring); }

/* table */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
th:first-child, td:first-child { text-align: left; }
td:first-child { color: var(--ink); font-weight: 500; }
tr.total td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--axis); }
td.neg { color: var(--critical); }
.empty { color: var(--ink-2); padding: 24px 0; text-align: center; }

.foot { color: var(--muted); font-size: 12px; line-height: 1.6; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 150px;
  background: var(--surface); color: var(--ink); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 0 0 1px var(--ring), 0 8px 24px rgba(0, 0, 0, 0.14);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.tooltip b { display: block; font-size: 12px; margin-bottom: 4px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 16px; color: var(--ink-2); }
.tooltip .row strong { color: var(--ink); font-weight: 600; }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page { padding: 16px 16px 40px; }
  .tiles { grid-template-columns: 1fr; }
  .hero { font-size: 40px; }
  .controls { flex-direction: column; align-items: stretch; }
  .nav { justify-content: space-between; }
  .period-label { min-width: 0; flex: 1; }
  .hbar { grid-template-columns: 96px 1fr minmax(104px, auto); }
  .dbar { grid-template-columns: 1fr 56px; row-gap: 4px; column-gap: 8px; }
  .dbar-label { grid-column: 1 / -1; }
  .dbar-axis { grid-template-columns: 1fr 56px; gap: 8px; }
  .dbar-axis > span:first-child { display: none; }
}

/* live sync */
.live { display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.live-dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--chip-good-bg); }
.live-dot.warn { background: var(--warning); }
.live-dot.err { background: var(--critical); }
.live-dot.busy { background: var(--series-1); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-dot.busy { animation: none; } }
.ghost.small { height: 28px; padding: 0 10px; font-size: 13px; }
.ghost:disabled { opacity: .5; cursor: default; }
.channels { background: var(--surface); border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); padding: 10px 14px; font-size: 13px; }
.channels summary { cursor: pointer; color: var(--ink-2); display: flex; align-items: center; gap: 8px; list-style: none; }
.channels summary::-webkit-details-marker { display: none; }
.channels summary::after { content: "▸"; margin-left: auto; color: var(--muted); }
.channels[open] summary::after { content: "▾"; }
.channels ul { list-style: none; margin: 10px 0 2px; padding: 0; display: grid; gap: 6px; }
.channels li { display: grid; grid-template-columns: 16px 220px 110px 1fr; gap: 8px; align-items: baseline; }
.channels li .when { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.channels li .msg { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
  .live { flex-wrap: wrap; }
  .channels li { grid-template-columns: 16px 1fr auto; }
  .channels li .msg { grid-column: 2 / -1; white-space: normal; }
}

/* brand bar */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.brandbar { background: var(--brand); color: var(--brand-ink); border-bottom: 1px solid rgba(0, 0, 0, 0.06); }
:root:not([data-theme="light"]) .brandbar { border-bottom-color: transparent; }
.brandbar-inner { max-width: 1240px; margin: 0 auto; padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand .logo { height: 46px; width: auto; color: var(--brand-logo); display: block; }
.brand-divider { width: 1px; height: 30px; background: currentColor; opacity: .25; }
.brandbar .sub { color: var(--brand-ink); opacity: .8; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.brandbar .sync { color: var(--brand-ink); }
.brandbar .ghost { background: rgba(255, 255, 255, 0.55); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12); color: var(--brand-ink); }
.brandbar .ghost:hover { background: rgba(255, 255, 255, 0.8); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brandbar { border-bottom: 1px solid #BAB29D; }
  :root:not([data-theme="light"]) .brandbar .ghost { background: #161512; box-shadow: 0 0 0 1px rgba(255,255,255,.14); }
}
:root[data-theme="dark"] .brandbar { border-bottom: 1px solid #BAB29D; }
:root[data-theme="dark"] .brandbar .ghost { background: #161512; box-shadow: 0 0 0 1px rgba(255,255,255,.14); }
.live-dot.ok { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45); }
@media (max-width: 640px) {
  .brandbar-inner { padding: 12px 16px; }
  .brand .logo { height: 36px; }
  .brand-divider, .brandbar .sub { display: none; }
}

/* account nav */
.usernav { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.usernav[hidden] { display: none; }
.usernav a { color: var(--brand-ink); text-decoration: none; opacity: .85; }
.usernav a:hover { opacity: 1; text-decoration: underline; }
.usernav form { margin: 0; }
a.brand { color: inherit; text-decoration: none; }

/* forms & auth pages */
.auth-body { background: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auth-body { background: var(--page); } }
:root[data-theme="dark"] .auth-body { background: var(--page); }
.auth-body .brandbar { border-bottom: 0; }
.auth-page { max-width: 440px; padding-top: 48px; }
.auth-card, .card.narrow { padding: 28px 28px 24px; }
.card.narrow { max-width: 560px; }
.auth-card h2 { font-size: 20px; font-weight: 650; margin-bottom: 4px; }
.form { display: grid; gap: 14px; margin-top: 18px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form input[type=text], .form input[type=email], .form input[type=password], .copy-row input {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
.form input:focus, .copy-row input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; border-color: transparent; }
button.primary {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 11px 16px; cursor: pointer;
  background: var(--seg-on-bg); color: var(--seg-on-ink);
}
button.primary:hover { opacity: .9; }
.ghost.danger { color: var(--critical); }
.form-error { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--chip-crit-bg); color: var(--ink); font-size: 13px; }
.form-help { margin-top: 14px; color: var(--ink-2); font-size: 12px; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--chip-good-bg); font-size: 13px; }
.muted { color: var(--muted); }
.link-card { box-shadow: 0 0 0 2px var(--brand-deep, #9C937A); }
.copy-row { display: flex; gap: 8px; margin-top: 14px; }
.copy-row input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.users-table th, .users-table td, .log-table th, .log-table td { text-align: left; }
.users-table td.actions { text-align: right; }
.row-actions { display: inline-flex; gap: 6px; }
.row-actions form { margin: 0; }
.copy-row button { white-space: nowrap; }
.users-table td:first-child { white-space: nowrap; }
main.page > .card + .card { margin-top: 0; }
@media (max-width: 640px) {
  .usernav { width: 100%; justify-content: flex-end; }
  .copy-row { flex-direction: column; }
}
