@import url("./ui-tokens.css");

body { font-family: var(--font-body); font-size: var(--text-body); line-height: var(--leading-body); }
body .app-shell { width: auto; max-width: var(--content-max); margin: 0 0 0 var(--nav-width); padding: var(--space-7) var(--space-8) var(--space-10); min-width: 0; }
body h1 { font-size: var(--text-h1); font-weight: var(--weight-heavy); letter-spacing: -.04em; line-height: var(--leading-tight); }
body h2 { font-size: var(--text-h4); font-weight: var(--weight-bold); letter-spacing: -.025em; }
body h3 { font-size: var(--text-lead); }
body h4 { font-size: var(--text-body); }
body p { line-height: var(--leading-body); }
body a { color: var(--accent); }
body .page-nav { display: none; }
body .topbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); margin: var(--space-7) 0 var(--space-6); }
body .topbar > div:first-child { flex: 1; min-width: 0; }
body .eyebrow { color: var(--muted); font-size: var(--text-small); font-weight: var(--weight-medium); margin-bottom: var(--space-2); }
body .top-actions { gap: var(--space-2); }
body .panel, body .summary-card { border-radius: var(--radius-lg); border-color: var(--line); box-shadow: var(--shadow); min-width: 0; }
body .panel-header { display: flex; padding: var(--space-5) var(--space-6); gap: var(--space-4); }
body .panel-header p { font-size: var(--text-small); color: var(--muted); margin-top: var(--space-1); }
body .panel > h2, body .panel > p, body .panel > label, body .panel > select { margin: var(--space-5) var(--space-6); }
body .panel + .panel { margin-top: var(--space-5); }
body .workspace { gap: var(--space-5); }
body .summary-grid { gap: var(--space-3); margin-bottom: var(--space-5); }
body .summary-card { padding: var(--space-5); }
body .summary-card > span { font-size: var(--text-small); margin-bottom: var(--space-2); color: var(--muted); }
body .summary-card > strong { font-family: var(--font-number); font-size: var(--text-h2); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }
body button, body .ghost-button, body .primary-button, body .file-button { border-radius: var(--radius-sm); font-size: var(--text-small); transition: background var(--transition), border-color var(--transition); }
body .ghost-button, body .primary-button, body .file-button, body .button-row > button { display: inline-flex; align-items: center; justify-content: center; min-height: var(--control-height); padding: var(--space-2) var(--space-4); text-decoration: none; }
body .button-row > button { border: var(--border-width) solid var(--line); color: var(--ink); background: var(--panel); }
body .ghost-button:hover { background: var(--ui-subtle); border-color: var(--muted); }
body .primary-button, body .file-button { background: var(--accent); color: var(--ui-white); }
body label { font-size: var(--text-small); color: var(--muted); font-weight: var(--weight-medium); gap: var(--space-2); }
body label input, body label select, body label textarea, body select, body input { border-radius: var(--radius-sm); border-color: var(--line); color: var(--ink); }
body input, body select { min-height: var(--control-height); background: var(--panel); }
body input[type="checkbox"], body input[type="radio"] { min-height: auto; accent-color: var(--accent); }
body :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
body [hidden] { display: none !important; }

.workspace-nav { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--nav-width); padding: var(--space-7) var(--space-4) var(--space-5); background: var(--ui-nav); color: var(--ui-white); display: flex; flex-direction: column; overflow: auto; }
.workspace-brand { display: flex; align-items: center; gap: var(--space-3); margin: 0 var(--space-2) var(--space-7); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: var(--space-8); height: var(--space-8); border-radius: var(--radius-md); background: var(--ui-lime); color: var(--ui-nav); font-family: Georgia, serif; font-size: var(--text-h3); font-weight: var(--weight-bold); }
.brand-name { color: var(--ui-white); font-size: var(--text-h4); font-weight: var(--weight-heavy); letter-spacing: -.04em; }
.brand-name small { display: block; color: var(--ui-nav-muted); font-size: var(--text-caption); font-weight: var(--weight-normal); letter-spacing: .06em; }
.nav-group { margin-bottom: var(--space-4); }
.nav-group h2 { font-size: var(--text-caption); font-weight: var(--weight-medium); color: var(--ui-nav-muted); margin: 0 var(--space-3) var(--space-1); letter-spacing: .04em; }
body .workspace-nav a.nav-link { display: flex; align-items: center; gap: var(--space-3); min-height: var(--control-height); margin: var(--space-1) 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--ui-nav-muted); text-decoration: none; font-size: var(--text-small); font-weight: var(--weight-medium); }
body .workspace-nav a.nav-link:hover { background: var(--ui-nav-active); color: var(--ui-white); }
body .workspace-nav a.nav-link.active { color: var(--ui-lime); background: var(--ui-nav-active); box-shadow: inset 3px 0 var(--ui-lime); }
.nav-link svg, .utility-icon { width: var(--icon-size); height: var(--icon-size); fill: none; stroke: currentColor; stroke-width: 1.6; flex-shrink: 0; }
.nav-note { margin-top: auto; padding: var(--space-4) var(--space-3) 0; border-top: var(--border-width) solid var(--ui-nav-active); font-size: var(--text-caption); color: var(--ui-nav-muted); }
.nav-note strong { display: block; color: var(--ui-white); font-size: var(--text-small); margin-bottom: var(--space-1); }
.workspace-utility { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: var(--space-8); font-size: var(--text-small); }
.utility-breadcrumb { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); }
.utility-breadcrumb strong { color: var(--ink); font-weight: var(--weight-medium); }
.snapshot-chip { display: inline-flex; align-items: center; gap: var(--space-2); border: var(--border-width) solid var(--line); border-radius: var(--radius-pill); padding: var(--space-1) var(--space-3); background: var(--panel); color: var(--muted); white-space: nowrap; font-size: var(--text-caption); }
.snapshot-chip::before { content: ""; width: var(--space-2); height: var(--space-2); border-radius: var(--radius-pill); background: var(--accent); }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); color: var(--muted); font-size: var(--text-caption); }
.page-meta a { color: var(--muted); text-decoration: none; border-bottom: var(--border-width) dotted var(--line); }
.data-footer { margin-top: var(--space-6); padding-top: var(--space-4); border-top: var(--border-width) solid var(--line); color: var(--muted); font-size: var(--text-caption); overflow-wrap: anywhere; }
.mobile-nav-toggle, .mobile-nav-close, .nav-backdrop { display: none; }

body .table-wrap, body .registration-scroll { max-width: 100%; max-height: var(--table-height); overflow: auto; isolation: isolate; }
body table { min-width: var(--table-min); border-collapse: separate; border-spacing: 0; font-size: var(--text-small); }
body table thead th { position: sticky; top: 0; z-index: 3; background: var(--ui-subtle); color: var(--muted); border-bottom: var(--border-width) solid var(--line); font-size: var(--text-caption); font-weight: var(--weight-bold); padding: var(--space-3) var(--space-4); text-align: left; white-space: nowrap; }
body .watch-table thead th.locked { position: sticky; top: 0; }
body table tbody td { padding: var(--space-3) var(--space-4); border-bottom: var(--border-width) solid var(--line); border-right-color: var(--ui-subtle); font-size: var(--text-small); color: var(--ink); line-height: var(--leading-body); }
body table tbody tr:nth-child(even) { background: var(--ui-subtle); }
body table tbody tr:hover { background: var(--ui-hover); }
body table .ui-number, body table .number-cell, body table .computed { text-align: right; font-variant-numeric: tabular-nums; }
body table th.ui-number { text-align: right; }
body table .ui-number input { text-align: right; }
body table .ui-status { text-align: left; }
body .ledger-table td:nth-child(2) { min-width: var(--product-min); max-width: var(--product-max); font-weight: var(--weight-medium); }
body .ledger-table { min-width: var(--ledger-min); }
body .ledger-table td:first-child { font-family: var(--font-number); color: var(--muted); font-size: var(--text-caption); }
body .inflow-table, body .distribution-table { table-layout: auto; min-width: var(--table-min); }
body .inflow-table th:first-child, body .inflow-table td:first-child { width: 38%; }
body .inflow-table th:last-child { width: auto; }
body .empty-cell, body .watch-empty { padding: var(--space-10) var(--space-6); text-align: center; color: var(--muted); font-size: var(--text-body); }
body .ledger-summary, body .registration-summary { padding: var(--space-5) var(--space-6); background: var(--panel); border: var(--border-width) solid var(--line); border-radius: var(--radius-lg); margin-bottom: var(--space-5); color: var(--muted); font-size: var(--text-small); }
body .ledger-summary strong { font-family: var(--font-number); color: var(--ink); font-size: var(--text-h2); }
body .ledger-summary p { margin-top: var(--space-1); }
body .ledger-controls, body .registration-controls, body .controls, body .watch-filters, body .inflow-controls, body .matrix-form { gap: var(--space-4); padding: var(--space-5) var(--space-6); }
body .ledger-controls > label, body .registration-controls > label { flex: 1 1 160px; }
body .ledger-help, body .registration-help, body .help, body .watch-help, body .inflow-help, body .distribution-help { font-size: var(--text-small); color: var(--muted); line-height: var(--leading-body); }
body .inflow-summary, body .distribution-summary { gap: var(--space-4); margin: var(--space-5) 0; }
body .inflow-summary > div, body .distribution-summary > div { padding: var(--space-5); border-radius: var(--radius-lg); }
body .inflow-summary dd, body .distribution-summary dd { font-family: var(--font-number); font-size: var(--text-h1); font-weight: var(--weight-bold); margin-top: var(--space-2); }
body .inflow-banner { background: var(--ui-warning-bg); color: var(--ui-warning-ink); padding: var(--space-3) var(--space-4); border: var(--border-width) solid var(--line); border-radius: var(--radius-md); font-size: var(--text-small); }
.ui-chip { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1); padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); color: var(--ui-neutral-ink); background: var(--ui-neutral-bg); font-size: var(--text-caption); font-weight: var(--weight-bold); line-height: var(--leading-tight); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ui-chip[data-tone="success"] { color: var(--ui-success-ink); background: var(--ui-success-bg); }
.ui-chip[data-tone="warning"] { color: var(--ui-warning-ink); background: var(--ui-warning-bg); }
.ui-chip[data-tone="danger"] { color: var(--ui-danger-ink); background: var(--ui-danger-bg); }
.ui-chip[data-tone="info"] { color: var(--ui-info-ink); background: var(--ui-info-bg); }
body table .unknown-value { color: var(--muted); }

.dashboard-intro { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.dashboard-intro p { color: var(--muted); font-size: var(--text-small); }
.dashboard-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.kpi-card { background: var(--panel); border: var(--border-width) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); min-width: 0; box-shadow: var(--shadow); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); color: var(--muted); font-size: var(--text-small); }
.kpi-icon { display: grid; place-items: center; width: var(--space-8); height: var(--space-8); border-radius: var(--radius-md); color: var(--accent); background: var(--soft); }
.kpi-icon svg { width: var(--icon-size); height: var(--icon-size); stroke: currentColor; stroke-width: 1.6; fill: none; }
.kpi-value { display: flex; align-items: baseline; gap: var(--space-1); margin: var(--space-3) 0 var(--space-2); font-family: var(--font-number); font-size: var(--text-display); line-height: var(--leading-tight); font-weight: var(--weight-medium); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-family: var(--font-body); font-size: var(--text-small); color: var(--muted); font-weight: var(--weight-normal); letter-spacing: 0; }
.kpi-card > p { color: var(--muted); font-size: var(--text-caption); }
.kpi-card[data-emphasis="true"] { background: var(--ui-nav); border-color: var(--ui-nav); color: var(--ui-white); }
.kpi-card[data-emphasis="true"] .kpi-top, .kpi-card[data-emphasis="true"] p, .kpi-card[data-emphasis="true"] small { color: var(--ui-nav-muted); }
.kpi-card[data-emphasis="true"] .kpi-icon { background: var(--ui-nav-active); color: var(--ui-lime); }
.dashboard-charts { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-5); margin-bottom: var(--space-5); }
.dashboard-lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: var(--space-5); margin-bottom: var(--space-6); }
body .dashboard-charts > .panel, body .dashboard-lower > .panel { margin-top: 0; }
.chart-panel { min-width: 0; }
.chart-panel .panel-header { border-bottom: 0; align-items: center; }
.chart-body { padding: 0 var(--space-6) var(--space-4); }
.chart-body svg { display: block; width: 100%; height: auto; max-height: var(--chart-height); overflow: visible; }
.chart-grid { stroke: var(--line); stroke-dasharray: 3 5; }
.chart-axis { fill: var(--muted); font-family: var(--font-body); font-size: var(--text-caption); }
.chart-label { fill: var(--ink); font-family: var(--font-number); font-size: var(--text-small); font-weight: var(--weight-bold); }
.chart-bar { fill: var(--ui-chart-sales); }
.chart-margin { fill: var(--ui-chart-margin); stroke: var(--ui-chart-margin); }
.chart-line { fill: none; stroke: var(--ui-chart-margin); stroke-width: 3; stroke-linecap: round; }
.chart-legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: var(--text-caption); color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: var(--space-2); }
.legend-dot { width: var(--space-2); height: var(--space-2); border-radius: var(--radius-pill); background: var(--ui-chart-sales); }
.legend-dot.margin { background: var(--ui-chart-margin); }
.chart-note { color: var(--muted); font-size: var(--text-caption); padding: 0 var(--space-6) var(--space-4); }
.donut-layout { display: flex; align-items: center; gap: var(--space-5); padding: var(--space-2) var(--space-6) var(--space-6); }
.donut-wrap { width: var(--chart-ring-size); height: var(--chart-ring-size); position: relative; flex-shrink: 0; }
.donut-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-ring { fill: none; stroke-width: var(--ui-ring-stroke, var(--chart-stroke)); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; font-size: var(--text-caption); color: var(--muted); }
.donut-center strong { font-family: var(--font-number); font-size: var(--text-h1); color: var(--ink); font-weight: var(--weight-medium); line-height: var(--leading-tight); }
.donut-legend { flex: 1; min-width: 0; list-style: none; padding: 0; margin: 0; }
.donut-legend li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-2); padding: var(--space-3) 0; border-bottom: var(--border-width) solid var(--line); font-size: var(--text-small); }
.donut-legend strong { font-family: var(--font-number); font-weight: var(--weight-bold); }
.chart-tone-0 { fill: var(--ui-chart-sales); stroke: var(--ui-chart-sales); background: var(--ui-chart-sales); }
.chart-tone-1 { fill: var(--ui-chart-margin); stroke: var(--ui-chart-margin); background: var(--ui-chart-margin); }
.chart-tone-2 { fill: var(--ui-chart-other); stroke: var(--ui-chart-other); background: var(--ui-chart-other); }
.chart-tone-3 { fill: var(--ui-chart-unknown); stroke: var(--ui-chart-unknown); background: var(--ui-chart-unknown); }
.donut-ring.chart-tone-0, .donut-ring.chart-tone-1, .donut-ring.chart-tone-2, .donut-ring.chart-tone-3 { fill: none; }
.histogram-good { fill: var(--ui-chart-sales); }
.histogram-caution { fill: var(--ui-chart-margin); }
.histogram-danger { fill: var(--danger); }
.histogram-unknown { fill: var(--ui-chart-unknown); }
.task-list { list-style: none; margin: 0; padding: 0 var(--space-6) var(--space-2); }
.task-list li + li { border-top: var(--border-width) solid var(--line); }
.task-list a { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) 0; text-decoration: none; color: var(--ink); }
.task-index { display: grid; place-items: center; width: var(--space-8); height: var(--space-8); background: var(--ui-subtle); border: var(--border-width) solid var(--line); border-radius: var(--radius-md); font-family: var(--font-number); font-size: var(--text-small); color: var(--muted); flex-shrink: 0; }
.task-text { flex: 1; min-width: 0; font-size: var(--text-body); font-weight: var(--weight-medium); }
.task-text small { display: block; color: var(--muted); font-size: var(--text-caption); font-weight: var(--weight-normal); margin-top: var(--space-1); }
.task-count { font-size: var(--text-small); color: var(--danger); font-family: var(--font-number); white-space: nowrap; }
.task-list svg { width: var(--icon-size); height: var(--icon-size); flex-shrink: 0; fill: none; stroke: var(--muted); stroke-width: 1.6; }
.calculator-disclosure { border: var(--border-width) solid var(--line); border-radius: var(--radius-lg); background: var(--panel); overflow: hidden; }
.calculator-disclosure > summary { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-5) var(--space-6); cursor: pointer; list-style: none; font-size: var(--text-lead); font-weight: var(--weight-bold); }
.calculator-disclosure > summary::after { content: "+"; margin-left: auto; color: var(--accent); font-size: var(--text-h2); }
.calculator-disclosure[open] > summary::after { content: "−"; }
.calculator-disclosure > summary small { font-size: var(--text-small); color: var(--muted); font-weight: var(--weight-normal); }
.calculator-content { padding: var(--space-5); border-top: var(--border-width) solid var(--line); background: var(--bg); }
.calculator-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.dashboard-error { background: var(--ui-danger-bg); color: var(--ui-danger-ink); padding: var(--space-4); border-radius: var(--radius-md); margin-bottom: var(--space-4); }
.inflow-chart { margin-bottom: var(--space-5); }
.inflow-chart .donut-layout { justify-content: center; }
.inflow-chart .donut-legend { max-width: var(--legend-max); }

@media (min-width: 1600px) {
  .dashboard-kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 1180px) {
  body .app-shell { padding-left: var(--space-6); padding-right: var(--space-6); }
  .dashboard-charts { grid-template-columns: 1fr; }
  .donut-layout { justify-content: center; }
  .donut-legend { max-width: var(--legend-max); }
}
@media (max-width: 760px) {
  body .app-shell { margin-left: 0; padding: var(--space-4) var(--space-4) var(--space-8); width: auto; max-width: 100%; }
  body .topbar { margin: var(--space-6) 0 var(--space-5); gap: var(--space-4); align-items: start; }
  body .topbar > div:first-child { flex-basis: 100%; }
  body h1 { font-size: var(--text-h2); }
  .workspace-nav { transform: translateX(-100%); transition: none; width: var(--nav-mobile-width); }
  body.nav-open .workspace-nav { transform: translateX(0); transition: transform var(--transition); box-shadow: var(--shadow-raised); }
  body .watch-table thead th.locked { left: auto; }
  body.nav-open { overflow: hidden; }
  .nav-backdrop { position: fixed; inset: 0; background: var(--ui-overlay); border: 0; border-radius: 0; z-index: 29; }
  body.nav-open .nav-backdrop { display: block; }
  .mobile-nav-toggle, .mobile-nav-close { display: inline-flex; align-items: center; justify-content: center; min-width: var(--touch-height); min-height: var(--touch-height); border: var(--border-width) solid var(--line); padding: var(--space-2); background: var(--panel); color: var(--ink); }
  .mobile-nav-close { position: absolute; right: var(--space-3); top: var(--space-3); color: var(--ui-nav-muted); background: var(--ui-nav); border-color: var(--ui-nav-active); min-width: var(--space-8); min-height: var(--space-8); }
  .workspace-brand { margin-top: var(--space-6); }
  .utility-breadcrumb { gap: var(--space-2); }
  .utility-breadcrumb > span { display: none; }
  .snapshot-chip { font-size: var(--text-caption); padding: var(--space-1) var(--space-2); }
  .workspace-utility { gap: var(--space-2); }
  .page-meta { display: grid; gap: var(--space-1); font-size: var(--text-caption); }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .kpi-card { padding: var(--space-4); }
  .kpi-icon { display: none; }
  .kpi-value { font-size: var(--text-h1); }
  .kpi-top { font-size: var(--text-caption); }
  .kpi-card > p { font-size: var(--text-caption); }
  .dashboard-intro { align-items: flex-start; }
  .dashboard-intro p { font-size: var(--text-small); }
  .dashboard-intro .ui-chip { flex-shrink: 0; }
  .dashboard-charts, .dashboard-lower { grid-template-columns: 1fr; gap: var(--space-4); }
  body .panel-header { padding: var(--space-4); gap: var(--space-3); }
  .chart-panel .panel-header { flex-wrap: wrap; }
  .chart-body { padding: 0 var(--space-4) var(--space-4); }
  .chart-note { padding: 0 var(--space-4) var(--space-4); }
  .donut-layout { padding: var(--space-2) var(--space-4) var(--space-5); gap: var(--space-4); }
  .donut-wrap { width: var(--donut-mobile-size); height: var(--donut-mobile-size); }
  .chart-axis { font-size: var(--text-h4); }
  .chart-label { font-size: var(--text-h3); }
  .donut-legend li { font-size: var(--text-caption); gap: var(--space-1); }
  .task-list { padding: 0 var(--space-4) var(--space-2); }
  .task-text { font-size: var(--text-small); }
  .calculator-disclosure > summary { padding: var(--space-4); flex-wrap: wrap; gap: var(--space-2); }
  .calculator-disclosure > summary small { flex-basis: 70%; }
  .calculator-content { padding: var(--space-3); }
  body .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body .summary-card { padding: var(--space-4); }
  body .summary-card > strong { font-size: var(--text-h3); overflow-wrap: anywhere; }
  body .top-actions { justify-content: flex-start; width: 100%; }
  body .top-actions > * { flex: 1 1 auto; }
  body .ledger-controls, body .registration-controls, body .controls, body .watch-filters, body .inflow-controls { padding: var(--space-4); gap: var(--space-3); }
  body .ledger-controls > label, body .registration-controls > label, body .controls > label, body .watch-filters > label { flex-basis: 100%; }
  body .inflow-summary, body .distribution-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  body .inflow-summary > div, body .distribution-summary > div { padding: var(--space-4); }
  body .inflow-summary dd, body .distribution-summary dd { font-size: var(--text-h2); }
  body .ledger-summary, body .registration-summary { padding: var(--space-4); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
