:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #111827;
  --text: #1f2937;
  --muted: #64748b;
  --line: #d9e2ef;
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #15803d;
  --amber: #b45309;
  --red: #be123c;
  --violet: #7c3aed;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 14px 28px;
  background: rgba(17, 24, 39, 0.96);
  color: #fff;
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #9fb3c8;
  font-size: 12px;
}

nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

nav a {
  color: #e5edf7;
  text-decoration: none;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: clamp(30px, 3vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.48;
}

.overview {
  display: grid;
  grid-template-columns: minmax(320px, 0.44fr) minmax(680px, 1.56fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 14px;
}

.headline {
  min-height: 100%;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#heroCopy {
  max-width: 640px;
  margin-bottom: 0;
  font-size: 16px;
}

.status {
  display: inline-flex;
  margin-bottom: 14px;
  border-radius: 999px;
  padding: 7px 11px;
  background: #ffe4e6;
  color: var(--red);
  font-weight: 800;
  font-size: 13px;
}

.meta-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.meta-strip span,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card,
.phase-card,
.chart-panel,
.table-panel,
.history-summary,
.method article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card {
  display: grid;
  width: 100%;
  min-height: 134px;
  align-content: space-between;
  padding: 15px;
  overflow: hidden;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.kpi-card:hover,
.kpi-card:focus-visible {
  border-color: rgba(37, 99, 235, 0.48);
  outline: 2px solid rgba(37, 99, 235, 0.14);
  outline-offset: 2px;
  transform: translateY(-1px);
}

.kpi-card span,
.phase-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: clamp(25px, 3vw, 36px);
  line-height: 1;
}

.kpi-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi-card.danger strong {
  color: var(--red);
}

.kpi-card.warning strong {
  color: var(--amber);
}

.kpi-spark {
  height: 5px;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.kpi-spark i {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  background: var(--c, var(--blue));
}

.toolbar {
  position: sticky;
  top: 65px;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(16px);
}

.toolbar .is-hidden {
  display: none;
}

.date-filter input,
.history-actions select {
  width: 100%;
}

.date-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 6px;
}

.date-input-row button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.date-input-row button:hover,
.date-input-row button:focus-visible {
  border-color: var(--blue);
  color: var(--blue);
  outline: 2px solid rgba(37, 99, 235, 0.16);
  outline-offset: 1px;
}

.history-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.history-actions label {
  display: grid;
  gap: 5px;
  min-width: min(260px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.export-panel {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.export-panel h2 {
  margin-bottom: 3px;
}

.export-panel p {
  margin-bottom: 0;
  font-size: 14px;
}

.export-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.export-actions button {
  min-height: 38px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 8px 11px;
  background: #eff6ff;
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
}

.export-actions button:hover,
.export-actions button:focus-visible {
  border-color: var(--blue);
  outline: 2px solid rgba(37, 99, 235, 0.16);
  outline-offset: 1px;
}

.data-density {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.data-density article {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.data-density span,
.data-density small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.data-density strong {
  display: block;
  margin: 6px 0;
  color: var(--ink);
  font-size: clamp(20px, 1.8vw, 25px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.data-density article[data-level="good"] strong {
  color: var(--green);
}

.data-density article[data-level="warn"] strong {
  color: var(--amber);
}

.insight-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.insight-strip button {
  position: relative;
  min-width: 0;
  min-height: 118px;
  padding: 15px 15px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}

.insight-strip button::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent, var(--blue));
}

.insight-strip button:hover,
.insight-strip button:focus-visible {
  border-color: #93c5fd;
  outline: 2px solid rgba(37, 99, 235, 0.16);
  outline-offset: 1px;
}

.insight-strip span,
.insight-strip small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.insight-strip strong {
  display: block;
  margin: 8px 0 7px;
  color: var(--ink);
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.insight-strip button[data-level="good"] {
  --accent: var(--green);
}

.insight-strip button[data-level="good"] strong {
  color: var(--green);
}

.insight-strip button[data-level="warn"] {
  --accent: var(--amber);
}

.insight-strip button[data-level="warn"] strong {
  color: var(--amber);
}

.insight-strip button[data-level="bad"] {
  --accent: var(--red);
}

.insight-strip button[data-level="bad"] strong {
  color: var(--red);
}

.insight-strip button[data-level="neutral"] {
  --accent: var(--blue);
}

.toolbar label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.toolbar select,
.toolbar input,
.history-actions select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--text);
}

.current-band {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.overview .current-band {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0;
}

.live-status {
  scroll-margin-top: 96px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.live-status article {
  display: grid;
  align-content: space-between;
  min-width: 0;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.live-status span,
.live-status small {
  color: var(--muted);
  font-size: 13px;
}

.live-status strong {
  display: block;
  margin: 6px 0;
  color: var(--ink);
  font-size: clamp(21px, 2vw, 26px);
  line-height: 1;
  overflow-wrap: anywhere;
}

.live-status.online strong {
  color: var(--green);
}

.live-status.stale strong {
  color: var(--amber);
}

.live-status.offline strong {
  color: var(--red);
}

.phase-card {
  min-height: 154px;
  padding: 13px;
}

.overview .phase-card {
  min-height: 164px;
  padding: 15px;
}

.online-empty {
  grid-column: 1 / -1;
}

.phase-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
  margin-bottom: 12px;
}

.phase-card h3 {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 15px;
}

.phase-card strong {
  display: block;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.overview .phase-card strong {
  font-size: clamp(32px, 3.8vw, 46px);
}

.meter {
  position: relative;
  height: 12px;
  margin: 13px 0 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fee2e2 0 18%, #dcfce7 18% 82%, #fee2e2 82% 100%);
  overflow: hidden;
}

.meter i {
  position: absolute;
  top: -2px;
  width: 4px;
  height: 16px;
  border-radius: 999px;
  background: var(--ink);
  left: var(--x, 50%);
}

.phase-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.phase-meta span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-summary {
  padding: 16px;
  margin-bottom: 14px;
}

.history-summary .kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.history-summary .kpi-card {
  min-height: 104px;
  padding: 12px;
  box-shadow: none;
}

.history-summary .kpi-card strong {
  font-size: clamp(21px, 1.9vw, 27px);
}

.history-summary .kpi-spark {
  margin-top: 10px;
}

.chart-layout,
.table-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(380px, 0.82fr);
  gap: 14px;
  margin-bottom: 14px;
}

.chart-panel,
.table-panel {
  padding: 16px;
  min-width: 0;
}

.full-width {
  margin-bottom: 14px;
}

.chart-wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.panel-head p {
  margin-bottom: 0;
  font-size: 14px;
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c);
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 260px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-table-wrap {
  max-height: 560px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3f8;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

tbody tr.clickable-row {
  cursor: pointer;
}

tbody tr.clickable-row:hover,
tbody tr.clickable-row:focus-visible {
  background: #f8fafc;
  outline: 2px solid rgba(37, 99, 235, 0.18);
  outline-offset: -2px;
}

tbody tr.has-events {
  background: #fff7ed;
}

tbody tr.has-events:hover,
tbody tr.has-events:focus-visible {
  background: #ffedd5;
}

.row-detail {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  background: #fff;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.row-detail:hover,
.row-detail:focus-visible {
  border-color: var(--blue);
  outline: 2px solid rgba(37, 99, 235, 0.16);
  outline-offset: 1px;
}

th {
  color: #475569;
  font-weight: 800;
}

th button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font-weight: inherit;
}

td.numeric,
th.numeric button {
  justify-content: flex-end;
  text-align: right;
}

.sort-mark {
  color: var(--blue);
  font-size: 11px;
}

.risk {
  color: var(--red);
  font-weight: 800;
}

.warn {
  color: var(--amber);
  font-weight: 800;
}

.ok {
  color: var(--green);
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.method {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.method article {
  padding: 16px;
}

.detail-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.detail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
}

.detail-shell {
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.detail-shell header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.detail-shell h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

.detail-shell p {
  margin-bottom: 0;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.detail-body {
  padding: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.detail-grid article {
  min-width: 0;
  min-height: 94px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-grid span,
.detail-grid small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  display: block;
  margin: 7px 0 4px;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.detail-grid article.risk strong {
  color: var(--red);
}

.detail-grid article.warn strong {
  color: var(--amber);
}

.detail-grid article.ok strong {
  color: var(--green);
}

.detail-section {
  margin-top: 16px;
}

.detail-section h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 15px;
}

.mini-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mini-table {
  min-width: 640px;
}

.empty-note {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.empty-cell {
  padding: 18px;
  color: var(--muted);
  text-align: left;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 28px 32px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .overview,
  .chart-layout,
  .table-layout,
  .method {
    grid-template-columns: 1fr;
  }

  .overview .current-band,
  .current-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .live-status {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .kpi-grid,
  .data-density,
  .insight-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  footer,
  .panel-head,
  .export-panel {
    display: grid;
  }

  .topbar {
    position: static;
    padding: 14px;
  }

  nav {
    justify-content: start;
  }

  main {
    padding: 12px;
  }

  .headline {
    min-height: auto;
    padding: 18px;
  }

  .kpi-grid,
  .data-density,
  .insight-strip,
  .toolbar,
  .overview .current-band,
  .current-band,
  .live-status {
    grid-template-columns: 1fr;
  }

  .toolbar {
    position: static;
  }

  .export-actions {
    justify-content: stretch;
  }

  .export-panel {
    grid-template-columns: 1fr;
  }

  .export-actions button {
    flex: 1 1 150px;
  }

  .chart-panel,
  .table-panel,
  .method article {
    padding: 13px;
  }

  .table-wrap {
    max-height: 460px;
  }

  table {
    min-width: 760px;
  }

  .row-detail {
    min-width: 68px;
  }

  .detail-dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
  }

  .detail-shell {
    max-height: 100vh;
    border-radius: 0;
  }

  .detail-shell header {
    padding: 14px;
  }

  .detail-body {
    padding: 12px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .mini-table {
    min-width: 620px;
  }
}
