/* Bitebell partner portal — one stylesheet, tokens first. */

:root {
  color-scheme: light;
  --page: #f5f6f6;
  --surface: #ffffff;
  --surface-2: #f9fafa;
  --text: #16191a;
  --text-2: #596164;
  --text-3: #858d90;
  --hairline: #e6e8e9;
  --border: rgba(15, 23, 25, 0.12);
  --accent: #0f766e;
  --accent-hover: #0b5f59;
  --accent-ink: #ffffff;
  --accent-soft: #e5f2f0;
  --chart: #0d9488;
  --chart-muted: #8fcdc6;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --good: #006c10;
  --bad: #b42318;
  --warn-bg: #fff6dd;
  --warn-ink: #6e4600;
  --warn-line: #f2d48a;
  --crit-bg: #fdecea;
  --crit-ink: #8a1c12;
  --info-bg: #e9f3f2;
  --info-ink: #0b4f49;
  --shadow: 0 1px 2px rgba(16, 24, 26, 0.04), 0 1px 1px rgba(16, 24, 26, 0.03);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0c0e0e;
    --surface: #161919;
    --surface-2: #1b1f1f;
    --text: #eceeee;
    --text-2: #a3abad;
    --text-3: #7b8486;
    --hairline: #272c2d;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #2bb3a3;
    --accent-hover: #3cc6b5;
    --accent-ink: #04211e;
    --accent-soft: #12302d;
    --chart: #2bb3a3;
    --chart-muted: #1d6a62;
    --grid: #2b3030;
    --axis: #474747;
    --good: #53c556;
    --bad: #ff8a7a;
    --warn-bg: #2e2510;
    --warn-ink: #f4cf7c;
    --warn-line: #5a4517;
    --crit-bg: #3a1714;
    --crit-ink: #ffb4a9;
    --info-bg: #10292a;
    --info-ink: #9fe0d6;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
small, .muted { color: var(--text-2); }
.subtle { color: var(--text-3); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- shell */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-inner, .container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .topbar-inner, .container { padding: 0 32px; } }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 14px; font-weight: 750;
}
.brand small { font-weight: 450; color: var(--text-2); }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav a {
  color: var(--text-2); padding: 6px 10px; border-radius: 7px; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); font-weight: 550; }
.nav .badge-count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--warn-bg); color: var(--warn-ink); font-size: 12px; text-align: center;
}
.usermenu { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); }
.usermenu form { margin: 0; }
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 6px; gap: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .usermenu .who { display: none; }
  .brand small { display: none; }
}
main { padding: 28px 0 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 24px; }
.page-head p { margin-top: 4px; }
.eyebrow { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack > * + * { margin-top: 24px; }

/* ---------- cards & tiles */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 16px 20px 0; }
.card-head p { font-size: 13px; color: var(--text-2); }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 12px 0 0; }

.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.tile { padding: 18px 20px; }
.tile-label { font-size: 13px; color: var(--text-2); }
.tile-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; }
.tile-value .unit { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 4px; letter-spacing: 0; }
.tile-meta { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.hero { padding: 22px 24px; }
.hero .tile-value { font-size: 48px; line-height: 1.1; margin-top: 6px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.grid-hero { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid-hero > * { min-width: 0; }
.hero { display: flex; flex-direction: column; }
.hero-facts { margin-top: auto; padding-top: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; border-top: 1px solid var(--hairline); }
.hero-facts dt { font-size: 12px; color: var(--text-2); }
.hero-facts dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hero .actions { margin-bottom: 20px; }
@media (min-width: 980px) { .grid-hero { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); } }

/* ---------- chart (single series column chart, server geometry) */
.chart { margin: 0; padding: 8px 20px 16px; }
.chart-area { position: relative; height: 240px; margin-left: 44px; }
.chart-grid { position: absolute; inset: 0; list-style: none; margin: 0; padding: 0; }
.chart-grid li { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.chart-grid li:first-child { border-top-color: var(--axis); }
.chart-grid span {
  position: absolute; right: calc(100% + 8px); transform: translateY(-50%);
  font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chart-bars { position: absolute; inset: 0; display: flex; list-style: none; margin: 0; padding: 0; }
.chart-bars li { flex: 1; position: relative; }
.chart-bars a {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: flex-end;
  border-radius: 6px;
}
.chart-bars a:hover, .chart-bars a:focus-visible { background: color-mix(in srgb, var(--chart) 7%, transparent); text-decoration: none; }
.chart-bar {
  display: block; width: min(24px, 60%); background: var(--chart-muted); border-radius: 4px 4px 0 0;
  min-height: 2px; transition: background-color 120ms ease;
}
.chart-bars a:hover .chart-bar, .chart-bars a:focus-visible .chart-bar { background: var(--chart); }
.chart-bars li.is-last .chart-bar { background: var(--chart); }
.chart-cap {
  position: absolute; left: 50%; transform: translate(-50%, -6px); white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; pointer-events: none;
}
.chart-x { display: flex; margin-left: 44px; margin-top: 8px; }
.chart-x span { flex: 1; min-width: 0; text-align: center; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.chart-tip {
  position: fixed; z-index: 30; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.35; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap;
}
.chart-tip strong { display: block; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .chart-x span:nth-child(even) { visibility: hidden; } }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--hairline); vertical-align: top; }
table.data th:first-child, table.data td:first-child { padding-left: 20px; }
table.data th:last-child, table.data td:last-child { padding-right: 20px; }
table.data thead th {
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2);
  position: sticky; top: 0; white-space: nowrap;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--border); }
table.data td.num, table.data th.num { text-align: right; }
table.data td.invoices { font-size: 13px; color: var(--text-2); min-width: 120px; }
table.data td.name { min-width: 220px; }
table.data .sub { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }
table.data tr.is-hidden { display: none; }
tr.row-note td { padding-top: 0; color: var(--text-2); font-size: 13px; border-top: 0; }
.empty { padding: 32px 20px; text-align: center; color: var(--text-2); }

/* ---------- badges, callouts */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; white-space: nowrap; border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-published { background: var(--info-bg); color: var(--info-ink); }
.badge-draft { background: var(--warn-bg); color: var(--warn-ink); }
.badge-superseded, .badge-none { background: var(--surface-2); color: var(--text-2); border-color: var(--hairline); }
.badge-review { background: var(--warn-bg); color: var(--warn-ink); }
.badge-partner { background: var(--accent-soft); color: var(--info-ink); }
.callout { border-radius: var(--radius); padding: 12px 16px; font-size: 14px; border: 1px solid transparent; }
.callout-info { background: var(--info-bg); color: var(--info-ink); }
.callout-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.callout-error { background: var(--crit-bg); color: var(--crit-ink); }
.callout-ok { background: var(--info-bg); color: var(--info-ink); }
.callout strong { font-weight: 650; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.secret { font: 600 16px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .02em; user-select: all; }

/* ---------- forms & buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 550 14px var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--bad); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-link { background: none; border: 0; padding: 0; height: auto; color: var(--accent); font: inherit; cursor: pointer; }
.btn-link:hover { text-decoration: underline; background: none; }
form.inline { display: inline; margin: 0; }
label { display: block; font-size: 13px; font-weight: 550; color: var(--text-2); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search],
select, textarea {
  width: 100%; height: 38px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 15px var(--font);
}
textarea { height: auto; padding: 8px 10px; min-height: 70px; }
select.compact, input.compact { height: 32px; font-size: 14px; padding: 0 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.checkbox { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); font-weight: 450; }

/* ---------- toolbar, tabs, chips */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.toolbar input[type=search] { max-width: 280px; height: 34px; font-size: 14px; }
.bulk-bar { padding-top: 12px; padding-bottom: 4px; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--hairline); border-radius: 9px; }
.tabs button, .tabs a {
  border: 0; background: none; padding: 5px 12px; border-radius: 7px; font: 550 13px var(--font);
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs [aria-selected="true"], .tabs [aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--hairline); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--border); color: var(--text-2); background: var(--surface);
}
.chip:hover { text-decoration: none; color: var(--text); }
.chip[aria-current="page"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { font-variant-numeric: tabular-nums; opacity: .75; }

/* ---------- misc layouts */
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }
.side-layout { display: grid; gap: 24px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .side-layout { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--hairline); font-size: 14px; display: flex; justify-content: space-between; gap: 12px; }
.list-plain li:last-child { border-bottom: 0; }
.change-list { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.change-list h3 { font-size: 13px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.change-list ul { margin: 0; padding-left: 18px; font-size: 14px; }
details.disclosure > summary { cursor: pointer; font-size: 14px; color: var(--text-2); padding: 4px 0; }
details.disclosure[open] > summary { margin-bottom: 8px; }
details.row-edit > summary { list-style: none; cursor: pointer; color: var(--accent); font-size: 13px; }
details.row-edit > summary::-webkit-details-marker { display: none; }
details.row-edit[open] { position: relative; }
.row-edit-panel {
  position: absolute; right: 0; top: 24px; z-index: 5; width: 300px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.14);
  text-align: left; white-space: normal;
}
.row-edit-panel hr { border: 0; border-top: 1px solid var(--hairline); margin: 12px 0; }
.pager { display: flex; gap: 8px; align-items: center; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p.muted { margin-bottom: 20px; font-size: 14px; }
.footer { color: var(--text-3); font-size: 12px; padding: 24px 0; text-align: center; }

/* ---------- invoices with expandable items */
.inv-table tbody.inv { border-bottom: 1px solid var(--hairline); }
.inv-table tbody.inv tr td { border-bottom: 0; }
.inv-table tbody.inv:hover { background: var(--surface-2); }
.inv-table tbody.inv tr:hover { background: transparent; }
.inv-table tbody.inv.is-hidden { display: none; }
.inv-table tr.item-row td { padding-top: 2px; padding-bottom: 6px; font-size: 13px; color: var(--text-2); }
.inv-table tr.item-row td.item-name { padding-left: 12px; }
.inv-table tr.item-row:last-child td { padding-bottom: 12px; }
.expander {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 4px; margin: -2px 0 0 -4px;
  border: 0; border-radius: 6px; background: none; color: var(--accent); font: 550 14px var(--font); cursor: pointer;
}
.expander::before {
  content: ""; width: 0; height: 0; border-left: 5px solid currentColor; border-top: 4px solid transparent;
  border-bottom: 4px solid transparent; transition: transform 120ms ease;
}
.expander[aria-expanded="true"]::before { transform: rotate(90deg); }
.expander:hover { background: var(--accent-soft); }
table.data .sub.note { color: var(--info-ink); }
.pdf-link {
  display: inline-block; margin-left: 4px; padding: 0 5px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px; font-weight: 600; line-height: 16px; color: var(--text-2); vertical-align: 1px;
}
.pdf-link:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
tr.is-canceled td { color: var(--text-3); }
tr.is-canceled td:first-child { text-decoration: line-through; }
.badge-canceled { background: var(--crit-bg); color: var(--crit-ink); }
table.data tfoot tr.grand td { font-size: 15px; border-top: 1px solid var(--border); }
tr.subtle-row td { color: var(--text-3); }
.assign-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.assign-form select { width: auto; min-width: 160px; }
.assign-form input[type=month] { width: auto; }
.decide-bar { align-items: center; }
.publish-form { display: inline-flex; align-items: center; gap: 10px; }
.publish-form .checkbox { font-size: 13px; color: var(--text-2); margin: 0; }
table.recon td.decision { min-width: 260px; }
table.recon td.decision input { width: 100%; }
table.recon td.decision .badge { margin-bottom: 2px; }
.share-list li { align-items: center; }

@media (forced-colors: active) {
  .chart-bar { background: CanvasText; }
  .badge::before { background: CanvasText; }
}
@media print {
  .topbar, .actions, .toolbar, .footer { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
