/* ============================================================
   Wage Wise — Brand CSS
   All custom properties used throughout the app.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;600;700&display=swap');

:root {
  /* Brand palette */
  --primary:        #1e4d4f;
  --primary-light:  #cfdedb;
  --teal:           #2c8b94;
  --gold:           #c89b3c;
  --gold-light:     #e6c87a;
  --surface:        #faf7ee;
  --surface-offset: #ebe5d4;
  --background:     #f5f1e8;
  --text:           #1f2a2a;
  --text-muted:     #5b6a6a;
  --text-inverse:   #faf7ee;
  --border:         #cfc8b4;
  --divider:        #d9d3c2;

  /* Survey stat colors */
  --stat-above: #15803d;
  --stat-below: #b91c1c;

  /* Spacing tokens */
  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(30,77,79,.08), 0 1px 2px rgba(30,77,79,.04);
  --shadow:    0 4px 16px rgba(30,77,79,.10), 0 2px 6px rgba(30,77,79,.06);
  --shadow-lg: 0 12px 32px rgba(30,77,79,.14), 0 4px 12px rgba(30,77,79,.08);
}

/* ── Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--primary);
  line-height: 1.2;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell ──────────────────────────────────────────── */
.app-header {
  background: var(--primary);
  color: var(--text-inverse);
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  flex-shrink: 0;
}

.app-header-logo {
  height: 40px;
  width: auto;
  border-radius: var(--radius-sm);
}

.app-header-wordmark {
  display: flex;
  flex-direction: column;
}

.app-header-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold-light);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.app-header-tagline {
  font-size: 0.68rem;
  color: var(--primary-light);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.app-header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

.app-header-nav a {
  color: var(--primary-light);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.app-header-nav a:hover,
.app-header-nav a.active {
  background: rgba(255,255,255,.12);
  color: #fff;
  text-decoration: none;
}

/* User dropdown */
.user-menu {
  position: relative;
  margin-left: 0.5rem;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: var(--text-inverse);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: 'Inter', sans-serif;
}

.user-menu-trigger:hover {
  background: rgba(255,255,255,.18);
}

.user-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
}

.user-menu.open .user-menu-dropdown { display: block; }

.user-menu-dropdown a,
.user-menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  text-decoration: none;
  transition: background 0.1s;
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
  background: var(--surface-offset);
}

.user-menu-dropdown hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: 0;
}

/* ── Page layout ────────────────────────────────────────── */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.app-main.full-width {
  max-width: 100%;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: visible;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-offset) 100%);
}

.card-header h2, .card-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.card-body { padding: 1.5rem; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1.125rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.btn-gold {
  background: var(--gold);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-teal {
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover { background: var(--primary-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface-offset); }

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.form-label .required { color: #dc2626; margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(44,139,148,.15);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235b6a6a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.78rem;
  color: #dc2626;
  margin-top: 0.25rem;
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  border-left: 4px solid transparent;
}

.alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }

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

table.ww-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.ww-table th {
  background: var(--primary);
  color: var(--text-inverse);
  font-weight: 600;
  padding: 0.625rem 0.875rem;
  text-align: left;
  white-space: nowrap;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ww-table td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
}

.ww-table tr:last-child td { border-bottom: none; }
.ww-table tbody tr:hover { background: var(--surface-offset); }

.ww-table .stat-above { color: var(--stat-above); font-weight: 600; }
.ww-table .stat-below { color: var(--stat-below); font-weight: 600; }

/* Survey-specific stat rows */
.ww-table tr.row-median td { background: #f0f9ff; font-weight: 600; }
.ww-table tr.row-pct    td { background: #f8f4ff; font-style: italic; font-size: 0.82rem; }
.ww-table tr.row-average td { background: #fffbeb; font-weight: 600; }
.ww-table tr.row-blank  td { padding: 4px; background: transparent; }
.ww-table tr.row-home td { background: var(--primary-light); font-weight: 700; }
.ww-table tr.row-home td { color: var(--primary); }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.5rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
  transition: background 0.1s;
}

.pagination a:hover { background: var(--surface-offset); }
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.dots { border: none; background: none; color: var(--text-muted); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: var(--surface-offset); color: var(--text-muted); }
.badge-teal   { background: var(--primary-light); color: var(--primary); }

/* ── Survey builder wizard ──────────────────────────────── */
.wizard-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  align-items: start;
}

.wizard-rail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: sticky;
  top: 80px;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
  transition: background 0.1s, color 0.1s;
}

.wizard-step.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.wizard-step.completed {
  color: var(--stat-above);
}

.wizard-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wizard-step.active .wizard-step-num {
  background: var(--primary);
  color: #fff;
}

.wizard-step.completed .wizard-step-num {
  background: var(--stat-above);
  color: #fff;
}

.wizard-panel { display: none; }
.wizard-panel.active { display: block; }

.wizard-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--divider);
}

/* ── Data-point toggle panel ────────────────────────────── */
.dp-group {
  margin-bottom: 1.5rem;
}

.dp-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--divider);
}

.dp-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.5rem;
}

.dp-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
}

.dp-toggle:hover { border-color: var(--teal); background: var(--primary-light); }
.dp-toggle.checked { border-color: var(--primary); background: var(--primary-light); }
.dp-toggle.disabled { opacity: 0.6; cursor: not-allowed; }

.dp-toggle input[type=checkbox] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.dp-toggle-info {}
.dp-toggle-label { font-size: 0.875rem; font-weight: 600; color: var(--text); display: block; }
.dp-toggle-desc  { font-size: 0.75rem; color: var(--text-muted); }

.dp-more-section {
  margin-top: 1.5rem;
}

.dp-more-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--teal);
  user-select: none;
  padding: 0.5rem 0;
  border-top: 1px solid var(--divider);
}

.dp-more-content { display: none; margin-top: 1rem; }
.dp-more-content.open { display: block; }

/* ── Typeahead ──────────────────────────────────────────── */
.typeahead-wrap { position: relative; }

.typeahead-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 50;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: none;
}

.typeahead-dropdown.open { display: block; }

.typeahead-item {
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--divider);
  transition: background 0.1s;
}

.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover, .typeahead-item.focused { background: var(--primary-light); }
.typeahead-item small { color: var(--text-muted); font-size: 0.75rem; }

/* ── Multi-select chip list ─────────────────────────────── */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  min-height: 40px;
  padding: 0.375rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  background: var(--primary-light);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 500;
}

.chip-remove {
  cursor: pointer;
  color: var(--primary);
  font-size: 1rem;
  line-height: 1;
  background: none;
  border: none;
  padding: 0;
  opacity: 0.6;
}

.chip-remove:hover { opacity: 1; }

/* ── Dashboard tiles ────────────────────────────────────── */
.dash-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: box-shadow 0.2s, transform 0.2s;
  text-decoration: none;
  color: inherit;
}

.dash-tile:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  text-decoration: none;
}

.dash-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.dash-tile-icon.teal  { background: var(--primary-light); color: var(--primary); }
.dash-tile-icon.gold  { background: #fef9c3; color: var(--gold); }
.dash-tile-icon.green { background: #dcfce7; color: var(--stat-above); }

.dash-tile h3 { margin: 0; font-size: 1.1rem; }
.dash-tile p  { margin: 0; font-size: 0.875rem; color: var(--text-muted); }

.stat-block { display: flex; align-items: baseline; gap: 0.5rem; }
.stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); font-family: 'Playfair Display', serif; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* ── Page header ────────────────────────────────────────── */
.page-header {
  margin-bottom: 1.75rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 { margin: 0; font-size: 1.75rem; }
.page-header p  { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.9rem; }

/* ── Footer ─────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--divider);
  margin-top: 3rem;
}

/* ── Utility ────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.currency::before { content: '$'; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.justify-between { justify-content: space-between; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-main { padding: 1rem 1rem 3rem; }

  .wizard-layout {
    grid-template-columns: 1fr;
  }

  .wizard-rail {
    position: static;
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    padding: 0.5rem;
  }

  .wizard-step {
    flex-shrink: 0;
    flex-direction: column;
    text-align: center;
    font-size: 0.75rem;
    padding: 0.5rem;
    min-width: 60px;
  }

  .wizard-step-num { width: 20px; height: 20px; font-size: 0.7rem; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .page-header { flex-direction: column; }

  .app-header-tagline { display: none; }

  .app-header-nav a { padding: 0.375rem 0.5rem; font-size: 0.8rem; }
}

/* ── Phase 4.5: Sortable column list + live preview ─────── */
.sortable-cols {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sortable-col {
  display: grid;
  grid-template-columns: 24px 22px 1fr auto;
  align-items: center;
  gap: 0.625rem;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.sortable-col:hover {
  border-color: var(--teal, var(--primary));
  background: var(--primary-light);
}

.sortable-col.checked {
  border-color: var(--primary);
  background: var(--primary-light);
}

.sortable-col.currency.checked { /* premium row when active */ }

.sortable-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  user-select: none;
  text-align: center;
  letter-spacing: -2px;
  font-weight: 700;
}

.sortable-handle:active { cursor: grabbing; }

.sortable-enable {
  display: flex;
  align-items: center;
  margin: 0;
  cursor: pointer;
}

.sortable-enable input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  margin: 0;
}

.sortable-info {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.sortable-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.sortable-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sortable-subtotal {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-offset);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.sortable-subtotal input[type=checkbox] {
  width: 13px;
  height: 13px;
  accent-color: var(--gold);
  margin: 0;
}

.sortable-subtotal:hover { border-color: var(--gold); }

.sortable-subtotal:has(input:checked) {
  background: var(--gold-light);
  border-color: var(--gold);
  color: var(--primary);
  font-weight: 600;
}

.sortable-subtotal-sigma {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--gold);
}

.sortable-subtotal:has(input:checked) .sortable-subtotal-sigma { color: var(--primary); }

.sortable-subtotal-placeholder {
  display: inline-block;
  width: 70px;
  /* keep alignment when non-currency rows have no Σ toggle */
}

.sortable-ghost {
  opacity: 0.5;
  background: var(--gold-light);
  border-style: dashed;
}

/* Live preview row */
.dp-preview-card {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--surface);
  border: 1px dashed var(--gold);
  border-radius: var(--radius);
}

.dp-preview-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0 0 0.5rem 0;
}

.dp-preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.dp-preview-cell {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.74rem;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.dp-preview-cell.meta {
  background: var(--surface-offset);
  font-weight: 600;
  color: var(--primary);
}

.dp-preview-cell.base {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.dp-preview-cell.in-sub {
  border-color: var(--gold);
  background: #fff;
  color: var(--text);
}

.dp-preview-cell.in-sub::before {
  content: "Σ ";
  color: var(--gold);
  font-weight: 700;
}

.dp-preview-cell.standalone {
  border-style: dashed;
  color: var(--text-muted);
}

.dp-preview-cell.calc {
  background: var(--gold-light);
  border-color: var(--gold);
  color: var(--primary);
  font-weight: 700;
}

.dp-preview-cell.tail {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

.dp-preview-sep {
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 0 0.1rem;
}

.dp-preview-note {
  margin-top: 0.55rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.dp-preview-note .dp-preview-key {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-radius: 2px;
  margin: 0 0.2rem 0 0.4rem;
  vertical-align: -1px;
}

/* Phase 4.5 fixes: prevent grid blowout from long descriptions */
.sortable-col .sortable-info {
  min-width: 0; /* allow flex/grid item to shrink below content */
}
.sortable-col .sortable-info > * {
  min-width: 0;
}
.sortable-col {
  grid-template-columns: 18px 18px minmax(0, 1fr) auto;
  align-items: center;
}
.sortable-col .sortable-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sortable-handle {
  font-size: 0.95rem;
}

/* Phase 4.5 fix v2: enable checkbox column must not expand */
.sortable-col .sortable-enable {
  width: 18px;
  flex: none;
}
.sortable-col {
  grid-template-columns: 20px 20px minmax(0, 1fr) auto !important;
  column-gap: 0.75rem;
}
.sortable-col .sortable-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  overflow: hidden;
}
.sortable-col .sortable-label {
  display: block;
  text-align: left;
}
.sortable-col .sortable-desc {
  display: block;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Phase 4.5 fix v3: assign explicit grid columns so whitespace text nodes
   don't shift items into wrong tracks */
.sortable-col > .sortable-handle    { grid-column: 1; }
.sortable-col > .sortable-enable    { grid-column: 2; }
.sortable-col > .sortable-info      { grid-column: 3; }
.sortable-col > .sortable-subtotal,
.sortable-col > .sortable-subtotal-placeholder { grid-column: 4; }

/* Phase 4.5 fix v4: switch from grid to flexbox to avoid whitespace text-node
   grid items messing up the layout. */
.sortable-col {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
}
.sortable-col > .sortable-handle    { flex: 0 0 18px; }
.sortable-col > .sortable-enable    { flex: 0 0 18px; }
.sortable-col > .sortable-info      { flex: 1 1 auto; min-width: 0; }
.sortable-col > .sortable-subtotal,
.sortable-col > .sortable-subtotal-placeholder { flex: 0 0 auto; }

/* ── Typeahead / Autocomplete Fix ───────────────────────── */

.typeahead-wrap {
  position: relative;
  overflow: visible !important;
}

.typeahead-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;

  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);

  z-index: 99999;

  max-height: 320px;
  overflow-y: auto;

  box-shadow: var(--shadow);

  display: none;
}

.typeahead-dropdown.open {
  display: block;
}

.typeahead-item {
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--divider);
  transition: background 0.1s;
  background: var(--surface);
}

.typeahead-item:last-child {
  border-bottom: none;
}

.typeahead-item:hover,
.typeahead-item.focused {
  background: var(--primary-light);
}

.typeahead-item small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Prevent wizard/card clipping */

.wizard-layout,
.wizard-panel,
.card,
.card-body {
  overflow: visible !important;
}