/* Business HQ — local dashboard. Light + dark, no dependencies. */

/* {{BRAND_TOKENS_START}} */
:root {
  --brand: #1b4b8a;
  --brand-accent: #f5862b;
  --brand-dark: #0d1b2e;
  --font-heading: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
}
/* {{BRAND_TOKENS_END}} */

:root {
  color-scheme: light;
  /* Surfaces carry a hint of the brand color (plain fallbacks first) */
  --bg: #f4f6f9;
  --bg: color-mix(in srgb, var(--brand) 4%, #f5f6f8);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-2: color-mix(in srgb, var(--brand) 3%, #f8fafc);
  --ink: #17202e;
  --ink-2: #5a6577;
  --ink-3: #8b95a7;
  --line: rgba(20, 35, 60, 0.1);
  --shadow: 0 4px 16px rgba(13, 27, 46, 0.06);
  /* chart series (validated, dataviz reference palette) */
  --money-in: #1baf7a;
  --money-out: #eb6834;
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4; --s8: #eb6834;
  --good: #2e9e5b;
  --warn: #d97706;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    /* Dark surfaces are derived from the client's brand-dark color */
    --bg: #10151d;
    --bg: color-mix(in srgb, var(--brand-dark) 35%, #0e1116);
    --surface: #1a212c;
    --surface: color-mix(in srgb, var(--brand-dark) 42%, #171c24);
    --surface-2: #151b25;
    --surface-2: color-mix(in srgb, var(--brand-dark) 38%, #12161d);
    --ink: #eef2f7;
    --ink-2: #a8b2c2;
    --ink-3: #748092;
    --line: rgba(255, 255, 255, 0.09);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    --money-in: #199e70;
    --money-out: #d95926;
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181; --s8: #d95926;
    --good: #3fbf74;
    /* Lighter amber: the light-mode --warn is too dark to read on dark surfaces */
    --warn: #f0a338;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
}
h1, h2, h3 { font-family: var(--font-heading); letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; font-weight: 600; }
button { font: inherit; cursor: pointer; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0.1em 0.4em; font-size: 0.85em; }
.muted { color: var(--ink-2); font-size: 0.88rem; }
.pad-x { padding: 0 1.4rem; }
.pad-b { padding-bottom: 1.2rem; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.side {
  width: 250px; flex: 0 0 auto;
  background: var(--brand-dark);
  background: linear-gradient(180deg, var(--brand-dark), color-mix(in srgb, var(--brand-dark) 78%, var(--brand)));
  color: rgba(255, 255, 255, 0.85);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; gap: 0.75rem; align-items: center; padding: 1.4rem 1.3rem 1.2rem; }
.side-logo {
  width: 42px; height: 42px; border-radius: 11px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-weight: 800; color: #fff; font-size: 0.95rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-accent));
}
.side-logo-img {
  width: 42px; height: 42px; border-radius: 11px; flex: 0 0 auto;
  object-fit: contain; background: rgba(255, 255, 255, 0.08);
}
/* [hidden] must beat the explicit display on these two */
.side-logo[hidden], .side-logo-img[hidden] { display: none !important; }
.side-brand strong { display: block; color: #fff; font-family: var(--font-heading); font-size: 0.98rem; line-height: 1.25; }
.side-brand span { font-size: 0.75rem; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.08em; }
.side-nav { display: grid; gap: 2px; padding: 0.6rem; }
.side-link {
  display: flex; align-items: center; gap: 0.6rem;
  background: none; border: 0; border-radius: 9px;
  color: rgba(255, 255, 255, 0.78); text-align: left;
  padding: 0.62rem 0.85rem; font-size: 0.92rem; font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.side-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.side-link.active {
  background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 var(--brand-accent);
}
.side-foot { margin-top: auto; padding: 1.1rem 1.3rem; font-size: 0.75rem; opacity: 0.65; display: grid; gap: 0.4rem; }
/* A warning at 65% opacity isn't a warning — let it through at full strength */
.side-foot .side-warn { color: var(--warn); opacity: 1; font-weight: 600; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 1.6rem 2rem 3rem; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.topbar h1 { font-size: 1.45rem; font-weight: 700; position: relative; padding-bottom: 6px; }
.topbar h1::after {
  content: ""; position: absolute; left: 0; bottom: 0;
  width: 34px; height: 3.5px; border-radius: 2px;
  background: var(--brand-accent);
}

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.seg-btn {
  border: 0; background: none; border-radius: 999px;
  padding: 0.38rem 0.95rem; font-size: 0.85rem; font-weight: 500; color: var(--ink-2);
  transition: background 0.2s, color 0.2s;
}
.seg-btn.active { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------- Tabs ---------- */
.tab { display: none; }
.tab.active { display: block; animation: fadeUp 0.35s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow);
}
.tile-label { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); display: flex; align-items: center; gap: 0.45rem; }
.tile-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.tile-value { font-family: var(--font-heading); font-weight: 700; font-size: 1.65rem; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 0.8rem; color: var(--ink-2); margin-top: 0.15rem; }

/* ---------- Cards & grids ---------- */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; margin-bottom: 1.2rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 1.2rem;
}
.grid-2 .card { margin-bottom: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.1rem 1.4rem 0.8rem; flex-wrap: wrap;
}
.chart { padding: 0.4rem 1rem 1rem; }
.chart svg { display: block; width: 100%; height: auto; }

/* ---------- Legend ---------- */
.legend { display: flex; gap: 1rem; font-size: 0.82rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Donut ---------- */
.donut-wrap { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem; align-items: center; padding: 0.2rem 1.2rem 1.2rem; }
.chart-donut { padding: 0; }
.donut-legend { display: grid; gap: 0.4rem; font-size: 0.85rem; }
.donut-legend .row { display: flex; align-items: center; gap: 0.5rem; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.donut-legend .row span:last-child { margin-left: auto; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-2); font-weight: 600; padding: 0.7rem 1.4rem; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap;
}
td { padding: 0.65rem 1.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-in { color: var(--good); font-weight: 600; }
.amt-out { color: var(--ink); font-weight: 600; }
.pill {
  display: inline-block; font-size: 0.75rem; font-weight: 600;
  padding: 0.12rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
  white-space: nowrap;
}

/* ---------- Lists ---------- */
.list-row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.75rem 1.4rem; border-top: 1px solid var(--line); font-size: 0.9rem;
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; }
.list-row .sub { color: var(--ink-2); font-size: 0.8rem; }
.list-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
  background: var(--surface-2); border: 1px solid var(--line);
}
.list-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.group-head { padding: 0.9rem 1.4rem 0.3rem; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.filters input[type="search"] {
  font: inherit; font-size: 0.88rem;
  padding: 0.45rem 0.9rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--ink); min-width: 220px;
}
.filters input[type="search"]:focus { outline: 2px solid var(--brand); outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); }

/* ---------- Empty state ---------- */
.empty-state {
  background: var(--surface); border: 1px dashed var(--line); border-radius: 14px;
  padding: 3.5rem 2rem; text-align: center; margin-bottom: 1.2rem;
}
.empty-state p { color: var(--ink-2); margin-top: 0.5rem; }
.empty-inline { padding: 1.6rem 1.4rem; color: var(--ink-2); font-size: 0.9rem; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--bg);
  font-size: 0.8rem; font-weight: 500; line-height: 1.4;
  padding: 0.45rem 0.7rem; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 240px;
}
.tooltip strong { display: block; }

/* ---------- Meter (tax set-aside) ---------- */
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin-top: 0.5rem; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side-nav { display: flex; overflow-x: auto; padding: 0 0.6rem 0.8rem; }
  .side-link { white-space: nowrap; }
  .side-foot { display: none; }
  .main { padding: 1.2rem 1rem 3rem; }
}
