:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222d;
  --line: #272c3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #4f8cff;

  /* Bar tones, matching the reference dashboard's palette */
  --blue: #4f8cff;
  --amber: #f5c344;
  --green: #58d68d;
  --lime: #7ed957;
  --pink: #ec2b6b;
  --maroon: #8b1538;
  --teal: #1ba97b;

  --radius: 12px;
}

* { box-sizing: border-box; }

/* The UA stylesheet hides [hidden] with display:none, but any author `display`
   rule outranks it - and .gate and .loader both set display:grid. Without this
   the token gate and the spinner would never disappear. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

.c-good { color: var(--green); }
.c-bad { color: var(--pink); }
.c-warn { color: var(--amber); }

/* ---------- token gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #1b2030, var(--bg));
  z-index: 50;
}

.gate-card {
  width: min(380px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gate-card h1 { font-size: 20px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 13px; }

.gate-card input,
.gate-card button {
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 14px;
}

.gate-card input { background: var(--bg); color: var(--text); }
.gate-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.gate-card button {
  background: var(--accent);
  color: #fff;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.gate-error { color: var(--pink) !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; letter-spacing: .2px; }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.controls select,
.controls button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.controls button { font-weight: 600; }
.controls button:hover { border-color: var(--accent); }
.controls button.ghost { color: var(--muted); }

/* ---------- layout ---------- */
main { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.kpi h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  font-weight: 500;
}

.kpi p {
  margin: 8px 0 2px;
  font-size: 28px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.kpi span { font-size: 12px; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

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

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

.chart-wrap { position: relative; height: 300px; }

/* ---------- tabs ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }

.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.tabs button:hover { color: var(--text); }

.tabs button.active {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }

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

th, td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  position: sticky;
  top: 0;
  background: var(--panel);
}

th.numeric { text-align: right; }

.label-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* A bar cell layers a proportional bar behind a right-aligned number. */
.bar-cell {
  position: relative;
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 84px;
}

.bar-cell .bar {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  height: 17px;
  border-radius: 3px;
  opacity: .85;
}

.bar-cell .val { position: relative; }

.tone-blue { background: var(--blue); }
.tone-amber { background: var(--amber); }
.tone-green { background: var(--green); }
.tone-lime { background: var(--lime); }
.tone-pink { background: var(--pink); }
.tone-maroon { background: var(--maroon); }
.tone-teal { background: var(--teal); }

tbody tr:hover { background: var(--panel-2); }

tfoot .totals td {
  font-weight: 650;
  border-top: 2px solid var(--line);
  border-bottom: none;
  text-align: right;
}

tfoot .totals .label-cell { text-align: left; }

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

/* ---------- sales cycle ---------- */
.cycle {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.cycle-stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.cycle-stat h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  font-weight: 500;
}

.cycle-stat p {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.cycle-warn {
  grid-column: 1 / -1;
  color: var(--amber);
  font-size: 13px;
  background: rgba(245, 195, 68, .08);
  border: 1px solid rgba(245, 195, 68, .35);
  border-radius: 8px;
  padding: 10px 14px;
}

.caveat {
  margin: -6px 0 14px;
  padding: 9px 12px;
  border-left: 3px solid var(--amber);
  background: rgba(245, 195, 68, .07);
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- capability notes ---------- */
.notes ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

.notes li { color: var(--muted); font-size: 13px; }

.notes li strong { color: var(--text); font-weight: 600; }

/* ---------- feedback ---------- */
.error-banner {
  background: rgba(236, 43, 107, .1);
  border: 1px solid var(--pink);
  color: var(--pink);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
}

footer { color: var(--muted); font-size: 12px; text-align: center; padding-bottom: 8px; }

.loader {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, .55);
  display: grid;
  place-items: center;
  z-index: 40;
}

.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}
