:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e3e8f0;
  --text: #111827;
  --muted: #64748b;
  --blue: #005bff;
  --blue-hover: #004ad4;
  --blue-soft: #eef4ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

.text-blue { color: var(--blue); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #005bff, #4f46e5);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
  letter-spacing: -0.02em;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-ok { background: var(--green); }
.dot-err { background: var(--red); }
.dot-muted { background: #94a3b8; }

/* Container */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }

.btn-warning { background: var(--amber-soft); color: var(--amber); border-color: #fde68a; }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: #fecaca; }

.btn-icon {
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

/* Panels & KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.kpi-card {
  padding: 16px 18px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.kpi-value-sm {
  font-size: 16px;
  padding-top: 6px;
}

.panel {
  padding: 18px 20px;
  margin-bottom: 18px;
}

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

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-subtitle {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* Tests Grid */
.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.test-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.test-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 6px 18px rgba(0, 91, 255, 0.08);
  transform: translateY(-1px);
}

.test-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.test-card-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.thumb-box {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  aspect-ratio: 4 / 3;
}

.thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(17, 24, 39, 0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}

.thumb-tag-active {
  background: var(--blue);
}

.test-card-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.mini-stat-label { font-size: 11px; color: var(--muted); }
.mini-stat-val { font-size: 13.5px; font-weight: 700; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}
.empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

/* Detail View */
.detail-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

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

.detail-header-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.detail-title {
  margin: 0;
  font-size: 20px;
}

.detail-submeta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.detail-verdict-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  min-width: 240px;
}

.ab-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.variant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.variant-card.is-live {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 91, 255, 0.12);
}

.variant-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.variant-media-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  align-items: start;
}

.variant-img-wrap {
  width: 150px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface-2);
}

.variant-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.variant-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  font-variant-numeric: tabular-nums;
}

.stat-item-label { font-size: 11.5px; color: var(--muted); }
.stat-item-value { font-size: 15px; font-weight: 700; }

.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Progress & Z-test */
.sample-progress-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.progress-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-fill.done { background: var(--green); }

.ztest-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ztest-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

.ztest-metric-name { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.ztest-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }

/* Morse Timeline */
.morse-timeline {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.morse-step {
  min-width: 78px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  background: var(--surface-2);
}

.morse-step.is-current {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.morse-step.is-done {
  background: #f8fafc;
}

.morse-day { font-size: 11px; color: var(--muted); }
.morse-var { font-size: 18px; font-weight: 800; margin: 2px 0; }
.morse-note { font-size: 10.5px; color: var(--muted); }

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

.logs-wrap {
  max-height: 280px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

.data-table-sm td,
.data-table-sm th {
  padding: 6px 8px;
  font-size: 12px;
}

/* Sync controls */
.sync-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.sync-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Forms & Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 720px; }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 18px 20px;
}

.modal-footer {
  margin-top: 16px;
}

.modal-footer-inline {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
}

.field-checkbox {
  justify-content: flex-end;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500 !important;
  padding-top: 20px;
}

.input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}

.input-sm {
  width: auto;
  padding: 6px 10px;
}

.input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 91, 255, 0.12);
}

.form-error {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-top: 8px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.section-subtitle {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}

/* Dropzone */
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.dropzone-icon {
  font-size: 24px;
  color: var(--blue);
  margin-bottom: 4px;
}

.upload-preview-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.upload-preview-wrap img {
  width: 76px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Accounts list */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  gap: 12px;
  flex-wrap: wrap;
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: #111827;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  max-width: 360px;
}
.toast-ok { background: #065f46; }
.toast-err { background: #991b1b; }

/* Product search picker */
.product-picker {
  position: relative;
}

.product-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
  max-height: 260px;
  overflow-y: auto;
}

.product-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.product-option:last-child {
  border-bottom: none;
}

.product-option:hover {
  background: var(--blue-soft);
}

.product-option img {
  width: 38px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.product-option-info {
  min-width: 0;
  flex: 1;
}

.product-option-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-option-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.selected-product-chip {
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--blue-soft);
  border: 1px solid #bfdbfe;
  font-size: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Test type segmented control & text variant boxes */
.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.type-switch-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.type-switch-btn.is-active {
  background: var(--surface);
  color: var(--blue);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.text-preview-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
  font-size: 12.5px;
}

.text-preview-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.text-preview-desc {
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 110px;
  overflow-y: auto;
  font-size: 12px;
}

@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .ab-compare-grid,
  .two-col-grid,
  .form-grid,
  .ztest-grid {
    grid-template-columns: 1fr;
  }
  .variant-media-row { grid-template-columns: 1fr; }
}
