:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #161e28;
  --panel-3: #1b2531;
  --line: #263241;
  --line-soft: #1c2633;
  --text: #f5f7fb;
  --muted: #9aa7b8;
  --faint: #647286;
  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);
  --orange: #fb923c;
  --rose: #fb7185;
  --blue: #60a5fa;
  --violet: #a78bfa;
  --green: #86efac;
  --shadow: 0 20px 54px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 24% -10%, rgba(45, 212, 191, 0.12), transparent 34%),
    linear-gradient(180deg, #0d1219 0%, var(--bg) 38%, #080b10 100%);
  color: var(--text);
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 20px;
}

.rail {
  position: sticky;
  top: 20px;
  display: grid;
  align-content: start;
  gap: 10px;
  height: calc(100vh - 40px);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 24, 32, 0.78);
  box-shadow: var(--shadow);
}

.mark,
.rail-button {
  display: grid;
  width: 54px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  letter-spacing: 0;
  font-weight: 900;
}

.mark {
  border: 1px solid rgba(45, 212, 191, 0.7);
  background: rgba(45, 212, 191, 0.12);
  color: #99f6e4;
}

.rail-button {
  border: 1px solid transparent;
  background: #151d28;
  color: #c7d2e1;
  font-size: 0.82rem;
}

.rail-button.active {
  border-color: rgba(45, 212, 191, 0.4);
  background: #1d2b36;
  color: #e7fffb;
}

.workspace {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

h1 {
  margin-top: 5px;
  font-size: clamp(1.9rem, 3vw, 2.75rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.15;
}

.top-actions,
.segmented,
.control-row,
.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.chip,
.chart-mode,
.button-chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(22, 30, 40, 0.86);
  color: #cbd5e1;
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.button.primary,
.chart-mode.active {
  border-color: rgba(45, 212, 191, 0.7);
  background: var(--teal-soft);
  color: #e7fffb;
}

.button.secondary {
  background: var(--panel-2);
  color: var(--text);
}

.button.warn {
  border-color: rgba(251, 146, 60, 0.45);
  background: rgba(251, 146, 60, 0.12);
  color: #fed7aa;
}

.button:disabled,
.button-chip:disabled,
.delete-row:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.compact-control {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  text-transform: uppercase;
}

.compact-control input,
.compact-control select,
.select-mock,
.entry-form input,
.entry-form select,
.entry-form textarea {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
  color: #d8e2ef;
  outline: none;
  padding: 8px 9px;
}

.compact-control input:focus,
.compact-control select:focus,
.select-mock:focus,
.entry-form input:focus,
.entry-form select:focus,
.entry-form textarea:focus {
  border-color: rgba(45, 212, 191, 0.7);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12);
}

.deploy-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid rgba(251, 146, 60, 0.34);
  border-radius: 8px;
  background: rgba(251, 146, 60, 0.1);
  color: #fed7aa;
  padding: 10px 12px;
  font-size: 0.84rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr 0.85fr 0.85fr;
  gap: 12px;
}

.card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(22, 30, 40, 0.94), rgba(17, 23, 32, 0.94));
  box-shadow: var(--shadow);
}

.card {
  display: grid;
  min-height: 126px;
  padding: 16px;
  gap: 10px;
}

.card.accent {
  background:
    linear-gradient(135deg, rgba(45, 212, 191, 0.16), rgba(96, 165, 250, 0.05)),
    linear-gradient(180deg, #172229, #111821);
  border-color: rgba(45, 212, 191, 0.45);
}

.label,
.entry-form label span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.value {
  display: block;
  font-size: clamp(1.45rem, 2.3vw, 2.25rem);
  line-height: 0.98;
  overflow-wrap: anywhere;
}

.sub,
.panel-head p,
.card p,
td small {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.32;
}

.delta {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(251, 113, 133, 0.13);
  color: #fecdd3;
  font-size: 0.76rem;
  font-weight: 850;
}

.delta.good {
  background: rgba(134, 239, 172, 0.12);
  color: #bbf7d0;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) 392px;
  gap: 14px;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  gap: 14px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.graph-layout {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  min-height: 412px;
}

.graph-controls {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  border-right: 1px solid var(--line-soft);
  background: rgba(10, 15, 22, 0.35);
}

.control-group {
  display: grid;
  gap: 7px;
}

.control-group .label {
  font-size: 0.68rem;
}

.select-mock {
  width: 100%;
  font-size: 0.78rem;
  font-weight: 760;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
  color: #d8e2ef;
  padding: 8px 9px;
  font-size: 0.78rem;
  font-weight: 760;
}

.switch-row input {
  width: 32px;
  height: 18px;
  accent-color: var(--teal);
}

.chart-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  padding: 14px 16px 16px;
}

.chart-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
}

.legend i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--legend-color);
}

.metric-chip {
  color: #e7fffb;
}

.chart-frame {
  position: relative;
  min-height: 330px;
  border: 1px solid #1a2431;
  border-radius: 8px;
  background: #0e141d;
  overflow: hidden;
}

#spendChart {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 330px;
}

.chart-tooltip {
  position: absolute;
  right: 18px;
  top: 18px;
  display: grid;
  gap: 5px;
  min-width: 184px;
  border: 1px solid rgba(45, 212, 191, 0.42);
  border-radius: 8px;
  background: rgba(13, 19, 27, 0.94);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.36);
  padding: 10px;
  pointer-events: none;
}

.chart-tooltip strong {
  font-size: 0.82rem;
}

.chart-tooltip div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.75rem;
}

.chart-tooltip[hidden] {
  display: none;
}

.insight-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.insight {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(13, 19, 27, 0.58);
}

.severity {
  width: 11px;
  height: 11px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.1);
}

.severity.high {
  background: var(--rose);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.1);
}

.severity.med {
  background: var(--orange);
  box-shadow: 0 0 0 4px rgba(251, 146, 60, 0.1);
}

.insight h3 {
  font-size: 0.9rem;
  line-height: 1.2;
}

.mini-action {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111923;
  color: #d8e2ef;
  padding: 5px 8px;
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}

.provider-list {
  display: grid;
  gap: 8px;
  padding: 12px 14px 14px;
}

.provider-row {
  display: grid;
  grid-template-columns: 152px minmax(120px, 1fr) 120px 92px 78px;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(11, 16, 23, 0.52);
  font-size: 0.82rem;
}

.provider-name {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--text);
  font-weight: 850;
}

.swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--swatch-color);
}

.bar-track {
  height: 7px;
  border-radius: 999px;
  background: #253141;
  overflow: hidden;
}

.bar-track span {
  display: block;
  width: var(--bar-width);
  height: 100%;
  border-radius: inherit;
  background: var(--bar-color);
}

.status {
  justify-self: start;
  min-height: 24px;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 850;
}

.status.ready,
.status.synced {
  background: rgba(134, 239, 172, 0.13);
  color: #bbf7d0;
}

.status.missing {
  background: rgba(251, 113, 133, 0.13);
  color: #fecdd3;
}

.status.error {
  background: rgba(251, 113, 133, 0.18);
  color: #fecdd3;
}

.numeric {
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.quality-grid {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.quality-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(13, 19, 27, 0.58);
}

.quality-item header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.84rem;
  font-weight: 850;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

.source-badge {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111923;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.delete-row {
  min-width: 34px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
  color: var(--muted);
}

.delete-row:hover:not(:disabled) {
  color: #fecdd3;
  border-color: rgba(244, 63, 94, 0.5);
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(4, 7, 12, 0.72);
}

.entry-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.entry-form label {
  display: grid;
  gap: 6px;
}

.entry-form textarea {
  resize: vertical;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.dialog-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
  color: var(--muted);
  font-weight: 800;
}

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

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-error {
  min-height: 20px;
  color: #fb7185;
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f131a;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .app,
  .main-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    grid-template-columns: repeat(7, 54px);
    height: auto;
    overflow-x: auto;
  }

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

  .provider-row {
    grid-template-columns: 132px minmax(120px, 1fr) 106px 82px 70px;
  }
}

@media (max-width: 760px) {
  .app {
    padding: 14px;
  }

  .topbar,
  .panel-head,
  .chart-topline {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .compact-control {
    min-width: calc(50% - 4px);
  }

  .compact-control input,
  .compact-control select {
    width: 100%;
  }

  .kpi-grid,
  .graph-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .graph-controls {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .provider-list {
    overflow-x: auto;
  }

  .provider-row {
    min-width: 680px;
  }

  .chart-tooltip {
    position: static;
    margin: 10px;
  }

  .deploy-notice {
    align-items: flex-start;
    flex-direction: column;
  }
}
