:root {
  --ink: #2f2a2c;
  --muted: #6f676a;
  --line: #ded9da;
  --soft-line: #ece8e9;
  --canvas: #f5f4f4;
  --paper: #ffffff;
  --red: #e51b36;
  --red-dark: #b9122b;
  --red-soft: #fff0f2;
  --green: #147d5a;
  --green-soft: #eaf7f1;
  --amber: #a35c00;
  --amber-soft: #fff6e5;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: #312d2f; color: white; display: flex; flex-direction: column; }
.brand-lockup { padding: 2px 8px 24px; border-bottom: 1px solid #514b4e; }
.brand-lockup img { display: block; width: 158px; height: auto; filter: brightness(0) invert(1); }
.brand-lockup span { display: block; margin-top: 8px; color: #cfc9cb; font-size: 12px; text-transform: uppercase; font-weight: 700; }
.primary-nav { display: grid; gap: 4px; padding-top: 20px; }
.nav-item { width: 100%; min-height: 40px; border: 0; border-radius: 6px; padding: 0 12px; text-align: left; color: #dcd7d9; background: transparent; font-size: 14px; font-weight: 600; }
.nav-item:hover { background: #403a3d; color: white; }
.nav-item.active { color: white; background: var(--red); }
.sidebar-status { margin-top: auto; padding: 14px 8px 2px; border-top: 1px solid #514b4e; display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: start; }
.sidebar-status strong, .sidebar-status span { display: block; }
.sidebar-status strong { font-size: 13px; }
.sidebar-status span { margin-top: 3px; color: #bbb4b7; font-size: 11px; line-height: 1.4; }
.status-dot { width: 9px; height: 9px; margin-top: 4px; border-radius: 50%; background: var(--amber); }
.status-dot.current { background: #31b886; }
.status-dot.error { background: var(--red); }

main { min-width: 0; padding: 0 34px 54px; }
.page-header { min-height: 116px; padding: 27px 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 5px; color: var(--red-dark); font-size: 11px; line-height: 1.2; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 27px; line-height: 1.2; }
h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.period-label { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.range-control { display: flex; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); }
.range-control button { min-width: 43px; height: 32px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 750; }
.range-control button.active { color: white; background: var(--ink); }
.command-button, .secondary-button { min-height: 40px; border: 1px solid transparent; border-radius: 6px; padding: 0 15px; font-size: 13px; font-weight: 750; }
.command-button { color: white; background: var(--red); }
.command-button:hover { background: var(--red-dark); }
.secondary-button { color: var(--ink); background: white; border-color: var(--line); }
.text-command { border: 0; padding: 5px 0; color: var(--red-dark); background: transparent; font-size: 12px; font-weight: 750; }
.text-command.link { text-decoration: none; }

.alert-band { display: grid; gap: 8px; margin: 18px 0; }
.alert-item { display: grid; grid-template-columns: 4px 1fr; gap: 12px; align-items: stretch; border: 1px solid var(--line); border-radius: 6px; background: white; overflow: hidden; }
.alert-item::before { content: ""; background: var(--amber); }
.alert-item.critical::before { background: var(--red); }
.alert-copy { padding: 11px 14px 11px 0; }
.alert-copy strong { display: inline; font-size: 13px; }
.alert-copy span { color: var(--muted); font-size: 12px; }

.view { display: none; }
.view.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(132px, 1fr)); gap: 10px; margin: 18px 0 30px; }
.kpi-card { min-height: 112px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.kpi-card .label { display: block; min-height: 30px; color: var(--muted); font-size: 12px; line-height: 1.3; }
.kpi-card .value { display: block; margin-top: 5px; font-size: 23px; line-height: 1.15; font-weight: 760; }
.kpi-card .change { display: block; margin-top: 8px; font-size: 11px; font-weight: 700; }
.change.improving { color: var(--green); }
.change.declining { color: var(--red-dark); }
.change.stable, .change.insufficient_data { color: var(--muted); }
.section-heading { min-height: 48px; margin-top: 24px; display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.section-heading.compact { margin: 0 0 14px; min-height: 38px; align-items: center; }
.definition { max-width: 620px; color: var(--muted); font-size: 11px; text-align: right; line-height: 1.4; }
.chart-panel { margin-top: 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--paper); }
.chart-legend { min-height: 38px; padding: 10px 12px 0; display: flex; gap: 18px; color: var(--muted); font-size: 11px; }
.chart-legend span { display: inline-flex; gap: 7px; align-items: center; }
.legend-line { width: 20px; height: 2px; background: var(--red); }
.legend-line.average { background: var(--ink); border-top: 1px dashed var(--ink); }
.legend-marker { width: 2px; height: 13px; background: var(--amber); }
.trend-chart { min-height: 290px; width: 100%; overflow: hidden; }
.trend-chart.tall { min-height: 340px; }
.trend-chart svg { display: block; width: 100%; height: 100%; min-height: inherit; }
.chart-grid-line { stroke: #eee9ea; stroke-width: 1; }
.chart-axis-label { fill: #746d70; font-size: 10px; }
.chart-path { fill: none; stroke: var(--red); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart-average { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 5; vector-effect: non-scaling-stroke; }
.chart-area { fill: url(#profitArea); }
.chart-point { fill: white; stroke: var(--red); stroke-width: 2; }
.annotation-line { stroke: var(--amber); stroke-width: 1; stroke-dasharray: 3 3; }
.annotation-dot { fill: var(--amber); }
.empty-chart { min-height: inherit; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

.overview-grid { margin-top: 28px; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr); gap: 28px; }
.data-block { min-width: 0; padding-top: 18px; border-top: 2px solid var(--ink); }
.data-block.full-width { margin-top: 30px; }
.bridge-row { display: grid; grid-template-columns: 120px minmax(90px, 1fr) 96px; gap: 12px; align-items: center; min-height: 37px; border-bottom: 1px solid var(--soft-line); font-size: 12px; }
.bridge-track { height: 8px; background: #eee9ea; }
.bridge-bar { height: 100%; min-width: 2px; background: var(--ink); }
.bridge-bar.cost { background: #9a8f93; }
.bridge-bar.profit { background: var(--green); }
.bridge-value { text-align: right; font-weight: 750; }
.funnel-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.funnel-step { min-height: 94px; padding: 15px 12px; background: white; }
.funnel-step span, .funnel-step strong { display: block; }
.funnel-step span { color: var(--muted); font-size: 11px; }
.funnel-step strong { margin-top: 7px; font-size: 22px; }
.funnel-step small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.funnel-flow { margin: 12px 0 28px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.funnel-flow .funnel-step { border: 1px solid var(--line); border-top: 3px solid var(--red); border-radius: 6px; }
.annotation-list { display: grid; gap: 9px; }
.annotation-item { display: grid; grid-template-columns: 78px 1fr auto; gap: 10px; align-items: start; padding-bottom: 9px; border-bottom: 1px solid var(--soft-line); }
.annotation-date { color: var(--muted); font-size: 11px; }
.annotation-item strong { display: block; font-size: 12px; }
.annotation-item p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.annotation-category { padding: 3px 6px; border-radius: 4px; color: var(--red-dark); background: var(--red-soft); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.empty-state { padding: 22px 0; color: var(--muted); font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--soft-line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.metric-positive { color: var(--green); font-weight: 700; }
.metric-negative { color: var(--red-dark); font-weight: 700; }
.search-input { width: min(240px, 40vw); height: 36px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; color: var(--ink); background: white; }
.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); border: 1px solid var(--line); }
.metric-strip > div { min-height: 88px; padding: 15px; border-right: 1px solid var(--line); background: white; }
.metric-strip > div:last-child { border-right: 0; }
.metric-strip strong, .metric-strip span { display: block; }
.metric-strip strong { font-size: 20px; }
.metric-strip span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.source-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 10px; margin: 12px 0 30px; }
.source-item { min-height: 136px; padding: 15px; border: 1px solid var(--line); border-top: 4px solid var(--amber); border-radius: 6px; background: white; }
.source-item.current { border-top-color: var(--green); }
.source-item.error { border-top-color: var(--red); }
.source-item h3 { margin: 0; font-size: 14px; }
.source-item strong { display: block; margin-top: 12px; font-size: 12px; text-transform: capitalize; }
.source-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.definition-list { margin: 0; }
.definition-list dt { margin-top: 12px; font-size: 12px; font-weight: 800; text-transform: capitalize; }
.definition-list dd { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

dialog { width: min(520px, calc(100vw - 30px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; box-shadow: 0 18px 60px rgba(44, 36, 39, .2); }
dialog::backdrop { background: rgba(47, 42, 44, .48); }
dialog form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 18px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--muted); background: var(--canvas); font-size: 22px; line-height: 1; }
dialog label { display: grid; gap: 6px; margin-top: 13px; color: var(--muted); font-size: 11px; font-weight: 750; }
dialog input, dialog select, dialog textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px; color: var(--ink); background: white; }
dialog textarea { resize: vertical; }
.dialog-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
.form-error { min-height: 16px; margin: 8px 0 0; color: var(--red-dark); font-size: 11px; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .source-grid { grid-template-columns: repeat(2, 1fr); }
  .funnel-flow { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 13px 14px 10px; }
  .brand-lockup { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 10px; }
  .brand-lockup img { width: 130px; }
  .brand-lockup span { margin: 0; }
  .primary-nav { display: flex; gap: 6px; overflow-x: auto; padding-top: 10px; scrollbar-width: none; }
  .nav-item { width: auto; min-width: max-content; min-height: 36px; text-align: center; }
  .sidebar-status { display: none; }
  main { padding: 0 16px 44px; }
  .page-header { min-height: 0; padding: 20px 0 16px; display: block; }
  .header-actions { margin-top: 16px; justify-content: space-between; }
  .overview-grid { grid-template-columns: 1fr; gap: 24px; }
  .definition { display: none; }
}

@media (max-width: 560px) {
  h1 { font-size: 23px; }
  .header-actions { align-items: stretch; flex-direction: column; }
  .range-control { justify-content: stretch; }
  .range-control button { flex: 1; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card { min-height: 105px; }
  .kpi-card .value { font-size: 20px; }
  .funnel-row, .funnel-flow { grid-template-columns: repeat(2, 1fr); }
  .source-grid, .metric-strip { grid-template-columns: 1fr; }
  .metric-strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-strip > div:last-child { border-bottom: 0; }
  .bridge-row { grid-template-columns: 100px minmax(60px, 1fr) 80px; }
  .section-heading.compact { align-items: start; }
  .search-input { width: 48%; }
}
