:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --field: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #d9e2ec;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --risk: #c2410c;
  --soft-accent: #f0fdfa;
  --button: #101828;
  --button-ink: #ffffff;
  --secondary-button: #e2e8f0;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --panel: #111827;
  --field: #0f172a;
  --ink: #f8fafc;
  --muted: #a7b4c8;
  --line: #243247;
  --accent: #2dd4bf;
  --accent-2: #60a5fa;
  --risk: #fb923c;
  --soft-accent: rgba(45, 212, 191, 0.12);
  --button: #e5eefc;
  --button-ink: #0b1120;
  --secondary-button: #263449;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--button);
  color: var(--button-ink);
  cursor: pointer;
}

button.secondary {
  background: var(--secondary-button);
  color: var(--ink);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--field);
  color: var(--ink);
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  padding: 24px 18px;
  background: #0f172a;
  color: #dbeafe;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar strong {
  color: #fff;
  font-size: 18px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar a {
  border-radius: 8px;
  padding: 10px 12px;
  color: #b6c7e5;
}

.sidebar a.active,
.sidebar a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.logout {
  margin-top: auto;
}

.theme-toggle {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.app-shell {
  margin-left: 260px;
  padding: 28px;
}

.page-head,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.08;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.period-controls,
.filter-row,
.grid-form {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.mapping-form,
.commit-row {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.grid-form label {
  min-width: 180px;
}

.check {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  min-height: auto;
}

.hero-metric {
  min-height: 190px;
  border-radius: 8px;
  padding: 28px;
  margin-bottom: 18px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.95), rgba(37, 99, 235, 0.92)),
    radial-gradient(circle at top right, rgba(255,255,255,0.24), transparent 35%);
  box-shadow: var(--shadow);
  display: flex;
  align-items: end;
}

.hero-metric span,
.metric-card span {
  color: inherit;
  opacity: 0.78;
  font-size: 13px;
  font-weight: 700;
}

.hero-metric strong {
  display: block;
  margin-top: 8px;
  font-size: 52px;
  line-height: 1;
}

.hero-metric p {
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.84);
}

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

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

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1.1;
}

.metric-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.panel {
  padding: 18px;
}

.panel.wide {
  margin-bottom: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
}

.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.import-table input {
  width: 100%;
  min-width: 120px;
}

.import-diagnostics {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-accent);
  margin-bottom: 14px;
  padding: 12px;
}

.import-diagnostics ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.import-diagnostics li {
  margin: 6px 0;
}

.import-diagnostics small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.compact-list,
.insight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.compact-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

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

.inline-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.subscription-editor-list {
  display: grid;
  gap: 14px;
}

.subscription-editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.subscription-editor strong {
  min-height: 42px;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.candidate-editor-list {
  display: grid;
  gap: 14px;
}

.candidate-editor {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) auto auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.compact-list small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.insight-list li {
  border-left: 3px solid var(--accent);
  background: var(--soft-accent);
  border-radius: 8px;
  padding: 12px;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.fixed-summary {
  display: grid;
  gap: 3px;
  margin-bottom: 14px;
}

.fixed-summary strong {
  font-size: 28px;
  line-height: 1.1;
}

.fixed-summary small {
  color: var(--muted);
}

.bar-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-bottom: 12px;
}

.bar-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.bar-row i {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.budget-list {
  display: grid;
  gap: 14px;
}

.budget-row {
  display: grid;
  gap: 8px;
}

.budget-row span {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.budget-row i {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.budget-row b {
  display: block;
  height: 100%;
}

.empty,
.flash,
.error {
  color: var(--muted);
}

.flash,
.error {
  border-radius: 8px;
  padding: 12px;
  background: #fff7ed;
  color: var(--risk);
}

.login-shell,
.setup-card {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel,
.setup-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1,
.setup-card h1 {
  margin: 0 0 8px;
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

canvas {
  max-height: 340px;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell {
    margin-left: 0;
    padding: 18px;
  }

  .metric-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .page-head {
    display: grid;
  }

  .subscription-editor {
    grid-template-columns: 1fr;
  }

  .candidate-editor {
    grid-template-columns: 1fr;
  }

  .hero-metric strong {
    font-size: 38px;
  }
}
