/* Analytics screens (profitability, operations, CFO). Everything is scoped under .an-root and reuses the
   design tokens of base.css, so light/dark follows the app's data-theme. */
.an-root {
  --hair: var(--line);
  --ring: var(--line);
  --page: var(--bg);
  --bad: var(--crit);
  --bad-ink: var(--crit-text);
  --bad-wash: var(--crit-soft);
  --warn-ink: var(--warn-text);
  --warn-wash: var(--warn-soft);
  --good-ink: var(--good-text);
  --accent-wash: var(--accent-soft);
  color: var(--ink);
  font: 13px/1.45 var(--font-ui);
}
.an-root *, .an-root *::before, .an-root *::after { box-sizing: border-box; }
.an-root button, .an-root input, .an-root select { font: inherit; color: inherit; }
.an-root :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.an-root .an-offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

/* toolbar: period line, filters, tab strip (sits under the app topbar, inside <main>) */
.an-root .an-bar { margin: -12px -14px 14px; padding: 10px 14px 0; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 94%, transparent); }
@media (min-width: 900px) and (min-height: 640px) {
  .an-root .an-bar { position: sticky; top: 0; z-index: 6; backdrop-filter: blur(8px); }
}
.an-root .an-subline { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.an-root .an-sub { color: var(--muted); font-size: 12px; }
.an-root .an-filters { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 8px; }
.an-root .an-fgroup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.an-root .an-flabel { font: 600 10.5px/1 var(--font-head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.an-root .an-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.an-root .an-chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; line-height: 1.3; }
.an-root .an-chip:hover { border-color: var(--accent-line); }
.an-root .an-chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.an-root .an-toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; user-select: none; }
.an-root .an-toggle input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.an-root .an-tabs { display: flex; gap: 2px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.an-root .an-tabs::-webkit-scrollbar { display: none; }
@media (min-width: 761px) { .an-root .an-tabs { flex-wrap: wrap; overflow-x: visible; } }
.an-root .an-tab { padding: 8px 12px 10px; font: 500 13px/1 var(--font-ui); color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.an-root .an-tab:hover { color: var(--ink); }
.an-root .an-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.an-root .an-tab .n { font: 500 11px var(--font-head); color: var(--muted); margin-left: 4px; }
.an-root .an-tabsep { align-self: center; font: 600 10px var(--font-head); letter-spacing: .1em; color: var(--accent); border-left: 1px solid var(--line); padding: 0 6px 0 12px; margin-left: 6px; }

/* layout */
.an-root .an-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.an-root .an-c12 { grid-column: span 12; } .an-root .an-c8 { grid-column: span 8; } .an-root .an-c7 { grid-column: span 7; }
.an-root .an-c6 { grid-column: span 6; } .an-root .an-c5 { grid-column: span 5; } .an-root .an-c4 { grid-column: span 4; }
@media (max-width: 1100px) { .an-root .an-c8, .an-root .an-c7, .an-root .an-c6, .an-root .an-c5, .an-root .an-c4 { grid-column: span 12; } }
.an-root .an-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.an-root .an-card > h2 { font: 600 12.5px/1.2 var(--font-head); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 2px; }
.an-root .an-note { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.an-root .an-mt6 { margin-top: 6px; } .an-root .an-mt8 { margin-top: 8px; } .an-root .an-mt10 { margin-top: 10px; }
.an-root .an-mt12 { margin-top: 12px; } .an-root .an-mt14 { margin-top: 14px; } .an-root .an-mt16 { margin-top: 16px; }
.an-root .an-mb6 { margin-bottom: 6px; } .an-root .an-mb8 { margin-bottom: 8px; }
.an-root .an-loading { color: var(--muted); }
.an-root .an-empty { color: var(--muted); padding: 24px; text-align: center; }
.an-root .an-empty .btn { margin-left: 6px; }
.an-root .an-empty-state { max-width: 640px; margin: 24px auto; padding: 24px 26px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.an-root .an-empty-state h2 { font: 600 17px/1.25 var(--font-head); letter-spacing: 0; text-transform: none; color: var(--ink); margin: 0; }
.an-root .an-empty-state p { margin: 0; color: var(--ink-2); max-width: 60ch; }
.an-root .an-empty-state .an-sub { font-size: 11.5px; }
.an-root .an-empty-state.error h2 { color: var(--crit-text); }

/* hero + tiles */
.an-root .an-hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr); gap: 14px; }
@media (max-width: 1100px) { .an-root .an-hero { grid-template-columns: 1fr; } }
.an-root .an-herocard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 18px 20px; display: flex; flex-direction: column; justify-content: space-between; gap: 14px; }
.an-root .an-herolabel { font: 600 11.5px var(--font-head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.an-root .an-herofig { font: 600 44px/1 var(--font-ui); letter-spacing: -.02em; margin-top: 4px; }
.an-root .an-herosub { color: var(--ink-2); font-size: 13.5px; margin-top: 8px; }
.an-root .an-herosub b { font-weight: 600; color: var(--ink); }
.an-root .an-bar100 { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); }
.an-root .an-bar100.thick { height: 14px; border-radius: 4px; }
.an-root .an-bar100 i { display: block; height: 100%; }
.an-root .an-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.an-root .an-legend span { display: inline-flex; align-items: center; gap: 6px; }
.an-root .an-sw, .an-root .an-tip .an-sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.an-root .an-swl, .an-root .an-tip .an-swl { width: 14px; height: 2px; border-radius: 1px; display: inline-block; flex: none; }
.an-root .an-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.an-root .an-card .an-tiles { margin-top: 8px; }
/* a row the tiles do not fill: its last tile takes the rest of the row, so no grey gap shows through; five tiles are one row of five */
.an-root .an-tiles > :last-child:nth-child(4n+1) { grid-column: span 4; }
.an-root .an-tiles > :last-child:nth-child(4n+2) { grid-column: span 3; }
.an-root .an-tiles > :last-child:nth-child(4n+3) { grid-column: span 2; }
@media (min-width: 1100px) {
  .an-root .an-tiles:has(> :nth-child(5):last-child) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .an-root .an-tiles:has(> :nth-child(5):last-child) > :last-child { grid-column: auto; }
}
@media (max-width: 760px) {
  .an-root .an-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-root .an-tiles > :last-child:nth-child(n) { grid-column: auto; }
  .an-root .an-tiles > :last-child:nth-child(odd) { grid-column: span 2; }
}
.an-root .an-tile { background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.an-root .an-tile .l { font-size: 12px; color: var(--ink-2); }
.an-root .an-tile .v { font: 600 21px/1.15 var(--font-ui); letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.an-root .an-tile .d { font-size: 11.5px; color: var(--muted); }

/* attention chips */
.an-root .an-alerts { display: flex; flex-wrap: wrap; gap: 8px; }
.an-root .an-alert { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); flex: 1 1 220px; cursor: pointer; text-align: left; }
.an-root .an-alert:hover { border-color: var(--line-2); background: var(--surface-2); }
.an-root .an-alert.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.an-root .an-alert .ic { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font: 700 12px var(--font-head); flex: none; }
.an-root .an-alert.bad .ic { background: var(--bad-wash); color: var(--bad-ink); }
.an-root .an-alert.warn .ic { background: var(--warn-wash); color: var(--warn-ink); }
.an-root .an-alert b { display: block; font-weight: 600; font-size: 13px; }
.an-root .an-alert span { color: var(--muted); font-size: 12px; }

/* charts */
.an-root .an-chart { position: relative; width: 100%; }
.an-root .an-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.an-root .an-chart text { font: 11px var(--font-ui); fill: var(--muted); font-variant-numeric: tabular-nums; }
.an-root .an-chart .lbl { fill: var(--ink-2); font-size: 11.5px; }
.an-root .an-chart .lblb { fill: var(--ink); font-weight: 600; font-size: 11.5px; }
.an-root .an-chart .grid-l { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.an-root .an-chart .base-l { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.an-root .an-chart .hit { fill: transparent; cursor: pointer; }
.an-root .an-chart .hit.crosshair { cursor: crosshair; }
.an-root .an-chart .hit:hover + .mk { filter: brightness(1.08); }
.an-root .an-chart .hrow { cursor: pointer; }
.an-root .an-chart .hrow:hover .hbg { fill: var(--accent-soft); }
.an-root .an-chart .hbg { fill: transparent; }
.an-root .an-tip { position: fixed; z-index: 70; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); box-shadow: var(--shadow); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 150px; max-width: 300px; opacity: 0; transition: opacity .08s; left: 0; top: 0; }
.an-root .an-tip.on { opacity: 1; }
.an-root .an-tip .th { font-weight: 600; margin-bottom: 4px; color: var(--ink-2); font-size: 11.5px; }
.an-root .an-tip .tr { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.an-root .an-tip .tr .k { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.an-root .an-tip .tr .val { font-weight: 600; font-variant-numeric: tabular-nums; }

/* tables */
.an-root .an-tbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.an-root .an-tbar-l { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; }
.an-root .an-search { border: 1px solid var(--line-2); background: var(--surface); border-radius: 6px; padding: 5px 10px; min-width: 0; width: 280px; max-width: 100%; height: 28px; }
.an-root .an-tscroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.an-root .an-tscroll table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.an-root .an-tscroll th, .an-root .an-tscroll td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.an-root .an-tscroll th { font: 600 11px/1.2 var(--font-head); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none; }
.an-root .an-tscroll th.l, .an-root .an-tscroll td.l { text-align: left; }
.an-root .an-tscroll th .ar { color: var(--accent); margin-left: 3px; }
.an-root .an-tscroll td.name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.an-root .an-tscroll td.wrapcell { white-space: normal; min-width: 180px; }
.an-root .an-tscroll tbody tr { cursor: pointer; }
.an-root .an-tscroll tbody.static tr { cursor: default; }
.an-root .an-tscroll tbody tr:hover td { background: var(--accent-soft); }
.an-root .an-tscroll tbody.static tr:hover td { background: transparent; }
.an-root .an-tscroll tfoot td { font-weight: 600; background: var(--surface-2); border-bottom: 0; }
.an-root .an-neg { color: var(--bad-ink); }
.an-root .an-pos { color: var(--good-ink); }
.an-root .an-pill { display: inline-block; font: 600 11px/1.5 var(--font-head); letter-spacing: .03em; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); }
.an-root .an-pill.bad { background: var(--bad-wash); color: var(--bad-ink); }
.an-root .an-pill.warn { background: var(--warn-wash); color: var(--warn-ink); }
.an-root .an-more { display: flex; justify-content: center; gap: 8px; padding: 10px; color: var(--muted); font-size: 12px; align-items: center; flex-wrap: wrap; }
.an-root .an-meter { display: inline-block; width: 46px; height: 6px; border-radius: 3px; background: var(--surface-2); vertical-align: middle; margin-left: 6px; overflow: hidden; }
.an-root .an-meter i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }

/* key/value, prose */
.an-root .an-kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.an-root .an-kv > div { background: var(--surface); padding: 10px 12px; }
.an-root .an-kv .l { font-size: 11.5px; color: var(--muted); }
.an-root .an-kv .v { font: 600 15px/1.2 var(--font-ui); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .an-root .an-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.an-root .an-prose { max-width: 72ch; color: var(--ink-2); }
.an-root .an-prose p { margin: 0 0 10px; }
.an-root .an-prose b { color: var(--ink); }
.an-root .an-methods { margin-top: 10px; }
.an-root .an-methods summary { cursor: pointer; color: var(--ink-2); font-weight: 500; }
.an-root .an-methods-b { margin-top: 8px; }
.an-root .an-kvlist { display: grid; grid-template-columns: auto auto; gap: 4px 18px; font-size: 12.5px; justify-content: start; margin: 0; }
.an-root .an-kvlist dt { color: var(--muted); }
.an-root .an-kvlist dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.an-root .an-kvlist.wide { grid-template-columns: minmax(130px, auto) 1fr; }
.an-root .an-kvlist.wide dd { text-align: left; }

/* cash-plan assumptions */
.an-root .an-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.an-root .an-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.an-root .an-form input[type=number] { border: 1px solid var(--line-2); background: var(--surface); border-radius: 6px; padding: 5px 9px; font-variant-numeric: tabular-nums; width: 100%; height: 30px; }
.an-root .an-form .hint { font-size: 11px; color: var(--muted); }
.an-root .an-form .chk { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.an-root .an-form .chk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.an-root .an-form .chk .hint { flex-basis: 100%; }

/* payment calendar */
.an-root .an-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.an-root .an-cal .dow { font: 600 10.5px var(--font-head); letter-spacing: .06em; color: var(--muted); text-transform: uppercase; padding: 2px 4px; }
.an-root .an-cal .day { min-height: 76px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; text-align: left; }
.an-root .an-cal .day:hover { border-color: var(--line-2); }
.an-root .an-cal .day.off { background: transparent; border-style: dashed; opacity: .45; cursor: default; }
.an-root .an-cal .day.today { box-shadow: 0 0 0 2px var(--accent); }
.an-root .an-cal .day.sel { border-color: var(--accent); background: var(--accent-soft); }
.an-root .an-cal .dn { font-weight: 600; color: var(--ink-2); }
.an-root .an-cal .o { color: var(--bad-ink); font-variant-numeric: tabular-nums; }
.an-root .an-cal .i { color: var(--good-ink); font-variant-numeric: tabular-nums; }
.an-root .an-cal .st { display: inline-block; font: 600 10px var(--font-head); background: var(--warn-wash); color: var(--warn-ink); border-radius: 3px; padding: 0 4px; align-self: flex-start; }
@media (max-width: 700px) { .an-root .an-cal .day { min-height: 54px; font-size: 10.5px; } .an-root .an-cal .i, .an-root .an-cal .o { display: none; } }

/* drill-down drawer */
.an-root .an-scrim { position: fixed; inset: 0; background: rgba(8, 12, 20, .38); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .15s; }
.an-root .an-scrim.on { opacity: 1; pointer-events: auto; }
.an-root .an-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--bg); z-index: 56; transform: translateX(100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; display: flex; flex-direction: column; border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(16, 24, 40, .14); }
.an-root .an-drawer.on { transform: none; visibility: visible; transition: transform .2s ease; }
.an-root .an-dhead { padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; background: var(--surface); }
.an-root .an-dhead .kind { font: 600 10.5px var(--font-head); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.an-root .an-dhead h3 { margin: 2px 0 0; font: 600 17px/1.25 var(--font-head); }
.an-root .an-dbody { overflow-y: auto; padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; }
.an-root .an-dbody > * { flex-shrink: 0; } /* the KPI grid clips (overflow hidden) and would otherwise shrink to nothing */
.an-root .an-x { border: 1px solid var(--line-2); background: var(--surface); border-radius: 6px; width: 32px; height: 32px; cursor: pointer; font-size: 18px; line-height: 1; flex: none; }
.an-root .an-x:hover { background: var(--surface-2); }

@media (max-width: 600px) {
  .an-root .an-search { width: 100%; }
  .an-root .an-herofig { font-size: 36px; }
  .an-root .an-card { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { .an-root * { transition: none !important; } }
