/* ─────────────────────────────────────────────────────────────
   dbot admin · design system
   Palette: Zinc neutrals + single Emerald accent. Off-black, no pure black.
   Typography: Geist (sans), Geist Mono (mono). No Inter.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Surfaces */
  --bg:           #fafafa;          /* zinc-50, very slightly off-white */
  --surface:      #ffffff;
  --surface-alt:  #f4f4f5;          /* zinc-100 */
  --hover:        #f4f4f5;

  /* Ink */
  --ink:          #0a0a0a;          /* zinc-950, off-black */
  --ink-soft:     #27272a;          /* zinc-800 */
  --muted:        #71717a;          /* zinc-500 */
  --muted-2:      #a1a1aa;          /* zinc-400 */

  /* Hairlines */
  --line:         #e4e4e7;          /* zinc-200 */
  --line-soft:    #f4f4f5;          /* zinc-100 */
  --line-strong:  #d4d4d8;          /* zinc-300 */

  /* Accent */
  --accent:       #10b981;          /* emerald-500 — desaturated, < 80% sat */
  --accent-ink:   #047857;          /* emerald-700 */
  --accent-soft:  #ecfdf5;          /* emerald-50 */

  --danger:       #b91c1c;          /* red-700, slightly muted */
  --danger-soft:  #fef2f2;
  --warn:         #b45309;          /* amber-700 */
  --warn-soft:    #fffbeb;

  /* Geometry */
  --radius-sm:    6px;
  --radius:       8px;
  --radius-lg:    12px;
  --radius-xl:    16px;

  /* Shadows — tinted to background, never blue */
  --shadow-sm:    0 1px 0 rgba(10,10,10,0.04);
  --shadow:       0 1px 2px rgba(10,10,10,0.04), 0 4px 12px -6px rgba(10,10,10,0.06);
  --shadow-lg:    0 1px 0 rgba(10,10,10,0.04), 0 24px 48px -24px rgba(10,10,10,0.18);

  /* Motion */
  --ease:         cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast:       120ms var(--ease);
  --t:            180ms var(--ease);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

body { font-variant-numeric: tabular-nums; }

button {
  font-family: inherit; font-size: inherit; cursor: pointer;
  background: none; border: 0; padding: 0; color: inherit;
}

input, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
}

.hidden { display: none !important; }
.muted  { color: var(--muted); }
.mono   { font-family: 'Geist Mono', ui-monospace, SFMono-Regular, monospace; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* ── Boot loader ── */
.boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.boot-pulse {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--ink);
  opacity: 0.06;
  animation: pulse 1.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.7); opacity: 0.05; }
  50%      { transform: scale(1);   opacity: 0.12; }
}

/* ── Icons ── */
/* Sprite contract: each <symbol> sets its own fill/stroke explicitly. */
.icon, .icon-sm, .icon-lg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  color: currentColor;
}
.icon    { width: 16px; height: 16px; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 20px; height: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500; font-size: 13px;
  letter-spacing: -0.005em;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--ink);
  color: white;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: #1f1f23; }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background: var(--hover); border-color: var(--line-strong); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }

.btn-icon-only {
  width: 28px; height: 28px; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.btn-icon-only:hover:not(:disabled) { background: var(--hover); color: var(--ink); }

.btn-lg { padding: 10px 16px; font-size: 14px; border-radius: var(--radius); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.btn-row-icon {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--muted-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.btn-row-icon:hover { background: var(--danger-soft); color: var(--danger); }

.kbd {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.65);
  letter-spacing: 0;
  border: 1px solid rgba(255,255,255,0.08);
}
.btn-secondary .kbd, .btn-ghost .kbd {
  background: var(--surface-alt); color: var(--muted); border-color: var(--line);
}

/* ── Auth screen (asymmetric, left-aligned) ── */
.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  padding: 64px 24px;
}
.auth-stack {
  width: 100%;
  max-width: 420px;
  margin-left: max(64px, 12vw);
}
@media (max-width: 768px) {
  .auth-stack { margin: 0 auto; }
}
.auth-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 24px;
}
.auth-eyebrow .dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-title {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
  margin: 0 0 12px;
  color: var(--ink);
}
.auth-sub {
  margin: 0 0 32px;
  color: var(--muted);
  max-width: 42ch;
  font-size: 14.5px;
  line-height: 1.55;
}
.auth-card {
  display: flex; flex-direction: column;
  gap: 14px;
}
.auth-actions { display: flex; gap: 8px; align-items: center; }
.auth-footnote {
  margin-top: 32px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.02em;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: -0.005em;
}

.otp-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 22px;
  letter-spacing: 0.4em;
  text-align: center;
  color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.otp-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,0.05); }
.otp-input::placeholder { color: var(--muted-2); letter-spacing: 0.4em; }

.inline-error {
  display: none;
  margin: 0;
  padding: 8px 12px;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 12.5px;
}
.inline-error.show { display: block; }

/* ── Editor shell ── */
.shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.brand-mark {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: linear-gradient(180deg, var(--ink) 0%, #18181b 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 1px 2px rgba(10,10,10,0.1);
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.brand-divider { color: var(--muted-2); }
.brand-section { color: var(--muted); }

.topbar-actions {
  display: flex; align-items: center; gap: 8px;
}
.topbar-sep {
  width: 1px; height: 18px; background: var(--line); margin: 0 4px;
}

.status {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11.5px;
  letter-spacing: 0.01em;
  color: var(--muted);
  min-width: 0; max-width: 240px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: inline-flex; align-items: center; gap: 6px;
  margin-right: 4px;
}
.status::before {
  content: ''; width: 6px; height: 6px; border-radius: 999px;
  background: var(--muted-2); flex-shrink: 0;
}
.status.dirty { color: var(--warn); }
.status.dirty::before { background: var(--warn); animation: pulse-dot 1.6s var(--ease) infinite; }
.status.saved { color: var(--accent-ink); }
.status.saved::before { background: var(--accent); }
.status.error { color: var(--danger); }
.status.error::before { background: var(--danger); }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180,83,9,0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(180,83,9,0.15); }
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
  overflow: hidden;
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-section { padding: 16px 0 8px; }
.sidebar-heading {
  padding: 0 16px 8px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.nav { list-style: none; padding: 0; margin: 0; }
.nav li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px;
  cursor: pointer; user-select: none;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav li:hover { background: var(--hover); color: var(--ink); }
.nav li.active {
  color: var(--ink);
  background: var(--surface-alt);
}
.nav li.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 2px; background: var(--ink); border-radius: 2px;
}
.nav .nav-icon { color: var(--muted-2); }
.nav li.active .nav-icon { color: var(--ink); }
.nav .nav-label { flex: 1; }
.nav .nav-count {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 400;
}
.nav li.active .nav-count { color: var(--muted); }

.sidebar-foot {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11.5px; color: var(--muted);
}
.legend-row { display: flex; align-items: center; gap: 8px; }

/* ── Content ── */
.content {
  padding: 32px 40px 80px;
  overflow-y: auto;
  max-width: 100%;
}
@media (max-width: 768px) {
  .content { padding: 20px 16px 60px; }
}

.page-head {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 28px;
  max-width: 720px;
}
.page-eyebrow {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
}
.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.018em;
  color: var(--ink);
}
.page-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  max-width: 60ch;
  line-height: 1.55;
}

/* ── Section blocks (dividers, no card overuse) ── */
.section-block {
  border-top: 1px solid var(--line);
  padding-top: 24px;
  margin-top: 32px;
  max-width: 720px;
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
}
.section-meta {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted-2);
}

/* ── Item rows (selects, zones) ── */
.items {
  display: flex; flex-direction: column;
  divide-y: 1px solid var(--line);
  max-width: 720px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.item {
  display: flex; gap: 8px; align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
}
.item:last-child { border-bottom: 0; }
.item:hover { background: rgba(244,244,245,0.4); }
.item input {
  flex: 1; padding: 7px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.item input:hover { background: var(--surface); border-color: var(--line); }
.item input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.04);
}

.item-add {
  display: flex; gap: 8px; align-items: center;
  margin-top: 16px;
  max-width: 720px;
}
.item-add input {
  flex: 1; padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.item-add input::placeholder { color: var(--muted-2); }
.item-add input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.04);
}

/* Empty state */
.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  max-width: 720px;
}

/* Warn banner (e.g., org has no zones) */
.banner-warn {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 14px;
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  color: var(--warn);
  font-size: 12.5px;
  max-width: 720px;
  margin-bottom: 12px;
}
.banner-warn .icon { color: var(--warn); }

/* ── Org selector chips ── */
.org-row {
  display: flex; gap: 8px; align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--line-soft);
}
.org-row:last-child { border-bottom: 0; }
.org-row input {
  flex: 1; padding: 7px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 500;
}
.org-row input:hover { background: var(--surface); border-color: var(--line); }
.org-row input:focus { outline: none; background: var(--surface); border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,0.04); }

.chip-zones {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: all var(--t-fast);
  white-space: nowrap;
}
.chip-zones:hover { color: var(--ink); border-color: var(--line-strong); }
.chip-zones.is-active {
  color: var(--ink);
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

/* ── Questions / drag-drop ── */
.q-list {
  display: flex; flex-direction: column;
  gap: 6px;
  max-width: 760px;
}
.q-row {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: grab;
  user-select: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
}
.q-row:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.q-row.dragging { opacity: 0.4; cursor: grabbing; }
.q-row.drop-above { box-shadow: 0 -2px 0 var(--accent); }
.q-row.drop-below { box-shadow: 0 2px 0 var(--accent); }
.q-row.hidden-q {
  background: var(--surface-alt);
  border-style: dashed;
}
.q-row.hidden-q .q-label { color: var(--muted); }
.q-row.hidden-q .q-key   { opacity: 0.5; }

.q-handle {
  display: grid; place-items: center;
  width: 22px; height: 22px;
  color: var(--muted-2);
  cursor: grab;
  transition: color var(--t-fast);
}
.q-handle:hover { color: var(--ink); }
.q-row.dragging .q-handle { cursor: grabbing; }

.q-main { flex: 1; min-width: 0; }
.q-label {
  font-weight: 500; font-size: 14px;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.q-meta {
  display: flex; gap: 8px; align-items: center;
  margin-top: 3px;
  font-size: 11.5px;
}
.q-key {
  font-family: 'Geist Mono', ui-monospace, monospace;
  color: var(--muted);
}

/* Type pills */
.q-badge, .legend-pill {
  display: inline-flex; align-items: center;
  padding: 1px 7px;
  border-radius: 4px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  border: 1px solid transparent;
}
.q-badge.type-select, .legend-pill.type-select { background: var(--surface-alt); color: var(--ink-soft); border-color: var(--line); }
.q-badge.type-text,   .legend-pill.type-text   { background: var(--warn-soft);   color: var(--warn);     border-color: #fde68a; }
.q-badge.type-location, .legend-pill.type-location { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.q-badge.type-file,   .legend-pill.type-file   { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }

.q-badge.depends {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}
.q-badge.depends::before { content: '↳ '; color: var(--muted-2); }

/* Switch */
.q-toggle {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.q-toggle-label {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 56px;
  text-align: right;
}
.q-row:not(.hidden-q) .q-toggle-label { color: var(--accent-ink); }

.switch {
  position: relative;
  display: inline-block;
  width: 32px; height: 18px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0; width: 0; height: 0;
  position: absolute;
}
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background var(--t-fast);
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 14px; width: 14px;
  left: 2px; top: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(10,10,10,0.18);
  transition: transform var(--t-fast);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(14px); }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 3px rgba(16,185,129,0.18); }

/* ── Toast / inline status messages ── */
.toast-error {
  position: fixed; bottom: 20px; right: 20px;
  max-width: 360px;
  padding: 10px 14px;
  background: var(--ink);
  color: white;
  border-radius: var(--radius);
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  display: flex; gap: 8px; align-items: flex-start;
  opacity: 0; transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--t), transform var(--t);
}
.toast-error.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast-error .icon { color: #fbbf24; margin-top: 2px; }
