:root {
  --ground: #f2f5f2;
  --surface: #ffffff;
  --raised: #e9eee9;
  --active: #e2e9e2;
  --border: #dfe6df;
  --rule: #edf1ed;
  --control: #cfd8cf;
  --text: #0e1410;
  --muted: #5f6b62;
  --faint: #7d877f;
  --accent: #1d5fbf;
  --positive: #2e7d32;
  --negative: #c4242a;
  --warning: #92400e;
  --pill-positive-bg: #dcfae5;
  --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea;
  --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb;
  --pill-warning-ink: #92400e;
  --pill-neutral-bg: #eef2ee;
  --pill-neutral-ink: #3d4a40;
  --radius-card: 8px;
  --radius-control: 6px;
  --row-height: 44px;
  --sidebar-width: 248px;
  --gap: 12px;
  --pad: 24px;
  --control-height: 36px;
  --fs-title: 24px;
  --fs-section: 16px;
  --fs-kpi: 30px;
  --fs-body: 14px;
  --fs-small: 12px;
  --font: "Geist", Inter, system-ui, -apple-system, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--ground);
  overflow-x: hidden;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.meta { color: var(--muted); font-size: var(--fs-small); }
.meta-label { color: var(--muted); font-size: 11px; }

.shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--border);
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 38px; height: 38px; color: var(--text); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.wordmark { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.scope { font-size: 11px; color: var(--muted); line-height: 1.25; }
.workspace { display: flex; flex-direction: column; gap: 5px; }
.workspace label { font-size: 11px; color: var(--muted); }
.workspace select { width: 100%; }
.workspace .meta { font-size: 11px; }

select, input[type="text"], input[type="password"], input[type="date"], textarea {
  height: var(--control-height);
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 0 10px;
  min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.4; }
select { padding-right: 26px; }
select:hover, input:hover, textarea:hover { border-color: #aebcae; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(29, 95, 191, 0.12); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--radius-control);
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--muted);
}
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item.active { background: var(--active); color: var(--text); font-weight: 500; }

.provenance {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: auto;
}
.prov-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text); }
.prov-row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.provenance p { margin: 5px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.ai-badge {
  font-size: 11px;
  color: var(--muted);
  background: var(--raised);
  border-radius: var(--radius-control);
  padding: 6px 8px;
  line-height: 1.3;
}
.ai-badge.online { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.ai-badge.error { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

.canvas { padding: 28px 32px 56px; max-width: 1440px; width: 100%; margin: 0 auto; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 16px; }
h1 { font-size: var(--fs-title); line-height: 1.15; letter-spacing: -0.025em; margin: 0 0 6px; font-weight: 600; }
h2 { font-size: var(--fs-section); line-height: 1.25; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.finding { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 780px; line-height: 1.4; }
.title-actions { display: flex; gap: 8px; flex: none; }

.primary, .secondary, .link-button, .chip {
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  height: var(--control-height);
  padding: 0 14px;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease;
}
.primary { background: #141414; color: #fff; border-color: #141414; font-weight: 500; }
.primary:hover { background: #2a2a2a; }
.secondary { background: var(--raised); color: var(--text); border-color: var(--border); }
.secondary:hover { background: var(--active); }
.link-button { background: transparent; color: var(--accent); padding: 0; height: auto; border: 0; font-size: var(--fs-small); }
.link-button:hover { text-decoration: underline; }
.chip { height: 28px; padding: 0 10px; background: var(--surface); border-color: var(--border); color: var(--muted); font-size: 12px; }
.chip:hover { color: var(--text); border-color: var(--control); }

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.composer > label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.composer-row { display: flex; gap: 8px; }
.composer-row input { flex: 1; height: 38px; }
.composer-row .secondary { height: 38px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ai-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }

.filters {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0 16px;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11px; color: var(--muted); }
.field select, .field input { height: var(--control-height); }
.filters .field select { min-width: 190px; }
.filters .field input[type="date"] { min-width: 136px; }
.filters .switch { flex-direction: row; align-items: center; gap: 8px; height: var(--control-height); padding: 0 4px; font-size: 12.5px; color: var(--muted); }
.filters .switch input { width: 15px; height: 15px; accent-color: var(--accent); }
.filters #applyFilters { margin-left: auto; }

.view { display: flex; flex-direction: column; gap: 12px; }
.analytics-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.analytics-card { padding: 18px 20px 0; }
.analytics-head { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 22px; padding-bottom: 16px; }
.hero { padding-top: 4px; display: flex; flex-direction: column; align-items: flex-start; }
.hero-value { font-size: var(--fs-kpi); line-height: 1.1; font-weight: 500; letter-spacing: -0.02em; margin: 6px 0 2px; }
.delta { font-size: 13px; color: var(--text); }
.delta .muted { color: var(--muted); }
.hero .meta { margin-top: 5px; }
.legend { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; width: 100%; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.legend-swatch.dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-swatch.dash { height: 0; border-top: 2px dashed #8a8a8a; border-radius: 0; }
.chart-wrap { min-width: 0; }
.chart { width: 100%; min-height: 300px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart.small { min-height: 210px; }
.chart-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart text { font-family: var(--font); }
.chart .gridline { stroke: var(--rule); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .series-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .baseline-line { fill: none; stroke: #8a8a8a; stroke-width: 1; stroke-dasharray: 4 4; }
.chart .anomaly-dot { fill: var(--warning); stroke: var(--surface); stroke-width: 1.5; }
.chart .last-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .annotation-line { stroke-width: 1.5; stroke-dasharray: 3 3; opacity: .8; }
.chart .annotation-label { font-size: 11px; }
.chart .empty-line { stroke: var(--border); stroke-width: 1; }
.chart .hover-line { stroke: var(--text); stroke-width: 1; opacity: .35; }
.chart .hover-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  margin: 0 -20px;
}
.kpi { padding: 12px 16px; border-left: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi-value { font-size: 21px; line-height: 1.2; font-weight: 500; letter-spacing: -0.015em; }
.kpi-label { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.kpi-note { font-size: 11px; color: var(--muted); margin-top: 2px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 12px; align-items: stretch; }
.panel { padding: 16px 18px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-note { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.45; }

.insight-list { display: flex; flex-direction: column; }
.insight { padding: 10px 0; border-top: 1px solid var(--rule); }
.insight:first-child { border-top: 0; padding-top: 2px; }
.insight-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.insight-title { font-weight: 500; font-size: 13px; }
.insight-text { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.pill { display: inline-flex; align-items: center; height: 19px; padding: 0 7px; border-radius: 4px; font-size: 11px; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; }
.pill.warning { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.pill.critical { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.info { background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }
.pill.kind-anomaly { background: #eef3fb; color: #1d4f8f; }
.pill.kind-event { background: #eaf4ea; color: #245b2a; }
.pill.kind-exclusion { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.pill.kind-risk { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.kind-note { background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }

.annotation-list { display: flex; flex-direction: column; }
.annotation-add { width: 100%; margin-top: 10px; }
.annotation-row { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 10px; padding: 9px 0; border-top: 1px solid var(--rule); align-items: start; }
.annotation-row:first-child { border-top: 0; padding-top: 2px; }
.annotation-date { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.35; }
.annotation-title { font-size: 13px; font-weight: 500; line-height: 1.35; }
.annotation-note { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.annotation-author { font-size: 11px; color: var(--muted); margin-top: 3px; }
.annotation-list.compact .annotation-row { grid-template-columns: 84px minmax(0, 1fr) auto; }
.annotation-actions { display: flex; gap: 4px; align-items: center; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 4px; border-radius: 4px; }
.icon-button:hover { background: var(--raised); color: var(--text); }
.empty { color: var(--muted); font-size: 12.5px; padding: 8px 0; }

.table-wrap { overflow-x: auto; }
#monthlyTable { max-height: 390px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11.5px; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
td.invalid { color: var(--muted); }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--positive); margin-right: 6px; }
.status-dot.bad { background: var(--negative); }
.status-dot.warn { background: var(--warning); }

.heatmap { display: grid; grid-template-columns: 58px repeat(12, minmax(24px, 1fr)); gap: 3px; align-items: stretch; min-width: 680px; }
.heatmap-wrap { overflow-x: auto; }
.heat-cell { height: 24px; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.heat-year { height: 24px; display: flex; align-items: center; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.heat-month { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.heat-legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 10px; }
.heat-legend i { width: 72px; height: 7px; background: var(--accent); opacity: .75; border-radius: 2px; display: inline-block; }

.reason-list { display: flex; flex-direction: column; gap: 0; }
.reason { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 12.5px; }
.reason:first-child { border-top: 0; padding-top: 2px; }
.reason span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.gap-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.gap-form .field input { min-width: 150px; }
.gap-result { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.gap-card { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 11px 12px; min-width: 0; }
.gap-card h3 { margin: 0 0 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
.gap-card .big { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.gap-card p { margin: 5px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.gap-recommendation { grid-column: 1 / -1; font-size: 12.5px; color: var(--text); line-height: 1.45; padding: 10px 12px; background: var(--raised); border-radius: var(--radius-card); }
.eda-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.eda-block { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 12px; min-width: 0; }
.eda-block h3 { margin: 0 0 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.eda-block .big { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.eda-block ul { margin: 6px 0 0; padding: 0; list-style: none; }
.eda-block li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 12px; border-top: 1px solid var(--rule); }
.eda-block li:first-child { border-top: 0; }
.eda-block li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.risk-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.risk-card { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px; min-width: 0; }
.risk-card.high { border-color: #e8b4b4; }
.risk-card.moderate { border-color: #e8d6a8; }
.risk-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.risk-title { font-size: 14px; font-weight: 500; }
.risk-score { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.risk-level { font-size: 11px; color: var(--muted); }
.risk-bar { height: 4px; background: var(--raised); border-radius: 2px; margin: 8px 0 10px; overflow: hidden; }
.risk-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.risk-card.high .risk-bar i { background: var(--negative); }
.risk-card.moderate .risk-bar i { background: var(--warning); }
.risk-evidence { margin: 0; padding-left: 15px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.risk-evidence li { margin: 2px 0; }
.risk-note { margin: 8px 0 0; font-size: 11px; color: var(--faint); line-height: 1.4; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: end; }
.form-grid .wide { grid-column: span 2; }
.form-grid .align-end { display: flex; align-items: flex-end; }
.form-grid .align-end button { width: 100%; }
.form-grid textarea { min-height: 66px; }

.report-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px; }
.narrative { font-size: 14px; line-height: 1.55; color: var(--text); min-height: 90px; }
.report-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.report-list { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.action-list { display: flex; flex-direction: column; }
.action { padding: 9px 0; border-top: 1px solid var(--rule); font-size: 12.5px; line-height: 1.45; }
.action:first-child { border-top: 0; padding-top: 2px; }
.action b { font-weight: 500; }

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .14);
}
.dialog::backdrop { background: rgba(14, 20, 16, .28); }
.dialog form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.dialog-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 9px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .10);
  max-width: 260px;
}
.tooltip b { font-weight: 500; }
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: #141414;
  color: #fff;
  border-radius: var(--radius-control);
  padding: 9px 14px;
  font-size: 12.5px;
  max-width: min(560px, calc(100vw - 32px));
}
.toast.error { background: var(--negative); }

@media (max-width: 1100px) {
  .shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px 10px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 16px;
    align-items: center;
  }
  .brand { grid-column: 1; }
  .workspace { grid-column: 2; min-width: 190px; }
  .nav { grid-column: 1 / -1; flex-direction: row; overflow-x: auto; padding-bottom: 2px; }
  .nav-item { white-space: nowrap; }
  .provenance { display: none; }
  .sidebar-foot { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; border-top: 0; padding-top: 0; }
  .canvas { padding: 22px 20px 40px; }
  .analytics-head { grid-template-columns: 240px minmax(0, 1fr); gap: 16px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .wide { grid-column: span 2; }
  .eda-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .canvas { padding: 16px 16px 32px; }
  .title-row { flex-direction: column; gap: 10px; }
  .title-actions { width: 100%; }
  .title-actions .primary { width: 100%; }
  .composer-row { flex-direction: column; }
  .composer-row .secondary { width: 100%; }
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
  .filters .field select, .filters .field input[type="date"] { min-width: 0; width: 100%; }
  .filters #applyFilters { margin-left: 0; width: 100%; }
  .filters .switch { grid-column: span 2; }
  .analytics-head { grid-template-columns: 1fr; }
  .hero { padding-top: 0; }
  .legend { flex-direction: row; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .two-col, .report-grid { grid-template-columns: 1fr; }
  .risk-grid { grid-template-columns: 1fr; }
  .eda-grid, .gap-result { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: span 1; }
  .annotation-row, .annotation-list.compact .annotation-row { grid-template-columns: 1fr auto; }
  .annotation-date { grid-column: 1 / -1; }
  .chart { min-height: 220px; }
  .sidebar { grid-template-columns: 1fr; }
  .workspace { grid-column: 1; }
  .nav { grid-column: 1; flex-wrap: wrap; overflow-x: visible; }
  .sidebar-foot { grid-column: 1; }
  .table-wrap table { min-width: 560px; }
  #monthlyTable table { min-width: 640px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
