:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f3ec;
  --ink: #17211b;
  --muted: #647067;
  --line: #d7ded6;
  --accent: #087f6f;
  --accent-strong: #056456;
  --gold: #c58b16;
  --danger: #bf3328;
  --good: #118447;
  --shadow: 0 16px 40px rgba(23, 33, 27, 0.12);
}

body.dark {
  color-scheme: dark;
  --bg: #171a18;
  --surface: #222720;
  --surface-strong: #2c332b;
  --ink: #f4f7ef;
  --muted: #b9c3b7;
  --line: #3a4539;
  --accent: #21a48f;
  --accent-strong: #46c2ae;
  --gold: #e0aa3b;
  --danger: #ed6d5f;
  --good: #5fd18d;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; border-radius: 8px; }

button {
  border: 0;
  background: var(--accent);
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

button:hover { background: var(--accent-strong); }
button.secondary { background: var(--surface-strong); color: var(--ink); border: 1px solid var(--line); }
button.danger-button { color: var(--danger); }

.app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--surface); padding: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: grid; grid-template-columns: 74px 1fr; gap: 14px; align-items: center; margin-bottom: 26px; }
.brand img { width: 74px; height: 74px; object-fit: cover; border-radius: 8px; }
.brand h1, .topbar h2 { margin: 2px 0 0; line-height: 1.05; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.75rem;
  font-weight: 900;
}

.nav-list { display: grid; gap: 8px; }
.nav-item { width: 100%; text-align: left; background: transparent; color: var(--ink); border: 1px solid transparent; }
.nav-item.active { background: var(--surface-strong); border-color: var(--line); color: var(--accent-strong); }

.data-discipline { margin-top: 24px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); }
.data-discipline ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); }
.main { padding: 24px; min-width: 0; }
.topbar, .filters, .panel-header, .button-row { display: flex; align-items: center; gap: 12px; }
.button-row { flex-wrap: wrap; }
.topbar { justify-content: space-between; margin-bottom: 18px; }
.topbar-actions, .filters { display: flex; flex-wrap: wrap; gap: 12px; }
.role-badge {
  min-height: 42px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  display: grid;
  align-content: center;
}
.role-badge span { color: var(--muted); font-size: 0.72rem; font-weight: 900; text-transform: uppercase; }
.role-badge strong { font-size: 0.92rem; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
input, select, textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 10px;
  outline-color: var(--accent);
  min-width: 0;
}
textarea { resize: vertical; }
button:disabled, input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.filters { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 18px; }
.filters label { min-width: 150px; flex: 1; }
.view { display: none; }
.view.active { display: block; }
.kpi-grid, .panel-grid { display: grid; gap: 16px; }
.kpi-grid { grid-template-columns: repeat(6, minmax(140px, 1fr)); margin-bottom: 16px; }

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

.kpi-card { min-height: 124px; padding: 16px; display: grid; align-content: space-between; }
.kpi-card strong { display: block; font-size: clamp(1.3rem, 2.2vw, 2rem); line-height: 1; margin: 10px 0 4px; }
.kpi-card span { color: var(--muted); font-size: 0.8rem; }
.positive { color: var(--good); }
.negative { color: var(--danger); }
.panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel.wide { grid-column: 1 / -1; }
.panel, .form-panel { padding: 18px; }
.panel-header { justify-content: space-between; margin-bottom: 14px; }
.panel-header h3, .form-panel h3 { margin: 0; }
.panel-header span, .helper { color: var(--muted); font-size: 0.86rem; }

.split-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.form-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-panel h3, .form-panel .full { grid-column: 1 / -1; }
.form-panel button { width: 100%; }
.table-panel { min-width: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 10px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
}

.pill.overdue { background: rgba(191, 51, 40, 0.14); color: var(--danger); }
.pill.good { background: rgba(17, 132, 71, 0.14); color: var(--good); }
.bar-chart, .stack-list, .activity-list, .leaderboard { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 84px; gap: 12px; align-items: center; }
.bar-track { height: 28px; background: var(--surface-strong); border-radius: 8px; overflow: hidden; display: flex; }
.bar { min-width: 2px; height: 100%; }
.bar.revenue { background: var(--accent); }
.bar.profit { background: var(--good); }
.bar.spend { background: var(--gold); }
.stack-item, .activity-item, .leader-row { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); }
.stack-item { display: grid; gap: 8px; }
.meter { height: 9px; background: rgba(100, 112, 103, 0.22); border-radius: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.leader-row { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 12px; }
.avatar { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; }
.empty-state { color: var(--muted); padding: 18px; border: 1px dashed var(--line); border-radius: 8px; }

@media (max-width: 1120px) {
  .app-shell, .split-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 12px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand {
    grid-template-columns: 48px 1fr;
    gap: 10px;
    margin-bottom: 10px;
  }
  .brand img {
    width: 48px;
    height: 48px;
  }
  .brand h1 {
    font-size: 1.05rem;
  }
  .nav-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }
  .nav-list::-webkit-scrollbar {
    display: none;
  }
  .nav-item {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 13px;
    scroll-snap-align: start;
    white-space: nowrap;
  }
  .data-discipline { display: none; }
  .main {
    padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
  }
  .topbar, .panel-header { align-items: stretch; flex-direction: column; }
  .topbar-actions, .filters, .form-panel { display: grid; grid-template-columns: 1fr; }
  .role-badge { min-height: 48px; }
  button, input, select, textarea { min-height: 46px; }
  .kpi-grid, .panel-grid { grid-template-columns: 1fr; }
  .kpi-card { min-height: 104px; }
  .panel, .form-panel { padding: 14px; }
  .filters { padding: 12px; }
  .filters label { min-width: 0; }
  .bar-row { grid-template-columns: 1fr; }
  .leader-row {
    grid-template-columns: 42px 1fr;
  }
  .leader-row span {
    grid-column: 1 / -1;
  }
}
