/* ============ Design tokens (8px spacing system) ============ */
:root {
  /* surfaces & ink */
  --page: #f6f8fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #46506a;
  --muted: #848ea3;
  --grid: #e8ebf1;
  --baseline: #c9d0dd;
  --border: rgba(15, 23, 42, 0.08);
  --sidebar: #eef1f6;
  /* brand */
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --series-3: #eda100;
  --good: #067647;
  --bad: #d03b3b;
  --accent: #1148A0;
  --accent-2: #10B981;
  --accent-grad: linear-gradient(135deg, #1148A0 0%, #10B981 100%);
  --accent-soft: rgba(17, 72, 160, 0.10);
  --topbar-grad: linear-gradient(120deg, rgba(17,72,160,0.05), rgba(16,185,129,0.05));
  /* geometry & depth */
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-2: 0 4px 14px -3px rgba(16, 24, 40, 0.09), 0 2px 5px -2px rgba(16, 24, 40, 0.05);
  --shadow-3: 0 16px 40px -10px rgba(16, 24, 40, 0.18);
  --glass: rgba(255, 255, 255, 0.72);
  /* motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);      /* “ease-out-quint” — Apple/Linear feel */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 260ms;
}
:root[data-theme="dark"] {
  --page: #0c111b;
  --surface: #151c2a;
  --ink: #f2f5fa;
  --ink-2: #b9c3d6;
  --muted: #7d879c;
  --grid: #232c3e;
  --baseline: #34405a;
  --border: rgba(255, 255, 255, 0.08);
  --sidebar: #0B1D3A;
  --series-1: #4f9cf0;
  --series-2: #2bc98d;
  --series-3: #e0a83d;
  --good: #34d399;
  --bad: #f38c8c;
  --accent: #5aa2f2;
  --accent-2: #34D399;
  --accent-grad: linear-gradient(135deg, #3b7fd8 0%, #10B981 100%);
  --accent-soft: rgba(90, 162, 242, 0.16);
  --topbar-grad: linear-gradient(120deg, rgba(90,162,242,0.10), rgba(52,211,153,0.08));
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 6px 18px -4px rgba(0, 0, 0, 0.45), 0 2px 6px -2px rgba(0, 0, 0, 0.35);
  --shadow-3: 0 20px 48px -12px rgba(0, 0, 0, 0.6);
  --glass: rgba(21, 28, 42, 0.72);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "ss01";
  transition: background-color 300ms var(--ease), color 300ms var(--ease);
}
::selection { background: var(--accent-soft); }
/* slim, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--baseline) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }
/* accessible focus ring everywhere */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

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

/* ---- Sidebar ---- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 20px; }
.brand-mark-img {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 10px;
  box-shadow: 0 2px 10px rgba(17, 72, 160, 0.30);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 10.5px; color: var(--muted); line-height: 1.35; margin-top: 1px; }

nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; overflow: hidden;
  text-align: left;
  background: none; border: none;
  padding: 9px 10px 9px 16px; border-radius: var(--r-sm);
  font: inherit; font-size: 13.5px; color: var(--ink-2);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              padding-left 200ms var(--ease), transform 140ms var(--ease);
}
.nav-item::before {
  content: ''; position: absolute; left: 4px; top: 50%; width: 3px; height: 0;
  transform: translateY(-50%); border-radius: 2px; background: var(--accent-grad);
  transition: height 240ms var(--ease-spring);
}
.nav-item:hover { background: var(--border); color: var(--ink); padding-left: 19px; }
.nav-item:active { transform: scale(0.98); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before { height: calc(100% - 14px); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sidebar-footer { margin-top: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 10px; }
.company-switch { display: flex; flex-direction: column; gap: 4px; }
.switch-label { font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.company-switch select { width: 100%; }
.conn-actions { display: flex; flex-direction: column; gap: 6px; }
.footer-utils { display: flex; gap: 6px; }
.footer-utils .ghost-btn { flex: 1; }
.primary-btn.small { padding: 8px 12px; font-size: 12.5px; text-align: center; }
.conn { font-size: 12px; color: var(--ink-2); line-height: 1.45; }
.conn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.conn .dot.on { background: var(--good); }
.conn .dot.off { background: var(--bad); }
.conn .dot.demo { background: var(--series-3); }
.conn .dot.warn { background: var(--series-3); }
.conn-warn { display: block; margin-top: 4px; color: var(--series-3); }

/* Connections panel (Connect view) */
.conn-panel h3 { margin: 0 0 6px; font-size: 15px; }
.conn-panel .hint { margin: 0 0 14px; }
.conn-table td { vertical-align: top; }
.conn-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.conn-sub.err { color: var(--bad); max-width: 34rem; }
.conn-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; }
.conn-badge.live { color: var(--good); background: rgba(6, 118, 71, 0.12); }
.conn-badge.warn, .conn-badge.unlinked { color: var(--series-3); background: rgba(237, 161, 0, 0.14); }
.conn-badge.expired { color: var(--bad); background: rgba(208, 59, 59, 0.12); }
.conn-actions-cell { white-space: nowrap; }
.conn-actions-cell button { margin: 0 0 4px 4px; }
.ghost-btn.small { padding: 6px 10px; font-size: 12px; }
.ghost-btn.danger { color: var(--bad); border-color: rgba(208, 59, 59, 0.35); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
        color: var(--accent); background: var(--accent-soft); vertical-align: middle; }
.mono { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-2); }
.warn-text { color: var(--series-3); }
.connect-steps { margin: 4px 0 18px; padding-left: 20px; color: var(--ink-2); font-size: 13.5px; line-height: 1.7; }
/* Inline action inside a banner ("Reconnect QuickBooks") */
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 700;
            color: inherit; text-decoration: underline; cursor: pointer; }
.banner-detail { display: block; margin-top: 4px; font-size: 12px; opacity: 0.85; }
.conn a { color: var(--accent); }
.ghost-btn {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 12px; font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--ink-2); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform 140ms var(--ease), box-shadow var(--dur) var(--ease);
}
.ghost-btn:hover { border-color: var(--baseline); color: var(--ink); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.ghost-btn:active { transform: translateY(0) scale(0.97); }

/* ---- Main ---- */
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; max-width: 1160px; }
.topbar {
  position: sticky; top: 12px; z-index: 40;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  margin-bottom: 20px; flex-wrap: wrap;
  padding: 14px 18px; border-radius: var(--r-lg);
  background: var(--glass); border: 1px solid var(--border);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  transition: box-shadow 300ms var(--ease);
}
body.scrolled .topbar { box-shadow: var(--shadow-2); }
h1 {
  font-size: 22px; font-weight: 700; margin: 0 0 2px; letter-spacing: -0.02em;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--accent);
}
.company-line { margin: 0; font-size: 12.5px; color: var(--muted); }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 30px 8px 12px; font: inherit; font-size: 13px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23848ea3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
select:hover { border-color: var(--baseline); }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.banner {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--series-3);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 16px;
}
.banner a { color: var(--accent); }
.banner.error { border-left-color: var(--bad); }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 16px 18px 16px 20px;
  box-shadow: var(--shadow-1);
  transition: transform 220ms var(--ease-spring), box-shadow 220ms var(--ease), border-color 220ms var(--ease);
}
.tile::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--tile-c, var(--accent));
  transition: width 220ms var(--ease);
}
.tile::after {
  /* soft top-corner glow tinted by the tile accent */
  content: ''; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px;
  border-radius: 50%; background: var(--tile-c, var(--accent)); opacity: 0.07;
  filter: blur(18px); pointer-events: none;
  transition: opacity 220ms var(--ease);
}
.tile:hover { transform: translateY(-3px) scale(1.015); box-shadow: var(--shadow-2); border-color: var(--baseline); }
.tile:hover::before { width: 6px; }
.tile:hover::after { opacity: 0.14; }
.tile:active { transform: translateY(-1px) scale(0.995); }
.kpis .tile:nth-child(4n+1) { --tile-c: var(--series-1); }
.kpis .tile:nth-child(4n+2) { --tile-c: var(--series-2); }
.kpis .tile:nth-child(4n+3) { --tile-c: var(--series-3); }
.kpis .tile:nth-child(4n)   { --tile-c: var(--accent-2); }
.tile .label { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.tile .value { font-size: 23px; font-weight: 650; letter-spacing: -0.01em; }
.tile .sub { display: flex; gap: 8px; align-items: baseline; margin-top: 6px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.delta { font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---- Cards & charts ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px 20px 16px; margin-bottom: 16px;
  box-shadow: var(--shadow-1);
  transition: box-shadow 260ms var(--ease), border-color 260ms var(--ease), transform 260ms var(--ease);
}
.card:hover { box-shadow: var(--shadow-2); border-color: var(--baseline); }
.card h2 { position: relative; font-size: 14px; font-weight: 600; margin: 0 0 2px; padding-left: 12px; }
.card h2::before {
  content: ''; position: absolute; left: 0; top: 1px; bottom: 1px; width: 3px;
  border-radius: 2px; background: var(--accent-grad);
}
.card .desc { padding-left: 12px; }
.card .desc { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.chart-box { position: relative; height: 280px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 12px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin: 0 0 0 auto; }
}

/* ---- Statement table ---- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child {
  text-align: left; font-variant-numeric: normal; white-space: normal;
  min-width: 220px; position: sticky; left: 0; background: var(--surface);
}
thead th { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--baseline); }
tbody tr { border-bottom: 1px solid var(--grid); }
tr.kind-section td { font-weight: 600; padding-top: 14px; }
tr.kind-summary td { font-weight: 600; border-top: 1px solid var(--baseline); }
tr.kind-data td:first-child { color: var(--ink-2); }
td.neg { color: var(--bad); }

.pagefoot { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---- Connect screen ---- */
.connect-card { max-width: 560px; padding: 28px; }
.connect-card p { color: var(--ink-2); line-height: 1.55; }
.connect-card code { background: var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.primary-btn {
  display: inline-block; background: var(--accent-grad); color: #fff;
  border: none; cursor: pointer;
  border-radius: 8px; padding: 11px 18px; font-weight: 600; text-decoration: none; margin: 10px 0;
  box-shadow: 0 2px 10px rgba(42, 120, 214, 0.3);
}
.primary-btn:hover { filter: brightness(1.08); }
.hint { font-size: 12.5px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Card header with actions ---- */
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 10px; align-items: center; }
.kpi-counts { font-size: 12px; color: var(--ink-2); display: inline-flex; gap: 10px; }
.kpi-counts .pill { display: inline-flex; align-items: center; gap: 5px; }
.kpi-counts .pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.kpi-counts .pill.ok::before { background: var(--good); }
.kpi-counts .pill.bad::before { background: var(--bad); }
.footnote { font-size: 11.5px; color: var(--muted); margin: 12px 0 0; }
.loading { font-size: 13px; color: var(--muted); padding: 8px 2px; }

/* ---- KPI table ---- */
.kpi-table td, .kpi-table th { padding: 9px 12px; }
.kpi-table td:first-child { min-width: 240px; }
tr.kpi-group td {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink); background: var(--page); padding-top: 12px;
}
.group-chip {
  display: inline-flex; width: 18px; height: 18px; border-radius: 4px; color: #fff;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  margin-right: 8px; vertical-align: middle;
}
.status-ok { color: var(--good); font-weight: 700; }
.status-bad { color: var(--bad); font-weight: 700; }
.trend-up { color: var(--good); }
.trend-down { color: var(--bad); }
.importance { font-size: 12px; color: var(--ink-2); }
.kpi-table input.target-input {
  width: 110px; background: var(--page); color: var(--ink);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 7px;
  font: inherit; font-size: 12.5px; text-align: right;
}

/* ---- Financials (Fathom-style) table ---- */
.fin-table td, .fin-table th { padding: 8px 12px; }
.var-good { color: var(--good); }
.var-bad { color: var(--bad); }
.donut-cell { display: inline-flex; align-items: center; gap: 7px; justify-content: flex-end; }
.donut-cell svg { flex-shrink: 0; }
.donut-cell .donut-pct { color: var(--ink-2); font-size: 12px; min-width: 34px; text-align: right; }
tr.kind-grand td { font-weight: 700; border-top: 2px solid var(--baseline); }

/* ---- Analysis ---- */
.chart-box.tall { height: 320px; }
.insights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.insights li {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--page); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; line-height: 1.5; color: var(--ink-2);
}
.insights li strong { color: var(--ink); }
.insights .ins-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.insights .ins-dot.good { background: var(--good); }
.insights .ins-dot.bad { background: var(--bad); }
.insights .ins-dot.info { background: var(--series-1); }

/* ---- Goalseek ---- */
.gs-goal-input { width: 72px; background: var(--page); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font: inherit; font-size: 13px; text-align: right; }
.gs-progress { display: flex; align-items: center; gap: 12px; margin: 6px 0 22px; }
.gs-progress .gs-start, .gs-progress .gs-goal-lbl { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.gs-bar { flex: 1; height: 10px; border-radius: 6px; background: repeating-linear-gradient(45deg, var(--grid), var(--grid) 4px, transparent 4px, transparent 8px); border: 1px solid var(--border); overflow: hidden; }
.gs-bar-fill { height: 100%; background: var(--series-2); border-radius: 6px; }
.gs-group { margin-bottom: 22px; }
.gs-group-title { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); text-align: center; margin-bottom: 4px; }
.gs-axis { position: relative; height: 16px; margin-left: 300px; border-bottom: 1px solid var(--grid); }
.gs-axis span { position: absolute; transform: translateX(-50%); font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gs-row { display: grid; grid-template-columns: 150px 90px 60px 1fr; align-items: center; gap: 0; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.gs-row .gs-name { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.gs-row .gs-name .swatch { width: 9px; height: 9px; border-radius: 2px; }
.gs-row .gs-achieve { font-size: 13px; font-weight: 650; text-align: right; padding-right: 20px; font-variant-numeric: tabular-nums; }
.gs-row .gs-change { font-size: 12px; color: var(--muted); text-align: right; padding-right: 20px; }
.gs-track { position: relative; height: 22px; }
.gs-track .gs-zero { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--baseline); }
.gs-track .gs-fill { position: absolute; top: 9px; height: 4px; border-radius: 2px; opacity: 0.5; }
.gs-track .gs-marker { position: absolute; top: 4px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); transform: translateX(-50%); }
.gs-track .gs-cap { position: absolute; top: 4px; width: 3px; height: 14px; border-radius: 2px; }
@media (max-width: 760px) {
  .gs-axis { margin-left: 0; }
  .gs-row { grid-template-columns: 110px 70px 44px 1fr; }
}

/* ---- Classification modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 620px; max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 10px; }
.modal-head h2 { position: relative; padding-left: 12px; font-size: 16px; margin: 0 0 2px; }
.modal-head h2::before { content: ''; position: absolute; left: 0; top: 1px; bottom: 1px; width: 3px; border-radius: 2px; background: var(--accent-grad); }
.modal-head .desc { padding-left: 12px; margin: 0; max-width: 460px; }
.class-list { overflow-y: auto; padding: 4px 20px; flex: 1; }
.class-group-title { font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.class-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.class-row .cr-name { font-size: 13px; color: var(--ink); display: flex; flex-direction: column; gap: 2px; }
.class-row .cr-val { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.seg button { background: none; border: none; padding: 6px 12px; font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active[data-tag="variable"] { background: var(--bad); color: #fff; }
.seg button.active[data-tag="fixed"] { background: var(--ink); color: var(--surface); }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot-btns { display: flex; gap: 8px; }
.class-summary { font-size: 12px; color: var(--ink-2); }

/* ---- KPI Explorer ---- */
.kpix-wrap { display: flex; justify-content: center; padding: 8px 0 4px; overflow-x: auto; }
.kpix-wrap svg { max-width: 100%; height: auto; }

/* ---- Profitability / breakeven ---- */
.prof-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 900px) { .prof-grid { grid-template-columns: 1fr; } }
.prof-formula {
  display: flex; align-items: stretch; justify-content: center; gap: 0;
  border: 1px solid var(--border); border-radius: 10px; overflow: visible;
  margin: 4px 0 16px; position: relative;
}
.prof-formula .pf-cell { flex: 1; text-align: center; padding: 10px 12px; }
.prof-formula .pf-cell + .pf-cell { border-left: 1px solid var(--border); }
.prof-formula .pf-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-2); margin-bottom: 4px; }
.prof-formula .pf-value { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.prof-formula .pf-op {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 15px; z-index: 2;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.prof-formula .pf-op.minus { left: 33.33%; background: var(--bad); }
.prof-formula .pf-op.equals { left: 66.66%; background: var(--muted); }
.prof-panel { display: flex; flex-direction: column; }
.prof-row { display: flex; justify-content: space-between; align-items: baseline; padding: 11px 2px; border-bottom: 1px solid var(--grid); gap: 12px; }
.prof-row:last-child { border-bottom: none; }
.prof-row .pr-label { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.prof-row .pr-label .swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.prof-row .pr-value { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.prof-row .pr-sub { font-size: 11px; color: var(--muted); }

/* ---- Cash flow waterfall ---- */
#cf-box { height: 520px; }

/* ---- Charts view ---- */
.charts-controls { flex-wrap: wrap; }
.charts-controls .chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.charts-controls .chk input { accent-color: var(--accent); }
.year-tabs { display: flex; gap: 4px; justify-content: flex-end; margin-bottom: 8px; flex-wrap: wrap; }
.year-tabs button {
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 4px 10px; font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.year-tabs button:hover { color: var(--ink); background: var(--border); }
.year-tabs button.active { color: var(--ink); font-weight: 600; border-color: var(--border); background: var(--surface); }

/* ---- Growth view ---- */
.growth-box { height: 460px; }
.growth-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 12px; }
.growth-legend .q {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 12px; color: var(--ink-2);
}
.growth-legend .q b { display: block; color: var(--ink); font-size: 12.5px; margin-bottom: 2px; }
.growth-legend .q .qtag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---- Management report ---- */
.report-section { margin-bottom: 12px; }
.report-cover {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 28px; margin-bottom: 12px;
}
.report-cover .rc-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
}
.report-cover h2 { font-size: 24px; font-weight: 650; margin: 0 0 4px; letter-spacing: -0.01em; }
.report-cover .rc-meta { font-size: 13px; color: var(--ink-2); }
.report-section h3 {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 10px;
}

/* ---- Sticky table headers ---- */
.table-scroll { max-height: 72vh; overflow: auto; }
thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; }
th:first-child { z-index: 3; }

/* ---- Sign-in overlay ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 14, 24, 0.6);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  display: flex; align-items: center; justify-content: center;
}
.login-overlay[hidden] { display: none; }
.login-card {
  width: min(400px, calc(100vw - 40px));
  background: #131c2b; color: #f2f5fa;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px; padding: 26px 26px 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 14px;
}
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-head img { border-radius: 10px; }
.login-card h2 { margin: 0; font-size: 20px; font-weight: 650; }
.login-sub { font-size: 12px; color: #9fb0c8; margin-top: 2px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: #c6d2e2; }
.login-field input {
  background: rgba(255, 255, 255, 0.06); color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.18); border-radius: 10px;
  padding: 10px 12px; font: inherit; font-size: 14px;
}
.login-field input:focus { outline: none; border-color: #34D399; box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.22); }
.login-error { color: #ff9d9d; font-size: 12.5px; }
.login-btn { margin: 6px 0 0; width: 100%; text-align: center; font-size: 14px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 14px; border-radius: 10px; cursor: pointer;
  background: #fff; color: #1f2937; border: 1px solid rgba(0,0,0,0.15);
  font: inherit; font-size: 14px; font-weight: 600;
  transition: transform 140ms var(--ease), box-shadow var(--dur) var(--ease);
}
.google-btn:hover { box-shadow: 0 3px 12px rgba(0,0,0,0.18); transform: translateY(-1px); }
.google-btn:active { transform: scale(0.98); }
.login-or { display: flex; align-items: center; gap: 10px; color: #8391a8; font-size: 11px; }
.login-or::before, .login-or::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.12); }
.login-switch { text-align: center; font-size: 12.5px; color: #9fb0c8; margin-top: 4px; }
.linkish { background: none; border: none; color: #6cc6ff; font: inherit; font-weight: 600; cursor: pointer; padding: 0 0 0 4px; }
.linkish:hover { text-decoration: underline; }
.connect-popup .connect-popup-body { font-size: 13.5px; color: #c6d2e2; line-height: 1.55; margin: 2px 0 6px; }
.connect-popup .ghost-btn { color: #c6d2e2; background: transparent; border-color: rgba(255,255,255,0.18); }

/* Impersonation banner */
.impersonate-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 350;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(90deg, #b45309, #d97706); color: #fff;
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-2);
}
.impersonate-bar[hidden] { display: none; }
.impersonate-bar .ghost-btn { background: rgba(255,255,255,0.16); color: #fff; border-color: rgba(255,255,255,0.4); }
body.impersonating { padding-top: 38px; }

/* Manage Users table */
.provider-pill, .role-pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.provider-pill.google { background: rgba(66,133,244,0.14); color: #4285F4; }
.provider-pill.local { background: var(--accent-soft); color: var(--accent); }
.role-pill.admin { background: rgba(217,119,6,0.15); color: #b45309; }
.role-pill.user { background: var(--grid); color: var(--ink-2); }
.role-pill.accountant { background: rgba(37,99,235,0.15); color: #1d4ed8; }
.role-pill.viewer { background: var(--grid); color: var(--ink-2); }

/* Admin: create-account form above the user table */
.new-user-form { border: 1px solid var(--grid); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.new-user-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.new-user-form .login-field { margin: 0; }
.new-user-form select, .role-select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--grid); border-radius: 8px;
  background: var(--card); color: var(--ink); font: inherit;
}
.role-select { width: auto; min-width: 130px; padding: 5px 8px; }
.new-user-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.new-user-actions .login-error { margin: 0; }

/* Role badge under the brand */
.brand-role { display: inline-block; margin-top: 6px; }

/* Read-only accounts: neutralise editable cells the server would reject */
body.role-readonly [contenteditable="true"] { pointer-events: none; opacity: 0.75; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.user-actions .ghost-btn { padding: 5px 10px; font-size: 12px; }
.user-actions .danger { color: var(--bad); border-color: rgba(208,59,59,0.4); }

/* ============ Motion system ============ */

/* Page transitions: each view fades + rises in; children stagger */
@keyframes viewRise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.view-enter { animation: viewRise 320ms var(--ease) both; }
.view-enter > .card, .view-enter > .grid2 > .card, .view-enter .kpis > .tile,
.view-enter > .prof-grid > .card, .view-enter #report-body > * {
  animation: viewRise 380ms var(--ease) both;
}
.view-enter > *:nth-child(1), .view-enter .kpis > .tile:nth-child(1) { animation-delay: 30ms; }
.view-enter > *:nth-child(2), .view-enter .kpis > .tile:nth-child(2) { animation-delay: 80ms; }
.view-enter > *:nth-child(3), .view-enter .kpis > .tile:nth-child(3) { animation-delay: 130ms; }
.view-enter > *:nth-child(4), .view-enter .kpis > .tile:nth-child(4) { animation-delay: 180ms; }
.view-enter > *:nth-child(n+5) { animation-delay: 220ms; }

/* Button ripple (element injected by JS on pointerdown) */
.ripple {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: currentColor; opacity: 0.18; transform: scale(0);
  animation: rippleGo 480ms var(--ease) forwards;
}
@keyframes rippleGo { to { transform: scale(2.6); opacity: 0; } }
.primary-btn { position: relative; overflow: hidden; transition: transform 140ms var(--ease), box-shadow var(--dur) var(--ease), filter var(--dur) var(--ease); }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35); }
.primary-btn:active { transform: scale(0.97); }

/* Top loading bar (replaces the plain “Loading…” text) */
.loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 300;
  background: transparent; pointer-events: none; opacity: 0; transition: opacity 200ms var(--ease);
}
body.is-loading .loadbar { opacity: 1; }
.loadbar::before {
  content: ''; position: absolute; inset: 0; width: 40%;
  background: var(--accent-grad); border-radius: 3px;
  animation: loadSlide 1.1s var(--ease) infinite;
}
@keyframes loadSlide {
  from { transform: translateX(-110%); }
  to   { transform: translateX(280%); }
}
.loading { display: none; }

/* Toasts */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); color: var(--ink);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 11px 16px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-3);
  animation: toastIn 320ms var(--ease-spring) both;
}
.toast.leaving { animation: toastOut 260ms var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(0.97); } }
.toast .t-check {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  background: var(--good); display: flex; align-items: center; justify-content: center;
}
.toast .t-check svg path {
  stroke-dasharray: 20; stroke-dashoffset: 20;
  animation: drawCheck 400ms 120ms var(--ease) forwards;
}
@keyframes drawCheck { to { stroke-dashoffset: 0; } }

/* Tables: calm rows that light up on hover */
tbody tr { transition: background-color 160ms var(--ease); }
tbody tr:hover td { background: var(--accent-soft); }
tbody tr:hover td:first-child { background: var(--accent-soft); }

/* KPI Explorer: ring sweep, square pop-in, hover expansion */
.kpix-sq { transform-box: fill-box; transform-origin: center; cursor: default;
  animation: kpixPop 420ms var(--ease-spring) both; animation-delay: var(--d, 0ms); }
.kpix-sq:hover { transform: scale(1.22); filter: drop-shadow(0 3px 8px rgba(0,0,0,0.25)); }
@keyframes kpixPop { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: scale(1); } }
.kpix-ring { transition: stroke-dasharray 900ms var(--ease); }
.kpix-wrap svg text { animation: viewRise 500ms var(--ease) both; }

/* Chart canvases are always fully visible (no opacity animation that could
   leave a canvas stuck invisible if the animation is interrupted). */
.chart-box canvas, .growth-box canvas, #cf-box canvas { opacity: 1 !important; }

/* Respect reduced motion: kill every animation & transition */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Responsive refinements */
@media (max-width: 900px) {
  .topbar { position: static; }
  .main { padding: 16px 14px 40px; }
}

/* ---- Print / PDF export ---- */
.print-header { display: none; }
@media print {
  @page { margin: 14mm 12mm; }
  body { background: #fff; color: #000; font-size: 11px; }
  .sidebar, .controls, .banner, .loading, #edit-targets, .pagefoot { display: none !important; }
  .table-scroll { max-height: none; overflow: visible; }
  thead th { position: static; }
  .report-section { break-inside: auto; }
  .report-section h3 { break-after: avoid; }
  .report-cover { border: none; padding: 0 0 12px; }
  .report-break { break-before: page; }
  .app { display: block; }
  .main { max-width: none; padding: 0; }
  .topbar { display: none; }
  .print-header {
    display: flex; justify-content: space-between; align-items: baseline;
    border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 16px; gap: 16px;
  }
  .ph-brand { font-weight: 700; font-size: 14px; }
  .ph-title { font-weight: 650; font-size: 16px; }
  .ph-meta { font-size: 10.5px; color: #444; text-align: right; }
  .card { border: none; padding: 0; margin-bottom: 18px; box-shadow: none; }
  .card h2 { font-size: 13px; }
  .table-scroll { overflow: visible; }
  table { font-size: 10.5px; }
  th:first-child, td:first-child { position: static; }
  tr { break-inside: avoid; }
  .chart-box { height: 240px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .grid2 { grid-template-columns: 1fr 1fr; }
}

/* Connect view: the exact OAuth settings, so a redirect_uri mismatch is visible */
.conn-config { display: grid; gap: 12px; margin: 16px 0 6px; padding: 14px 16px;
               background: var(--sidebar); border: 1px solid var(--border); border-radius: var(--r-md); }
.conn-config-key { display: block; font-size: 11px; font-weight: 700; letter-spacing: .04em;
                   text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.conn-uri { display: inline-block; font-size: 12.5px; padding: 4px 8px; border-radius: var(--r-sm);
            background: var(--surface); border: 1px solid var(--border); word-break: break-all; }
.conn-blocked { margin: 14px 0 0; padding: 12px 14px; border-radius: var(--r-md); font-size: 13px; line-height: 1.6;
                color: var(--bad); background: rgba(208, 59, 59, 0.10); border: 1px solid rgba(208, 59, 59, 0.30); }
