/* Tipsy AB-Config Console — minimal, dependency-free styling. */

:root {
  --fg: #1f2937;
  --muted: #6b7280;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-border: #fcd34d;
  --status-draft: #6b7280;
  --status-running: #16a34a;
  --status-paused: #ca8a04;
  --status-completed: #6b7280;
  --status-archived: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 600; }
.nav-main { display: flex; gap: 16px; flex: 1; }
.nav-item {
  text-decoration: none;
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 6px;
}
.nav-item:hover { background: #eef2ff; }
.nav-item.is-active { background: #e0e7ff; color: var(--primary); font-weight: 600; }
.user-box { display: flex; gap: 12px; align-items: center; }
.user-sub { color: var(--muted); font-size: 0.9em; }

.content { padding: 24px; max-width: 1200px; margin: 0 auto; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.page-header h1 { margin: 0; font-size: 1.4em; }

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95em;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover { background: #1d4ed8; }
.btn-link { border: none; background: transparent; color: var(--primary); padding: 4px 8px; }
.btn-link:hover { text-decoration: underline; background: transparent; }
.btn.danger, .btn-link.danger { color: var(--danger); }
.btn.danger { background: #fee2e2; border-color: var(--danger); }

.data-table { width: 100%; border-collapse: collapse; background: var(--card); }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th { font-weight: 600; background: #f9fafb; }
.data-table .actions-col { white-space: nowrap; }

.muted { color: var(--muted); }
.msg { margin-top: 8px; color: var(--muted); font-size: 0.9em; }

.form { display: flex; flex-direction: column; gap: 12px; max-width: 720px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.95em; }
/* Checkbox rows put the box inline with its label text (overrides the column
   default above) without affecting other .form label fields. */
.form label.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.form label.checkbox-row input { width: auto; }
.form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-family: inherit;
  font-size: 1em;
}
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.form-inline label { flex: 0 0 auto; }
.actions-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

.filter-bar { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar label { display: flex; flex-direction: column; gap: 4px; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 16px; background: var(--card); padding: 12px; border: 1px solid var(--border); border-radius: 6px; }
.kv dt { font-weight: 600; color: var(--muted); }
.kv dd { margin: 0; }

.value-box {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.85em;
  background: #e5e7eb;
  color: var(--fg);
}
.status-draft { background: #e5e7eb; }
.status-running { background: #dcfce7; color: #166534; }
.status-paused { background: #fef3c7; color: #854d0e; }
.status-completed { background: #e5e7eb; color: #374151; }
.status-archived { background: #e5e7eb; color: #6b7280; }

/* Version status-label badges (configs detail page). kind from
   /api/v1/configs/key-status drives the class: full/whitelist/ab/ab-paused/
   ab-draft/published. */
.status-full { background: #dcfce7; color: #166534; }
.status-whitelist { background: #ffedd5; color: #9a3412; }
.status-ab { background: #ede9fe; color: #5b21b6; }
.status-ab-paused { background: #fef9c3; color: #854d0e; }
.status-ab-draft { background: #e5e7eb; color: #4b5563; }
.status-published { background: #dbeafe; color: #1e40af; }

/* Per-version value cell in the Versions table: monospace, capped width,
   wrap long/multi-line values without blowing out the table layout. */
.value-cell {
  margin: 0;
  max-width: 360px;
  max-height: 6em;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.warn-card { background: var(--warn-bg); border-color: var(--warn-border); }

.edit-layout { display: grid; grid-template-columns: 260px 1fr; gap: 24px; }
.versions-col { background: var(--card); padding: 12px; border: 1px solid var(--border); border-radius: 6px; }
.version-list { list-style: none; padding: 0; margin: 0; }
.version-list li { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.editor-col { background: var(--card); padding: 16px; border: 1px solid var(--border); border-radius: 6px; }
.editor-col h3 { margin-top: 24px; }

.group-row { border: 1px solid var(--border); border-radius: 6px; padding: 12px; margin-bottom: 12px; background: #fafafa; }
.group-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.group-head input { flex: 1 1 120px; }
.group-detail { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }

/* Login page */
.login-body { background: var(--bg); }
.login-wrap { max-width: 480px; margin: 80px auto; padding: 24px; background: var(--card); border-radius: 8px; border: 1px solid var(--border); }
.login-wrap form { display: flex; flex-direction: column; gap: 12px; }

code { background: #f3f4f6; padding: 1px 6px; border-radius: 3px; font-family: ui-monospace, monospace; font-size: 0.9em; }

/* Topology (domains / layers / slots) — ST7 v2 console. */
.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #854d0e; padding: 10px 12px; border-radius: 6px; margin: 8px 0; }
.id-row { display: flex; gap: 8px; align-items: center; }
.id-row input { flex: 1 1 auto; }

/* layer_slot allocation bar: allocated experiment / domain ranges + gaps. */
.slot-bar { display: flex; width: 100%; height: 22px; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; margin: 8px 0 12px; background: #fff; }
.slot-bar span { display: inline-block; height: 100%; }
.slot-exp { background: #93c5fd; }
.slot-dom { background: #c4b5fd; }
.slot-gap { background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 6px, #e5e7eb 6px, #e5e7eb 12px); }

/* config_version key/version selector rows in the experiment group editor. */
.kv-selector { display: flex; flex-direction: column; gap: 6px; }
.kv-row { display: flex; gap: 8px; align-items: center; }
.kv-row select { flex: 1 1 auto; }

/* Compact per-entity slot component (P2 G7), reused on the domain detail +
   create pages. Builds on .form-inline (row + flex-wrap) but keeps the lo/hi
   number inputs at content width instead of stretching, and tightens the gap so
   the [lo] [hi] [Apply] [Cancel] controls read as one compact strip. Additive
   only — does not touch the shared .form / .form-inline rules. */
.slot-compact label { flex: 0 0 auto; }
.slot-compact input[type="number"] { width: 90px; }

/* Layer detail "Add slot" lo/hi pair (P2 G8). The Add-slot form is .form-inline
   (flex + wrap); when kind=experiment the Target select widens and the wrap
   point drifts so hi can drop to a new line away from lo. Wrapping the lo + hi
   labels in .slot-lohi makes the pair a SINGLE non-wrapping inline-flex item, so
   lo and hi always sit on the same line and wrap together as a unit. Additive
   only — does not change the shared .form / .form-inline rules. */
.slot-lohi {
  display: inline-flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 12px;
}
.slot-lohi label { flex: 0 0 auto; }
.slot-lohi input[type="number"] { width: 90px; }


/* Inline traffic-slot allocation fieldset on the Create Sub-Domain form (P2 G7).
   Groups the "allocate now" checkbox + lo/hi inputs into a bordered block so the
   two-step create→assign flow reads as one section. */
.slot-inline {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.slot-inline legend { padding: 0 6px; font-weight: 600; font-size: 0.95em; }
.slot-inline input[type="number"] { width: 90px; }

/* Deterministic 2-column grid for slot-add / slot-assign forms (P2 G7/G8 fix).
   Replaces the fragile .form-inline flex-wrap whose wrap point drifted when the
   Target option (a long domain UUID) widened. Fixed two columns: Kind|Target on
   row 1, lo|hi on row 2, actions span both on row 3 — never reflows. */
.slot-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 12px 16px;
  align-items: end;
  max-width: 720px;
}
.slot-grid > label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.slot-grid > label > input,
.slot-grid > label > select { width: 100%; box-sizing: border-box; }
.slot-grid-actions { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }

/* Filterable <select> combobox (FB3). The native select is kept in the DOM
   (hidden) as the value carrier; the text input drives fuzzy filtering and the
   list shows matches. Styled to visually match the native form inputs. */
.tc-combo { position: relative; display: block; width: 100%; }
.tc-combo-native {
  /* keep it in the form (name/value submit) but visually hidden */
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); border: 0;
}
.tc-combo-input {
  width: 100%; box-sizing: border-box;
  padding: 8px 26px 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font: inherit; cursor: text;
}
.tc-combo-input:hover { border-color: #9ca3af; }
/* Resting-state affordance (G2): a CSS-drawn ▾ pinned to the right so the input
   reads as a searchable dropdown. pointer-events:none — clicks fall through to
   the input. The 26px input padding-right reserves space (box-sizing:border-box
   means no outer-width change / reflow). */
.tc-combo-arrow {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0; pointer-events: none;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #6b7280;
}
.tc-combo.is-open .tc-combo-input { border-color: #2563eb; outline: none; }
.tc-combo-list {
  position: absolute; z-index: 50; top: calc(100% + 2px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none;
  max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
.tc-combo-opt {
  padding: 6px 8px; border-radius: 4px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tc-combo-opt.is-active { background: #eff6ff; }
.tc-combo-opt.is-selected { font-weight: 600; }
.tc-combo-opt.is-disabled { color: var(--muted, #9ca3af); cursor: not-allowed; }
.tc-combo-empty { padding: 6px 8px; color: var(--muted, #9ca3af); }

/* Disabled combobox (review B3): mirror the native select's disabled state so a
   disabled kv-version / pinned ns-or-layer reads as non-editable. */
.tc-combo.is-disabled .tc-combo-input {
  background: #f3f4f6; color: var(--muted, #9ca3af); cursor: not-allowed;
}
.tc-combo.is-disabled .tc-combo-arrow { opacity: 0.4; }

/* Draft Editor secondary actions (Save Draft / Delete Draft): less prominent
   than the primary "Publish New Version" — a tighter, muted row beneath it. */
.actions-secondary { margin-top: 4px; }
.actions-secondary .btn { color: var(--muted, #6b7280); }

/* Whitelist multi-key UI (a gray release controls 1..N (key,version) pairs that
   share one UID set). Mirrors the existing .slot-inline fieldset + .kv-row flex
   patterns so it reads as part of the same console. ------------------------- */
/* Create form: the repeatable key/version rows live in a bordered fieldset. */
.wl-keys-fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wl-keys-fieldset legend { padding: 0 6px; font-weight: 600; font-size: 0.95em; }
/* One key-select + version-select + remove button per row (like .kv-row). */
.wl-key-row { display: flex; gap: 8px; align-items: center; }
.wl-key-row > .tc-combo,
.wl-key-row select { flex: 1 1 auto; min-width: 0; }
.wl-key-row .wl-rm { flex: 0 0 auto; }
/* Stacked (key → version) lines inside the list table's Keys cell. */
.wl-key-line { white-space: nowrap; line-height: 1.6; }

/* Edit Keys modal: a dimmed full-screen backdrop centering a dialog box. The
   combobox list (z-index 50) must sit above the modal, so the overlay stays
   below it (z-index 40) and the modal allows the list to overflow. */
.wl-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(17, 24, 39, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto;
}
.wl-overlay[hidden] { display: none; }
.wl-modal {
  background: #fff; border-radius: 10px; padding: 20px 24px;
  width: 100%; max-width: 560px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.28);
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
}
.wl-modal h3 { margin: 0; }
.wl-modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }

/* Manage UIDs modal: a scrollable, selectable list of the release's current
   uids. Each .wl-uid-row shows a copyable uid (monospace, no chip background)
   left-aligned with a compact ghost Remove button right-aligned; rows are
   zebra-free with thin dividers so a long list reads cleanly. The list is
   capped in height and scrolls so a release with thousands of uids stays
   usable inside the modal. */
.wl-uid-list {
  max-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card);
  width: 100%; box-sizing: border-box;
}
.wl-uid-row {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  width: 100%; box-sizing: border-box;
  padding: 6px 12px;
}
.wl-uid-row + .wl-uid-row { border-top: 1px solid var(--border); }
.wl-uid-val {
  flex: 1 1 auto; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
  overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
/* Solid red Remove button, fixed width so every row's button lines up. */
.wl-uid-rm {
  flex: 0 0 auto; width: 84px; text-align: center;
  padding: 3px 10px; font-size: 0.85em; line-height: 1.5;
  color: #fff; background: var(--danger); border: 1px solid var(--danger);
  border-radius: 6px; cursor: pointer;
}
.wl-uid-rm:hover { background: #b91c1c; border-color: #b91c1c; text-decoration: none; }
.wl-uid-empty { padding: 12px; text-align: center; }
/* Add-UIDs block: label stacked above a full-width textarea (modal labels are
   not inside .form, so set the column layout locally). */
.wl-uid-add-label { display: flex; flex-direction: column; gap: 4px; font-size: 0.95em; }
.wl-uid-add-label textarea {
  width: 100%; box-sizing: border-box;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
  resize: vertical;
}
