*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0f;
  --sidebar: #161618;
  --surface: #1e1e22;
  --surface2: #26262c;
  --border: #2e2e36;
  --text: #ececf1;
  --muted: #8e8ea0;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --warning: #f39c12;
  --input-bg: #2a2a32;
  --radius: 12px;
}

body {
  font-family: 'Sora', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LOGIN PAGE ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin: 0 auto 16px;
}

.login-logo h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }
.login-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--muted); }
.form-group input, .form-group textarea, .form-group select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-group select { cursor: pointer; }

.error-msg {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.3);
  color: #ff6b6b;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: var(--muted);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px;
  border: none; cursor: pointer;
  font-family: 'Sora', sans-serif; font-size: 13px; font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-full { width: 100%; justify-content: center; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── DASHBOARD LAYOUT ── */
.dashboard-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.admin-sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.admin-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.logo-text { font-weight: 600; font-size: 14px; }
.logo-badge { font-size: 10px; color: var(--muted); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-size: 13px; color: var(--muted);
  cursor: pointer; transition: all 0.15s;
  border: none; background: transparent; width: 100%;
  text-align: left; font-family: 'Sora', sans-serif;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--text); }
.nav-item svg { opacity: 0.7; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.admin-sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 56px;
}

.admin-topbar h2 { font-size: 16px; font-weight: 600; }

.admin-content {
  flex: 1; overflow-y: auto; padding: 24px;
}

/* ── TAB PANELS ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; }

/* ── QUESTION LIST ── */
.question-list { display: flex; flex-direction: column; gap: 8px; }

.question-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: default;
  transition: border-color 0.15s;
}
.question-item.dragging { opacity: 0.4; }
.question-item.drag-over { border-color: var(--accent); }

.drag-handle {
  color: var(--muted); cursor: grab; padding-top: 2px; flex-shrink: 0;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }

.question-item-body { flex: 1; min-width: 0; }
.question-item-text {
  font-size: 14px; line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 6px;
}
.question-item-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.5px;
}
.badge-mc { background: rgba(16,163,127,0.15); color: var(--accent); border: 1px solid rgba(16,163,127,0.3); }
.badge-ms { background: rgba(255,159,67,0.15); color: #ffb142; border: 1px solid rgba(255,159,67,0.3); }
.badge-ot { background: rgba(108,92,231,0.15); color: #a29bfe; border: 1px solid rgba(108,92,231,0.3); }
.badge-inactive { background: rgba(143,143,160,0.15); color: var(--muted); border: 1px solid var(--border); }

.question-item-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.question-item.inactive { opacity: 0.5; }
.question-item.inactive:hover { opacity: 0.8; }
.question-item.inactive .question-item-text { color: var(--muted); }

/* ── INLINE EDIT FORM ── */
.inline-edit {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 8px;
  display: flex; flex-direction: column; gap: 12px;
}
.inline-edit-row { display: flex; gap: 12px; align-items: flex-start; }
.inline-edit-row .form-group { flex: 1; }

.choices-editor { display: flex; flex-direction: column; gap: 8px; }
.choice-input-row { display: flex; gap: 8px; align-items: center; }
.choice-input-row input { flex: 1; }

/* ── TOGGLE ── */
.toggle-wrap { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle {
  position: relative; width: 36px; height: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 99px; cursor: pointer; transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle::after {
  content: ''; position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px;
  transition: transform 0.2s;
}
.toggle.on::after { transform: translateX(16px); }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

.session-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--muted);
}

/* ── DRAWER ── */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100;
  display: none;
}
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 480px; max-width: 95vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101; overflow-y: auto;
  transform: translateX(100%); transition: transform 0.3s ease;
  padding: 24px;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.drawer-title { font-size: 15px; font-weight: 600; }

.qa-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.qa-question { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.qa-answer { font-size: 14px; line-height: 1.5; }

/* ── STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stat-value { font-size: 36px; font-weight: 600; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.funnel-label { width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); flex-shrink: 0; }
.funnel-bar-wrap { flex: 1; height: 20px; background: var(--surface2); border-radius: 99px; overflow: hidden; position: relative; }
.funnel-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.5s ease; }
.funnel-count { font-size: 12px; color: var(--muted); white-space: nowrap; width: 60px; text-align: right; }

/* ── DB STATUS ── */
.db-info { display: flex; flex-direction: column; gap: 10px; }
.db-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.db-row-label { color: var(--muted); width: 120px; flex-shrink: 0; }
.db-row-value { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ── GENERIC INPUTS ── */
input:not([type="checkbox"]):not([type="date"]):not([type="radio"]) {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
input:not([type="checkbox"]):not([type="date"]):not([type="radio"]):focus {
  border-color: var(--accent);
}
input::placeholder { color: var(--muted); }

/* ── CHECKBOXES ── */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--input-bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
input[type="checkbox"]:checked,
input[type="checkbox"]:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 8px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg);
}
input[type="checkbox"]:indeterminate::after {
  content: '';
  position: absolute;
  left: 2px; top: 5px;
  width: 9px; height: 2px;
  background: #fff;
}

/* ── FILTER BAR ── */
.filter-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar input[type="date"] {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  outline: none;
}
.filter-bar input[type="date"]:focus { border-color: var(--accent); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── TOAST ── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  animation: slideIn 0.3s ease;
  max-width: 320px;
}
.toast.success { border-color: rgba(16,163,127,0.4); color: var(--accent); }
.toast.error { border-color: rgba(231,76,60,0.4); color: #ff6b6b; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── MOBILE SIDEBAR ── */
.sidebar-backdrop { display: none; }
.hamburger-btn    { display: none; }

@media (max-width: 768px) {
  .dashboard-layout { display: block; }

  .admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .admin-sidebar.open { transform: translateX(0); }

  .admin-main { height: 100vh; }

  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .hamburger-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: transparent; border: 1px solid var(--border);
    color: var(--muted); cursor: pointer;
    margin-right: 10px;
  }
}

/* ── Conditional question boxes ────────────────────────────────────────────── */

.choice-branch-wrapper {
  padding: 0 0 4px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 2000px;
  opacity: 1;
}

.choice-branch-wrapper.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  padding: 0 0 0 32px;
}

.choice-branch {
  border: 1px solid var(--border);
  border-left: 3px solid var(--branch-accent, #3b82f6);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.branch-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--branch-accent, #3b82f6);
  padding: 6px 12px;
  background: color-mix(in srgb, var(--branch-accent, #3b82f6) 12%, transparent);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.branch-list {
  min-height: 40px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.15s;
}

.branch-list.drag-over {
  background: color-mix(in srgb, var(--branch-accent, #3b82f6) 8%, var(--surface));
  outline: 2px dashed var(--branch-accent, #3b82f6);
  outline-offset: -2px;
  border-radius: 4px;
}

.branch-empty-hint {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 4px;
  font-style: italic;
}

.branch-question-item {
  font-size: 13px;
  padding: 8px 10px;
  margin: 0;
}

.branch-question-item .question-item-text {
  font-size: 13px;
}

.branch-add-btn {
  margin: 4px 8px 8px;
  font-size: 12px;
}

.branch-inline-add {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.branch-inline-add textarea,
.branch-inline-add input[type="text"],
.branch-inline-add select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

.branch-inline-add textarea:focus,
.branch-inline-add input[type="text"]:focus,
.branch-inline-add select:focus {
  border-color: var(--accent);
}

.branch-inline-add select option {
  background: var(--surface2);
}

.collapse-chevron {
  transition: transform 0.2s ease;
}

.collapse-chevron.rotated {
  transform: rotate(-90deg);
}

