:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --text: #101828;
  --muted: #667085;
  --line: #d8dee7;
  --teal: #0d9488;
  --green: #16a34a;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --violet: #7c3aed;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.09);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d14;
  --surface: #10141f;
  --surface-2: #151b28;
  --surface-3: #1c2433;
  --text: #f8fafc;
  --muted: #9aa4b2;
  --line: rgba(255, 255, 255, 0.11);
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.brand-title {
  font-weight: 800;
  font-size: 14px;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.role-card {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.role-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.nav {
  margin-top: 18px;
  display: grid;
  gap: 6px;
}

.nav-button {
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font-weight: 700;
  text-align: left;
}

.nav-button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav-button.active {
  background: var(--teal);
  color: #fff;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  padding: 14px 16px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.2;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 750;
}

.button:hover {
  border-color: var(--teal);
}

.button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.button.danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.mobile-nav {
  display: none;
  gap: 8px;
  overflow-x: auto;
  padding-top: 12px;
}

.mobile-nav .nav-button {
  width: auto;
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
}

.content {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 150px;
}

select,
input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

select,
input {
  height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 72px;
  padding: 10px;
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--teal);
}

.grid {
  display: grid;
  gap: 16px;
}

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

.two-col {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
}

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

.four-col {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.kpi-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.panel-header {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 14px;
  font-weight: 800;
}

.kpi-card {
  padding: 14px;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--teal);
}

.kpi-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2), var(--shadow);
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.icon-box {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 900;
}

.delta {
  align-self: start;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.delta.good {
  background: rgba(22, 163, 74, 0.14);
  color: var(--green);
}

.delta.bad {
  background: rgba(220, 38, 38, 0.14);
  color: var(--red);
}

.kpi-label {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-value {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 850;
}

.kpi-sub {
  margin-top: 4px;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart.small {
  height: 250px;
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.axis {
  stroke: color-mix(in srgb, var(--muted) 40%, transparent);
}

.grid-line {
  stroke: color-mix(in srgb, var(--muted) 18%, transparent);
}

.tick,
.legend,
.chart-label {
  fill: var(--muted);
  font-size: 11px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th {
  padding: 0 12px 10px 0;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
}

td {
  border-top: 1px solid var(--line);
  padding: 12px 12px 12px 0;
  color: var(--muted);
  font-size: 13px;
}

td strong {
  color: var(--text);
}

tr.clickable:hover {
  background: var(--surface-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.insight-list,
.alert-list,
.stack-list {
  display: grid;
  gap: 10px;
}

.list-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.list-card.clickable:hover {
  border-color: var(--teal);
}

.list-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
}

.list-text {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.progress-row {
  display: grid;
  gap: 6px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.progress-meta strong {
  color: var(--text);
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.heatmap {
  overflow-x: auto;
}

.heatmap-grid {
  min-width: 640px;
  display: grid;
  grid-template-columns: 180px repeat(4, 1fr);
  gap: 8px;
}

.heatmap-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.heatmap-label,
.heatmap-cell {
  min-height: 42px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  font-weight: 800;
}

.heatmap-label {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.55);
}

.drawer {
  position: fixed;
  z-index: 90;
  top: 0;
  right: 0;
  width: min(620px, 100vw);
  height: 100vh;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 18px;
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.24);
}

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

.drawer h2 {
  margin: 4px 0 10px;
}

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

.detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.detail span {
  color: var(--muted);
  font-size: 12px;
}

.detail strong {
  display: block;
  margin-top: 4px;
}

.comment-box {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.comment-box input {
  flex: 1;
}

.hidden {
  display: none !important;
}

#print-report {
  display: none;
}

@media (max-width: 1180px) {
  .kpi-grid,
  .four-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-nav {
    display: flex;
  }

  .topbar-row {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    width: 100%;
  }

  .button {
    flex: 1 1 auto;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  .field {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .kpi-grid,
  .four-col,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .content,
  .topbar {
    padding: 12px;
  }

  h1 {
    font-size: 18px;
  }
}

@media print {
  body {
    background: #fff;
    color: #111827;
  }

  #app {
    display: none;
  }

  #print-report {
    display: block;
    padding: 24px;
    font-family: Arial, sans-serif;
  }

  #print-report h1 {
    margin: 0 0 8px;
    font-size: 22px;
  }

  #print-report h2 {
    margin: 18px 0 8px;
    font-size: 15px;
  }

  #print-report .metric-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 16px;
  }

  #print-report .metric {
    border: 1px solid #d0d5dd;
    padding: 10px;
  }

  #print-report table {
    width: 100%;
    border-collapse: collapse;
  }

  #print-report th,
  #print-report td {
    border: 1px solid #d0d5dd;
    padding: 8px;
    color: #111827;
    font-size: 11px;
  }
}
