
:root {
  color-scheme: light;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e5e7eb;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #1d4ed8;
  --accent-light: #dbeafe;
  --green: #059669;
  --green-light: #d1fae5;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-pill: 999px;
  font-family: Inter Variable, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

.clipboard-helper {
  position: fixed; top: 0; left: -9999px; width: 1px; height: 1px; opacity: 0;
}

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

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---- Auth ---- */

.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: linear-gradient(160deg, #111827 0%, #1f2937 42%, var(--bg) 42.2%, var(--bg) 100%);
}

.login-card {
  width: min(100%, 26rem); display: grid; gap: 1.1rem;
  padding: clamp(1.2rem, 5vw, 2rem);
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 6%);
}

.login-brand, .brand {
  display: flex; align-items: center; gap: 0.6rem; min-width: 0;
}

.brand-mark {
  width: 0.85rem; height: 0.85rem;
  border: 2px solid var(--accent); border-radius: 3px; transform: rotate(45deg); flex: 0 0 auto;
}

.brand-name { font-weight: 700; font-size: 1.05rem; }

.eyebrow {
  margin: 0 0 0.25rem; color: var(--accent);
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}

.login-card h1 { margin: 0; font-size: 2.4rem; line-height: 1; font-weight: 700; }

.login-form { display: grid; gap: 0.5rem; }

.login-form label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }

.login-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; }

.login-row input {
  min-width: 0; min-height: 2.5rem; padding: 0.5rem 0.65rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}

.login-error { color: var(--red); font-weight: 650; }

/* ---- Shell ---- */

.dashboard-shell { min-height: 100vh; background: var(--bg); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 3.2rem; padding: 0.5rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 88%); backdrop-filter: blur(12px);
}

.topbar .brand { color: var(--ink); }

.topbar .brand-subtitle { color: var(--muted); font-size: 0.8rem; }

.top-actions { display: flex; align-items: center; gap: 0.5rem; }

.button {
  min-height: 2.1rem; border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--ink); padding: 0.35rem 0.8rem;
  cursor: pointer; font-weight: 600; font-size: 0.82rem;
}

.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }

.button:disabled { cursor: wait; opacity: 0.6; }

.button:focus-visible, input:focus-visible, .improvement-status-card:focus-visible, .improvement-feed-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.status-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  min-height: 1.55rem; padding: 0.18rem 0.5rem;
  border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--muted);
  font-size: 0.74rem; font-weight: 650;
}

.status-pill::before {
  content: ""; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--accent);
}

.tag {
  display: inline-flex; align-items: center; min-height: 1.55rem;
  padding: 0.16rem 0.48rem; border: 1px solid var(--line);
  border-radius: var(--radius-pill); background: var(--surface-2);
  color: var(--muted); font-size: 0.72rem; font-weight: 650;
}

.tag.done, .tag.complete, .tag.configured, .tag.tested, .tag.ready, .tag.approved, .tag.scaling { color: #fff; border-color: var(--green); background: var(--green); }
.tag.active, .tag.iterating, .tag.testing, .tag.P2, .tag.drafted, .tag.partial { color: #fff; border-color: var(--accent); background: var(--accent); }
.tag.blocked, .tag.P0, .tag.high { color: #fff; border-color: var(--red); background: var(--red); }
.tag.waiting, .tag.P1, .tag.medium, .tag.approval { color: #fff; border-color: var(--amber); background: var(--amber); }

/* ---- Container ---- */

.container { max-width: 1280px; margin: 0 auto; padding: clamp(1rem, 2.5vw, 2rem); }

.view[hidden], [hidden] { display: none !important; }

/* ---- Dashboard Hero ---- */

.dashboard-hero {
  margin-bottom: 1.5rem;
}

.dashboard-hero h1 {
  margin: 0 0 0.35rem; font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  line-height: 1.1; font-weight: 700; color: var(--ink);
}

.dashboard-hero p {
  margin: 0; color: var(--muted); font-size: 0.95rem; max-width: 48rem;
}

/* ---- Improvement Dispatch ---- */

.improvement-dispatch {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: clamp(1rem, 2vw, 1.25rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.improvement-summary {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.improvement-summary h2,
.improvement-summary strong,
.improvement-detail h3,
.improvement-detail p,
.improvement-detail dl {
  margin: 0;
}

.improvement-summary h2 {
  color: var(--ink);
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  line-height: 1.04;
}

#improvementTotal {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.improvement-source {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.improvement-week {
  min-width: 10rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.improvement-week span,
.improvement-week strong {
  display: block;
}

.improvement-week span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
}

.improvement-week strong {
  margin-top: 0.18rem;
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1;
}

.improvement-status-rail {
  display: grid;
  grid-template-columns: repeat(5, minmax(8.5rem, 1fr));
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
}

.improvement-status-card {
  min-height: 7.4rem;
  display: grid;
  gap: 0.35rem;
  align-content: space-between;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.improvement-status-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-light);
}

.improvement-status-card span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.improvement-status-card strong {
  font-size: 2.5rem;
  line-height: 0.9;
}

.improvement-status-card small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.improvement-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 0.42fr);
  gap: 1rem;
  align-items: start;
}

.improvement-feed-panel,
.improvement-detail {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.section-header h2 {
  margin: 0;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.improvement-feed {
  display: grid;
  gap: 0.6rem;
}

.improvement-feed-item {
  display: grid;
  grid-template-columns: minmax(6rem, 0.24fr) minmax(9rem, 0.36fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.68rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.improvement-feed-item[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.improvement-feed-item strong,
.improvement-feed-item span,
.improvement-feed-item small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.improvement-feed-item > span:not(.tag),
.improvement-feed-item small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.32;
}

.improvement-feed-item small {
  grid-column: 2 / -1;
}

.improvement-item-status {
  justify-self: start;
}

.improvement-detail {
  position: sticky;
  top: 4.2rem;
  display: grid;
  gap: 0.8rem;
}

.improvement-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.improvement-detail-head .tag {
  flex: 0 0 auto;
  white-space: nowrap;
}

.improvement-detail h3 {
  margin-top: 0.15rem;
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1.15;
}

.improvement-detail p,
.improvement-next span,
.improvement-evidence,
.evidence-list {
  color: var(--muted);
  line-height: 1.4;
}

.improvement-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.improvement-detail-grid div,
.improvement-next {
  min-width: 0;
  padding: 0.62rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.improvement-detail-grid dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.improvement-detail-grid dd {
  margin: 0.16rem 0 0;
  color: var(--ink);
  font-weight: 750;
  overflow-wrap: anywhere;
}

.improvement-next {
  display: grid;
  gap: 0.25rem;
}

.improvement-next strong,
.improvement-evidence strong {
  color: var(--ink);
}

.evidence-list {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
}

.chart-note {
  margin: 0;
  padding: 0.72rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* ---- Two-Column Layout ---- */

.store-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

/* ---- Section Column ---- */

.store-column {
  display: flex; flex-direction: column; gap: 1rem;
}

.column-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

.column-header h2 {
  margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--ink);
}

.column-badge {
  min-height: 1.5rem; padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill); font-size: 0.74rem; font-weight: 700;
  white-space: nowrap;
}

.column-badge.prelaunch { background: var(--amber-light); color: var(--amber); }
.column-badge.live { background: var(--green-light); color: var(--green); }

/* ---- Store Card ---- */

.store-card {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--surface); overflow: hidden;
}

.store-card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.store-card-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }

.store-card-header .store-domain { color: var(--muted); font-size: 0.8rem; }

.store-card-body { padding: 1.1rem; display: grid; gap: 1rem; }

/* ---- Progress Bar ---- */

.progress-section { display: grid; gap: 0.5rem; }

.progress-label {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.82rem;
}

.progress-label span:first-child { font-weight: 650; }
.progress-label span:last-child { color: var(--muted); }

.progress-track {
  overflow: hidden; height: 0.5rem; border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.progress-fill {
  display: block; height: 100%; border-radius: inherit;
  background: var(--accent); transition: width 400ms ease;
}

.progress-fill.amber { background: var(--amber); }
.progress-fill.green { background: var(--green); }

/* ---- Gate Checklist ---- */

.gate-list { display: grid; gap: 0.4rem; }

.gate-item {
  display: flex; align-items: center; gap: 0.55rem; padding: 0.5rem 0.6rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 0.82rem;
}

.gate-item.done { opacity: 0.5; }

.gate-check {
  width: 1.1rem; height: 1.1rem; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 0.6rem; font-weight: 800;
}

.gate-check.done { background: var(--green); color: #fff; }
.gate-check.pending { background: var(--surface-3); color: var(--muted); }
.gate-check.blocked { background: var(--red-light); color: var(--red); }

.gate-label { flex: 1; min-width: 0; }
.gate-owner { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }

.distance-line {
  padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
  background: var(--accent-light); color: var(--accent);
  font-size: 0.8rem; font-weight: 650;
}

/* ---- KPI Grid ---- */

.kpi-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.55rem;
}

.kpi-cell {
  padding: 0.7rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2);
}

.kpi-value {
  display: block; font-size: 1.45rem; line-height: 1; font-weight: 700; color: var(--ink);
}

.kpi-label {
  display: block; margin-top: 0.2rem; color: var(--muted);
  font-size: 0.72rem; font-weight: 650;
}

/* ---- Attribution Mini-Table ---- */

.attribution-table {
  width: 100%; border-collapse: collapse; font-size: 0.8rem;
}

.attribution-table th {
  padding: 0.45rem 0.6rem; border-bottom: 2px solid var(--line);
  color: var(--muted); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; text-align: left;
}

.attribution-table td {
  padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line);
}

.attribution-table .rev-cell { font-weight: 700; text-align: right; }

/* ---- Mini Funnel ---- */

.mini-funnel { display: grid; gap: 0.3rem; }

.funnel-step {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 0.7rem;
  padding: 0.4rem 0.55rem; border-radius: var(--radius-sm); font-size: 0.8rem;
}

.funnel-step:nth-child(1) { background: var(--accent-light); }
.funnel-step:nth-child(2) { background: var(--surface-2); }
.funnel-step:nth-child(3) { background: var(--green-light); }

.funnel-step .step-label { font-weight: 650; }
.funnel-step .step-count { color: var(--muted); font-size: 0.76rem; }
.funnel-step .step-rev { font-weight: 700; }

/* ---- Optimization Todos ---- */

.opt-todo-list { display: grid; gap: 0.4rem; }

.opt-todo {
  display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.5rem 0.6rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 0.8rem;
}

.opt-todo .todo-text { flex: 1; min-width: 0; line-height: 1.4; }

/* ---- Data Source Connectors ---- */

.connector-strip {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
}

.connector-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.55rem; border-radius: var(--radius-pill);
  font-size: 0.74rem; font-weight: 600;
}

.connector-badge.live { background: var(--green-light); color: var(--green); }
.connector-badge.pending { background: var(--amber-light); color: var(--amber); }
.connector-badge.off { background: var(--surface-2); color: var(--muted); }

.connector-badge::before {
  content: ""; width: 0.35rem; height: 0.35rem; border-radius: 50%;
}

.connector-badge.live::before { background: var(--green); }
.connector-badge.pending::before { background: var(--amber); }
.connector-badge.off::before { background: var(--surface-3); }

/* ---- Empty State ---- */

.empty-state {
  padding: 3rem 1.5rem; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-md);
  background: var(--surface);
}

.empty-state-compact { padding: 1rem !important; }

.empty-state h3 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--muted); }
.empty-state p { margin: 0; color: var(--muted); font-size: 0.86rem; }

/* ---- Fill Width Utilities ---- */

.fill-w-0  { width: 0%; }
.fill-w-5  { width: 5%; }
.fill-w-10 { width: 10%; }
.fill-w-15 { width: 15%; }
.fill-w-20 { width: 20%; }
.fill-w-25 { width: 25%; }
.fill-w-30 { width: 30%; }
.fill-w-35 { width: 35%; }
.fill-w-40 { width: 40%; }
.fill-w-45 { width: 45%; }
.fill-w-50 { width: 50%; }
.fill-w-55 { width: 55%; }
.fill-w-60 { width: 60%; }
.fill-w-65 { width: 65%; }
.fill-w-70 { width: 70%; }
.fill-w-75 { width: 75%; }
.fill-w-80 { width: 80%; }
.fill-w-85 { width: 85%; }
.fill-w-90 { width: 90%; }
.fill-w-95 { width: 95%; }
.fill-w-100 { width: 100%; }

/* ---- Section Labels ---- */

.section-label {
  display: block; margin-bottom: 0.5rem;
  color: var(--muted); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* ---- Toast ---- */

.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  transform: translateY(1rem); opacity: 0; pointer-events: none;
  padding: 0.65rem 0.85rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: #111827; color: #fff;
  font-size: 0.84rem; transition: opacity 180ms ease, transform 180ms ease;
}

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

/* ---- Error ---- */

.error {
  margin-bottom: 1rem; padding: 0.9rem;
  border: 1px solid var(--red); border-radius: var(--radius-sm);
  color: var(--red); background: var(--red-light); font-size: 0.86rem;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .store-split { grid-template-columns: 1fr; }
  .improvement-workbench { grid-template-columns: 1fr; }
  .improvement-detail { position: static; }
  .improvement-status-rail { grid-template-columns: repeat(5, minmax(9.5rem, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .container { padding: 0.75rem; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-row { display: flex; flex-direction: column; }
  .dashboard-hero h1 { font-size: 1.5rem; }
  .topbar { flex-wrap: wrap; }
  .improvement-summary, .improvement-detail-head { flex-direction: column; align-items: stretch; }
  .improvement-status-rail, .improvement-feed-item { grid-template-columns: 1fr; overflow-x: visible; }
  .improvement-feed-item small { grid-column: auto; }
  .improvement-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attribution-table { font-size: 0.74rem; }
  .column-header { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
}
