/* ============================================================
   Rolling Plan Dashboard — styles
   1. Theme tokens   2. Base   3. Layout   4. Components
   5. Charts         6. Utilities   7. Responsive
   ============================================================ */

/* ---------- 1. Theme tokens ---------- */
:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --card: #ffffff;
  --muted: #ececf0;
  --muted-fg: #717182;
  --accent: #e9ebef;
  --border: rgba(0, 0, 0, 0.1);
  --primary: #030213;
  --primary-fg: #ffffff;
  --input-bg: #f3f3f5;
  --ring: #b3b3b3;

  --sidebar: #fafafa;
  --sidebar-border: #e8e8e8;
  --sidebar-accent: #f0f0f2;

  /* Semantic tones: --t-bg = soft fill, --t-fg = text/icon */
  --blue-bg: #dbeafe;   --blue-fg: #1d4ed8;   --blue: #2563eb;
  --green-bg: #dcfce7;  --green-fg: #15803d;  --green: #16a34a;
  --orange-bg: #ffedd5; --orange-fg: #c2410c; --orange: #ea580c;
  --purple-bg: #f3e8ff; --purple-fg: #7e22ce; --purple: #9333ea;
  --red-bg: #fee2e2;    --red-fg: #b91c1c;
  --yellow-bg: #fef9c3; --yellow-fg: #a16207;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.dark {
  --bg: #1e1e1e;
  --fg: #fafafa;
  --card: #242424;
  --muted: #383838;
  --muted-fg: #a8a8a8;
  --accent: #383838;
  --border: #3a3a3a;
  --primary: #fafafa;
  --primary-fg: #1e1e1e;
  --input-bg: #383838;
  --ring: #707070;

  --sidebar: #262626;
  --sidebar-border: #3a3a3a;
  --sidebar-accent: #383838;

  --blue-bg: #1e2a4a;   --blue-fg: #93c5fd;
  --green-bg: #14321f;  --green-fg: #86efac;
  --orange-bg: #3a2410; --orange-fg: #fdba74;
  --purple-bg: #2e1a3e; --purple-fg: #d8b4fe;
  --red-bg: #3a1a1a;    --red-fg: #fca5a5;
  --yellow-bg: #332a0d; --yellow-fg: #fde047;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; font-weight: 500; }
h2 { font-size: 1.125rem; font-weight: 500; }
h3 { font-size: 1.05rem; font-weight: 500; }
h4 { font-size: 1rem; font-weight: 500; }

button, input, select { font: inherit; color: inherit; }
ul { list-style: none; padding: 0; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon--sm { width: 16px; height: 16px; }

/* ---------- 3. Layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 256px;
  flex: none;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}
.sidebar__brand { padding: 24px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar__brand p { margin-top: 4px; }
.sidebar__nav { flex: 1; padding: 16px; overflow-y: auto; }
.sidebar__section-label { display: flex; align-items: center; gap: 8px; padding: 0 12px; margin: 28px 0 8px; }
.sidebar__footer { padding: 16px; border-top: 1px solid var(--sidebar-border); }

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s;
}
.nav-item:hover:not(:disabled) { background: var(--sidebar-accent); }
.nav-item.is-active { background: var(--accent); font-weight: 500; }
.nav-item.is-locked { opacity: 0.5; cursor: not-allowed; color: var(--muted-fg); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 64px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar__menu { display: none; }
.topbar__actions { display: flex; align-items: center; gap: 12px; }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ---------- 4. Components ---------- */
.view { display: none; flex-direction: column; gap: 24px; }
.view.is-active { display: flex; }

.page-head { display: flex; flex-direction: column; gap: 8px; }
.page-head--row { flex-direction: row; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.section-title { margin-top: 4px; }

/* Search */
.search { position: relative; flex: 1; max-width: 640px; }
.search__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-fg); }
.search input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.search input:focus { outline: 2px solid var(--ring); outline-offset: -1px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}
.btn--primary { background: var(--primary); color: var(--primary-fg); }
.btn--primary:hover { opacity: 0.9; }

.icon-btn {
  display: inline-flex;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent); }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card--tight { padding: 16px; }
.card--stat { gap: 8px; }
.card__head { display: flex; align-items: center; justify-content: space-between; }

/* KPI cards */
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.kpi__value { font-size: 1.875rem; font-weight: 500; margin: 6px 0; }
.kpi__unit { font-size: 1rem; color: var(--muted-fg); margin-left: 4px; }
.kpi__icon {
  display: inline-flex;
  padding: 12px;
  border-radius: var(--radius-sm);
}
.kpi__icon .icon { width: 24px; height: 24px; }

/* Grids */
.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, 1fr); gap: 24px; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--3-2 { grid-template-columns: 2fr 1fr; gap: 24px; }

/* Badges & tones */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--muted);
  color: var(--fg);
}
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; }

.tone-blue   { background: var(--blue-bg);   color: var(--blue-fg); }
.tone-green  { background: var(--green-bg);  color: var(--green-fg); }
.tone-orange { background: var(--orange-bg); color: var(--orange-fg); }
.tone-purple { background: var(--purple-bg); color: var(--purple-fg); }
.tone-red    { background: var(--red-bg);    color: var(--red-fg); }
.tone-yellow { background: var(--yellow-bg); color: var(--yellow-fg); }
.tone-neutral { background: var(--bg); color: var(--fg); border: 1px solid var(--border); }

/* Callouts */
.callout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
}
.callout--block {
  display: block;
  padding: 16px;
  border-radius: var(--radius-sm);
}
.callout--block p + p { margin-top: 6px; }
.callout .icon, .callout--block .icon { color: inherit; }

/* Dot labels & stats */
.dot { width: 12px; height: 12px; border-radius: 999px; display: inline-block; }
.dot--green { background: var(--green); }
.dot--blue { background: var(--blue); }
.dot--orange { background: var(--orange); }
.dot-label { display: flex; align-items: center; gap: 8px; }
.stat { font-size: 1.5rem; font-weight: 500; margin-top: 8px; }

/* Lists */
.row-list { display: flex; flex-direction: column; gap: 12px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--muted);
  border-radius: var(--radius-sm);
}
.policy { padding: 16px; background: var(--muted); border-radius: var(--radius-sm); }
.policy__head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }

.activity-list { display: flex; flex-direction: column; gap: 12px; }
.activity-item { padding: 12px; background: var(--muted); border-radius: var(--radius-sm); }
.activity-item__top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.activity-item__meta { display: flex; justify-content: space-between; }

/* Legends */
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; justify-content: space-between; font-size: 0.875rem; }
.legend__name { display: flex; align-items: center; gap: 8px; color: var(--muted-fg); }
.legend-row { display: flex; gap: 24px; flex-wrap: wrap; }
.legend-row__item { display: flex; align-items: center; gap: 8px; color: var(--muted-fg); font-size: 0.875rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { font-size: 0.875rem; font-weight: 400; color: var(--muted-fg); }
.data-table tbody tr:hover { background: var(--muted); }
.data-table .center { text-align: center; }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.filter-bar--years { align-items: flex-end; }
.filter-bar select, .field select {
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.875rem; color: var(--muted-fg); }
.vs { padding-bottom: 9px; }

/* Toggle group */
.toggle-group { display: flex; gap: 8px; }
.toggle {
  padding: 9px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--muted);
  cursor: pointer;
}
.toggle.is-active { background: var(--primary); color: var(--primary-fg); }

/* SDO detail */
.sdo-detail__head { display: flex; align-items: center; gap: 12px; }
.sdo-detail__group { display: flex; flex-direction: column; gap: 4px; }
.sdo-list { display: flex; flex-direction: column; gap: 12px; }
.sdo-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.sdo-item:hover { background: var(--accent); }
.sdo-item.is-selected { background: var(--blue-bg); border-color: var(--blue-fg); }
.sdo-item__value { font-size: 1.5rem; font-weight: 500; text-align: right; }

.network { position: relative; background: var(--muted); border-radius: var(--radius-sm); }
.network__hint { position: absolute; left: 16px; bottom: 12px; }
.network circle { cursor: pointer; transition: opacity 0.15s; }
.network circle:hover { opacity: 1 !important; }

/* Change visualisation */
.change-row { margin-bottom: 16px; }
.change-row__head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.change-bar { display: flex; height: 32px; border-radius: var(--radius-sm); overflow: hidden; }
.change-bar span {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.75rem;
}
.change-bar .seg-new { background: var(--green); }
.change-bar .seg-mod { background: var(--blue); }
.change-bar .seg-rem { background: var(--orange); }

.intensity { display: flex; align-items: center; gap: 8px; }
.intensity__track { flex: 1; height: 8px; background: var(--muted); border-radius: 999px; }
.intensity__fill { height: 8px; background: var(--blue); border-radius: 999px; }

/* Signals */
.signal-list { display: flex; flex-direction: column; gap: 12px; }
.signal {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.signal--gap { border-left-color: var(--orange); }
.signal--overlap { border-left-color: var(--blue); }
.signal__head { display: flex; justify-content: space-between; gap: 16px; }
.signal__title { display: flex; gap: 12px; }
.signal__foot {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.signal__action { flex: 1; }
.signal__metrics { display: flex; gap: 16px; }

/* Charts */
.chart { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg text { fill: var(--muted-fg); font-size: 11px; }
.chart-grid { stroke: var(--border); stroke-dasharray: 3 3; }
.chart-axis { stroke: var(--muted-fg); }

/* ---------- 6. Utilities ---------- */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--muted-fg); }
.text-pos { color: var(--green-fg); }
.text-link { color: var(--blue); }
.text-orange { color: var(--orange); }
.measure { max-width: 720px; }

/* ---------- 7. Responsive ---------- */
@media (max-width: 1024px) {
  .grid--3-2, .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .content { padding: 16px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .topbar__menu { display: inline-flex; }
  .grid--4 { grid-template-columns: 1fr; }
  .btn span { display: none; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar.is-open ~ .sidebar-overlay { display: block; }

  .page-head--row { flex-direction: column; }
  .signal__head, .signal__foot { flex-direction: column; align-items: flex-start; }
}

/* Backend connection indicator (top bar) */
.api-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--bg-2, transparent);
  white-space: nowrap;
}
.api-status[data-state="live"] {
  color: #047857;
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}
.api-status[data-state="static"] {
  color: #92400e;
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
}
