:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --text: #1F1F1F;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --accent: #2563EB;
  --success: #16A34A;
  --danger: #DC2626;
  --corridor-fill: rgba(37, 99, 235, 0.10);
  --event-marker: #F59E0B;
  --sidebar-w: 240px;
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

a { text-decoration: none; color: inherit; }

/* ── Header ─────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.app-header__title {
  font-size: 24px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.app-header__title i { color: var(--accent); font-size: 20px; }
.app-header__project { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 360px; }
.app-header__actions { margin-left: auto; }

/* ── Mobile step tabs ───────────────────────────────────────────── */
.mobile-steps {
  display: flex;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  gap: 6px;
}
.mobile-steps__item {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.mobile-steps__item.active { background: var(--corridor-fill); color: var(--accent); }

/* ── Layout ─────────────────────────────────────────────────────── */
.app-body {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-direction: column;
  padding: 20px 12px;
  gap: 4px;
}
.sidebar__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 0 10px 10px;
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text);
}
.sidebar__item:hover { background: var(--bg); }
.sidebar__item.active { background: var(--corridor-fill); color: var(--accent); }
.sidebar__num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 22px;
}
.sidebar__item.active .sidebar__num { background: var(--accent); color: #fff; }

.main-area {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.events-panel {
  width: 300px;
  flex: 0 0 300px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}
.events-panel__head, .events-mobile .events-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.events-panel__head h2 { font-size: 16px; font-weight: 600; margin: 0; }

.events-mobile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

.events-list { display: flex; flex-direction: column; gap: 10px; }
.event-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  position: relative;
}
.event-item__title { font-weight: 600; margin-bottom: 2px; }
.event-item__meta { color: var(--text-muted); font-size: 12px; }
.event-item__badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
  margin-top: 6px;
}
.event-item__badge.initiative { background: rgba(37,99,235,0.10); color: var(--accent); }
.event-item__badge.external { background: rgba(245,158,11,0.15); color: #92600a; }
.event-item__delete {
  position: absolute; top: 8px; right: 8px;
  border: none; background: none; color: var(--text-muted); cursor: pointer;
}
.event-item__delete:hover { color: var(--danger); }

/* ── Empty state ────────────────────────────────────────────────── */
.empty-state { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.empty-state__card {
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
}
.empty-state__icon { font-size: 40px; color: var(--accent); margin-bottom: 14px; }
.empty-state__card h1 { font-size: 24px; font-weight: 600; margin-bottom: 10px; }
.empty-state__steps { list-style: none; padding: 0; margin: 22px 0; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.empty-state__steps li { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.badge-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--corridor-fill); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; flex: 0 0 26px;
}
.empty-state__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ── Overview widgets ───────────────────────────────────────────── */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 767px) {
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.metric-card__label { font-size: 13px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.metric-card__value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.metric-card__sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.metric-card__value.is-bad { color: var(--danger); }
.metric-card__value.is-good { color: var(--success); }

/* ── Chart card ─────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.chart-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.chart-card__head h2 { font-size: 16px; font-weight: 600; margin: 0; }
.chart-card__controls { display: flex; align-items: center; gap: 8px; }
.chart-card__controls select { width: auto; }
.chart-card__body { position: relative; }
.chart-scroll { overflow-x: auto; }
.chart-scroll canvas { min-width: 640px; }
.chart-loading {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--text-muted); font-weight: 600;
  z-index: 5;
  border-radius: 12px;
}

/* ── Tabs / tables ──────────────────────────────────────────────── */
.tabs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 18px 18px;
}
.tabs-card .nav-tabs { border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs-card .nav-link { color: var(--text-muted); font-weight: 600; font-size: 14px; }
.tabs-card .nav-link.active { color: var(--accent); border-color: var(--border) var(--border) var(--surface); }

.table-scroll { overflow-x: auto; }
.data-table, .reconciliation-table {
  font-size: 13px;
  width: 100%;
}
.data-table th, .reconciliation-table th {
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.data-table td, .reconciliation-table td { font-variant-numeric: tabular-nums; }
.reconciliation-table tbody tr { transition: background-color .15s ease; }
.reconciliation-table tbody tr:hover { background: var(--bg); }
.reconciliation-table tr.in-corridor td.status-cell { color: var(--success); }
.reconciliation-table tr.out-corridor td.status-cell { color: var(--danger); }
.reconciliation-table tr.out-corridor { background: rgba(220,38,38,0.05); }
.reconciliation-table tr.in-corridor { background: rgba(22,163,74,0.05); }
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 12px;
}
.status-pill.ok { background: rgba(22,163,74,0.12); color: var(--success); }
.status-pill.bad { background: rgba(220,38,38,0.12); color: var(--danger); }
.status-pill.pending { background: var(--border); color: var(--text-muted); }

/* ── Decomposition ──────────────────────────────────────────────── */
.decomposition-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
}
.decomp-panel h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.event-coef-panel { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.event-coef-panel h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.event-coef-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; border-bottom: 1px dashed var(--border); }

/* ── Upload modal ───────────────────────────────────────────────── */
.upload-progress { margin-top: 12px; display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.upload-errors {
  margin-top: 12px;
  background: rgba(220,38,38,0.06);
  border: 1px solid rgba(220,38,38,0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  max-height: 200px;
  overflow-y: auto;
}
.upload-errors h6 { color: var(--danger); font-weight: 700; margin-bottom: 6px; }
.upload-errors ul { margin: 0; padding-left: 18px; }

/* ── Event popover ──────────────────────────────────────────────── */
.event-popover {
  position: fixed;
  z-index: 1090;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  max-width: 260px;
  pointer-events: none;
}
.event-popover strong { color: var(--event-marker); }

/* Buttons with disabled state (explicit, on top of Bootstrap defaults) */
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-spinner { margin-right: 4px; }

/* Collapsible reveal for decomposition tab */
#tab-decomposition.tab-pane { transition: opacity .25s ease; }

/* Focus visibility */
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 767px) {
  .sidebar { display: none !important; }
  .app-header__project { max-width: 160px; }
  .app-header__title span { display: none; }
}
