:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #66727f;
  --line: #d9e0e7;
  --green: #167a55;
  --green-soft: #dff3eb;
  --red: #b93737;
  --red-soft: #fae8e8;
  --blue: #2364aa;
  --amber: #a36f00;
  --amber-soft: #fff1cc;
  --sidebar: #18212c;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}
button { font: inherit; }
.hidden { display: none !important; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 30px; line-height: 1.15; }
h2 { margin-bottom: 8px; font-size: 19px; line-height: 1.2; }
p { color: var(--muted); line-height: 1.35; }

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--sidebar);
  color: #f7fafc;
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #263342;
  color: white;
  font-weight: 800;
}
.brand-title { font-size: 18px; font-weight: 800; }
.brand-org { margin-top: 3px; color: #dbe4ed; font-size: 12px; font-weight: 700; }
.brand-subtitle { color: #b9c4cf; font-size: 13px; }
.nav { display: grid; gap: 8px; }
.nav-button {
  min-height: 44px;
  border: 1px solid #3b4d60;
  border-radius: 8px;
  padding: 10px 12px;
  background: #263342;
  color: #ffffff;
  cursor: pointer;
  text-align: left;
}
.source-panel {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 16px;
  border: 1px solid #324254;
  border-radius: 8px;
  background: #202c3a;
}
.source-panel span { color: #b9c4cf; font-size: 13px; overflow-wrap: anywhere; }
.ghost-action {
  min-height: 38px;
  border: 1px solid #3b4d60;
  border-radius: 8px;
  background: transparent;
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.workspace { min-width: 0; padding: 28px; }
.topbar, .panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.topbar { margin-bottom: 22px; }
.eyebrow {
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}
.topbar-note { margin-bottom: 0; }
.status-badge {
  border-radius: 8px;
  padding: 10px 12px;
  background: #eef2f5;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}
.status-badge.green, .metric-status.green, em.green { background: var(--green-soft); color: var(--green); }
.status-badge.amber, .metric-status.amber, em.amber { background: var(--amber-soft); color: var(--amber); }
.status-badge.red, .metric-status.red, em.red { background: var(--red-soft); color: var(--red); }
.status-badge.error, .metric-status.error, em.error { background: var(--red); color: white; }
.execution-pill.green { background: var(--green-soft); color: var(--green); }
.execution-pill.amber { background: var(--amber-soft); color: var(--amber); }
.execution-pill.red { background: var(--red-soft); color: var(--red); }
.execution-pill.error { background: var(--red); color: white; }
.execution-pill.muted { background: #eef2f5; color: var(--muted); }

.kpi-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 10px;
}
.kpi-section-title h2 { margin: 0; font-size: 21px; }
.kpi-section-title span { color: var(--muted); font-size: 13px; font-weight: 800; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric-card, .panel, .setup-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}
.metric-card {
  position: relative;
  min-height: 150px;
  padding: 18px;
  border-top: 5px solid var(--blue);
}
.metric-card.green { border-top-color: var(--green); }
.metric-card.amber { border-top-color: var(--amber); }
.metric-card.red, .metric-card.error { border-top-color: var(--red); }
.metric-label { min-height: 34px; color: var(--muted); font-size: 14px; font-weight: 700; }
.metric-value { margin-top: 8px; font-size: 30px; line-height: 1.05; font-weight: 800; word-break: break-word; }
.metric-meta { margin-top: 8px; color: var(--muted); font-size: 13px; }
.metric-status {
  display: inline-block;
  margin-top: 12px;
  border-radius: 8px;
  padding: 6px 8px;
  background: #eef2f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.visual-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.36fr) minmax(0, 0.64fr);
  gap: 16px;
  margin-bottom: 16px;
}
.progress-panel, .chart-panel { min-height: 320px; }
.gauge-layout {
  display: grid;
  place-items: center;
  min-height: 230px;
}
.gauge {
  position: relative;
  width: min(360px, 100%);
  height: 230px;
}
.gauge svg {
  display: block;
  width: 100%;
  height: auto;
}
.gauge-track,
.gauge-zone {
  fill: none;
  stroke-linecap: round;
}
.gauge-track {
  stroke: #e6ebf0;
  stroke-width: 24;
}
.gauge-zone { stroke-width: 18; }
.gauge-zone-risk { stroke: #b93737; }
.gauge-zone-watch { stroke: #a36f00; }
.gauge-zone-good { stroke: #167a55; }
.gauge-needle {
  position: absolute;
  left: 50%;
  top: 64%;
  width: 3px;
  height: 96px;
  border-radius: 999px;
  background: var(--ink);
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(-90deg);
  transition: transform 260ms ease;
}
.gauge-needle.risk { background: var(--red); }
.gauge-needle.watch { background: var(--amber); }
.gauge-needle.good { background: var(--green); }
.gauge-needle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -9px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 14px solid var(--ink);
  transform: translateX(-50%);
}
.gauge-needle.risk::before { border-bottom-color: var(--red); }
.gauge-needle.watch::before { border-bottom-color: var(--amber); }
.gauge-needle.good::before { border-bottom-color: var(--green); }
.gauge-hub {
  position: absolute;
  left: 50%;
  top: 64%;
  width: 18px;
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: white;
  transform: translate(-50%, -50%);
}
.gauge-value {
  position: absolute;
  left: 50%;
  top: 73%;
  display: grid;
  justify-items: center;
  min-width: 180px;
  transform: translateX(-50%);
}
.gauge-value span {
  font-size: 32px;
  line-height: 1;
  font-weight: 800;
}
.gauge-value small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}
.gauge-start,
.gauge-end {
  position: absolute;
  top: 64%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.gauge-start { left: 4px; }
.gauge-end {
  right: 0;
  color: var(--ink);
}
canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.42fr);
  gap: 16px;
}
.panel, .setup-panel { padding: 18px; }
.panel.wide { grid-column: 1 / -1; }
.metric-table { display: grid; gap: 8px; }
.metric-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(2, minmax(90px, 0.55fr)) minmax(100px, 0.55fr) minmax(260px, 1.2fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.metric-row.header {
  background: #e8eef4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.metric-row strong { display: block; }
.metric-row span, .compact-row span, .action-card span, .action-card small { color: var(--muted); font-size: 13px; }
.metric-row b { font-size: 14px; overflow-wrap: anywhere; }
.metric-row .execution-pill {
  justify-self: start;
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 800;
  white-space: nowrap;
}
.metric-row em, .compact-row em, .action-card em {
  justify-self: start;
  border-radius: 8px;
  padding: 6px 8px;
  background: #eef2f5;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}
.metric-row p { margin: 0; font-size: 13px; white-space: pre-line; }

.compact-list, .action-list { display: grid; gap: 10px; }
.compact-row, .action-card {
  display: grid;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.compact-row { grid-template-columns: minmax(0, 1fr) auto; }
.action-card { grid-template-columns: 34px minmax(0, 1fr) auto; align-items: start; }
.action-priority {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--sidebar);
  color: white;
  font-weight: 800;
}
.action-card strong { display: block; }
.action-card p { margin: 6px 0; color: var(--ink); font-size: 14px; }
.empty-state {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 14px;
}
.setup-panel pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; overflow: visible; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .source-panel { margin-left: auto; margin-top: 0; min-width: 260px; }
  .kpi-grid, .main-grid, .visual-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-row { grid-template-columns: minmax(180px, 1fr) repeat(2, minmax(80px, 0.5fr)); }
  .metric-row b:nth-of-type(3), .metric-row p, .metric-row.header p { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .workspace, .sidebar { padding: 18px; }
  .topbar, .panel-header { flex-direction: column; }
  h1 { font-size: 24px; }
  .kpi-grid, .main-grid, .visual-grid, .metric-row, .compact-row, .action-card { grid-template-columns: 1fr; }
  .source-panel { width: 100%; }
}
