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

:root {
  --sidebar-w: 232px;
  --sidebar-bg: #0f172a;
  --sidebar-border: rgba(255,255,255,.06);
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #e2e8f0;
  --sidebar-active-bg: rgba(99,102,241,.18);
  --sidebar-active-text: #a5b4fc;
  --sidebar-active-border: #6366f1;
  --sidebar-logo-text: #f1f5f9;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --secondary: #64748b;
  --danger: #ef4444;
  --border: #d1d5db;
  --text-muted: #6b7280;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body { font-family: var(--font); font-size: 14px; background: #f1f5f9; color: #1a1a2e; display: flex; min-height: 100vh; }
#app { display: flex; flex: 1; min-height: 100vh; }

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────── */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; width: 100%; }
.login-box { background: #fff; padding: 40px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.10); width: 340px; }
.login-box h1 { text-align: center; margin-bottom: 4px; font-size: 22px; color: var(--accent); }
.login-sub { text-align: center; color: #94a3b8; font-size: 13px; margin-bottom: 28px; }
.login-box input { width: 100%; padding: 10px 14px; margin-bottom: 14px; border: 1px solid #dde1e7; border-radius: 8px; font-size: 14px; outline: none; transition: border .2s; }
.login-box input:focus { border-color: var(--accent); }
.login-box button { width: 100%; padding: 11px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; transition: background .2s; }
.login-box button:hover { background: var(--accent-dark); }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-text {
  color: var(--sidebar-logo-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}
.sidebar-logo-sub {
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-section-label {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--sidebar-text-hover);
  padding: 11px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s;
  text-align: left;
}

.nav-section-label.is-open,
.nav-section-label.has-active {
  background: rgba(255,255,255,.06);
}

.nav-group-toggle-label {
  flex: 1;
}

.nav-group-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sidebar-text);
  transition: transform .15s ease, color .15s ease;
}

.nav-section-label.is-open .nav-group-chevron,
.nav-section-label.has-active .nav-group-chevron {
  color: var(--sidebar-text-hover);
}

.nav-section-label.is-open .nav-group-chevron,
.nav-section-label.has-active .nav-group-chevron {
  transform: rotate(180deg);
}

.nav-group-items {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 6px;
}

.nav-group-items.is-open,
.nav-group-items.has-active {
  display: flex;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 10px;
  padding: 9px 10px 9px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.nav-link:hover {
  background: rgba(255,255,255,.06);
  color: var(--sidebar-text-hover);
}
.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--sidebar-active-border);
}
.nav-link svg { flex-shrink: 0; opacity: .8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--sidebar-text);
}
.sidebar-user span { flex: 1; color: var(--sidebar-text-hover); font-weight: 500; }
.sidebar-logout {
  padding: 4px 10px;
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  background: none;
  color: var(--sidebar-text);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.sidebar-logout:hover { background: rgba(255,255,255,.08); color: var(--sidebar-text-hover); }

/* ── Main layout ───────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.content { padding: 24px; flex: 1; max-width: 1200px; width: 100%; }
.tab-content iframe { width: 100%; height: 100vh; border: none; display: block; }
.iframe-active .content { padding: 0; max-width: none; }

/* ── Content ───────────────────────────────────────────────── */
.tab-content { padding: 0; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.toolbar h2 { font-size: 18px; font-weight: 600; color: #0f172a; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary { padding: 8px 18px; background: var(--accent); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; transition: background .2s; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-icon { padding: 5px 10px; border: 1px solid #e5e7eb; border-radius: 6px; background: none; cursor: pointer; font-size: 13px; color: #6b7280; transition: all .2s; margin-left: 4px; }
.btn-icon:hover { background: #f3f4f6; }
.btn-danger { border-color: #fca5a5; color: #ef4444; }
.btn-danger:hover { background: #fef2f2; }
.btn-secondary { padding: 8px 18px; border: 1px solid #d1d5db; border-radius: 8px; background: none; cursor: pointer; font-size: 14px; color: #374151; transition: background .2s; }
.btn-secondary:hover { background: #f9fafb; }

/* ── Table ─────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 6px rgba(0,0,0,.06); }
th { padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: #6b7280; background: #f9fafb; border-bottom: 1px solid #e5e7eb; }
td { padding: 12px 16px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

.q-question-row td {
  transition: background .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.q-question-row.is-drag-source td {
  opacity: .55;
  background: #eef2ff;
}

.q-question-row.is-drop-before td {
  box-shadow: inset 0 3px 0 var(--accent);
}

.q-question-row.is-drop-after td {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.q-question-row.is-saved td {
  background: #dcfce7;
}

.q-order-cell {
  vertical-align: top;
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
}

.q-order-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.q-order-number {
  line-height: 1;
}

.q-drag-handle {
  width: 28px;
  height: 28px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: var(--secondary);
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.q-drag-handle:hover {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: var(--accent-dark);
}

.q-drag-handle:active {
  cursor: grabbing;
}

.q-reorder-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Toggle ────────────────────────────────────────────────── */
.toggle { position: relative; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #d1d5db; border-radius: 20px; cursor: pointer; transition: .2s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle-slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Modal ─────────────────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 95vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,.18); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid #e5e7eb; }
.modal-header h3 { font-size: 16px; }
#modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: #9ca3af; line-height: 1; }
#modal-close:hover { color: #374151; }
#modal-body { padding: 24px; }

/* ── Form ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none; transition: border .2s; font-family: inherit; }
.form-group textarea { height: 140px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Handbook column filters ───────────────────────────────── */
.hb-col-filter {
  display: block; width: 100%; margin-top: 5px; padding: 3px 6px;
  font-size: 11px; font-weight: normal; letter-spacing: 0; text-transform: none;
  color: #374151; background: #fff; border: 1px solid #d1d5db; border-radius: 4px;
  outline: none; transition: border .2s;
}
.hb-col-filter:focus { border-color: var(--accent); }
#handbook-table th { vertical-align: top; }

/* ── Misc ──────────────────────────────────────────────────── */
.error { color: #ef4444; font-size: 13px; margin-top: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.badge-active { background: #dcfce7; color: #16a34a; }
.badge-inactive { background: #f3f4f6; color: #9ca3af; }
.stage-label { font-size: 12px; color: #6b7280; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.page-subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.confirmation-templates-toolbar {
  align-items: flex-start;
  gap: 16px;
}

.confirmation-templates-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.confirmation-templates-status {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #dbe3f0;
  background: #fff;
  color: #334155;
  font-size: 13px;
}

.confirmation-templates-status.is-success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.confirmation-templates-status.is-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.confirmation-templates-status.is-neutral {
  border-color: #dbe3f0;
  background: #fff;
  color: #334155;
}

.confirmation-templates-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.confirmation-template-list-panel,
.confirmation-template-editor-panel {
  background: #fff;
  border: 1px solid #dbe3f0;
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.confirmation-template-panel-head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid #edf2f7;
}

.confirmation-template-panel-head h3 {
  font-size: 16px;
  color: #0f172a;
}

.confirmation-template-panel-head p {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.confirmation-template-code {
  margin-top: 6px;
  font-size: 12px;
  color: #475569;
  font-family: 'Consolas', 'Courier New', monospace;
}

.confirmation-template-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.confirmation-template-list-empty {
  padding: 16px;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 13px;
}

.confirmation-template-list-item {
  width: 100%;
  padding: 14px;
  border: 1px solid #dbe3f0;
  border-radius: 14px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.confirmation-template-list-item:hover {
  border-color: #a5b4fc;
  box-shadow: 0 8px 18px rgba(99, 102, 241, 0.08);
  transform: translateY(-1px);
}

.confirmation-template-list-item.is-active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #eef2ff 0%, #ffffff 100%);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.12);
}

.confirmation-template-list-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.confirmation-template-list-title {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.confirmation-template-list-code {
  margin-top: 4px;
  font-size: 12px;
  color: #64748b;
  font-family: 'Consolas', 'Courier New', monospace;
}

.confirmation-template-list-snippet {
  margin-top: 12px;
  color: #475569;
  font-size: 13px;
  line-height: 1.5;
}

.confirmation-template-list-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.confirmation-template-list-badge.is-warning {
  background: #fef3c7;
  color: #92400e;
}

.confirmation-template-note {
  margin: 18px 20px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  border: 1px solid #dbeafe;
  color: #1e3a8a;
  font-size: 13px;
  line-height: 1.55;
}

.confirmation-template-draft-note {
  margin: 14px 20px 0;
  color: #475569;
  font-size: 13px;
  line-height: 1.5;
}

.confirmation-template-empty {
  margin: 18px 20px 20px;
  padding: 32px 20px;
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
  background: #f8fafc;
  color: #475569;
  text-align: center;
}

.confirmation-template-empty h4 {
  margin-bottom: 10px;
  font-size: 16px;
  color: #0f172a;
}

.confirmation-template-form {
  padding: 18px 20px 22px;
}

.confirmation-template-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.confirmation-template-field {
  display: grid;
  gap: 8px;
}

.confirmation-template-field.is-wide {
  grid-column: 1 / -1;
}

.confirmation-template-field span {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.confirmation-template-field input,
.confirmation-template-field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  color: #0f172a;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  background: #fff;
}

.confirmation-template-field textarea {
  resize: vertical;
  min-height: 120px;
}

.confirmation-template-field input:focus,
.confirmation-template-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.confirmation-template-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.confirmation-template-preview {
  padding: 0 20px 22px;
}

.confirmation-template-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.confirmation-template-preview-card {
  padding: 16px;
  border-radius: 16px;
  border: 1px solid #dbe3f0;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  min-height: 220px;
}

.confirmation-template-preview-card.is-success {
  border-color: #bbf7d0;
  background: linear-gradient(180deg, #ffffff 0%, #f0fdf4 100%);
}

.confirmation-template-preview-card.is-expired {
  border-color: #fde68a;
  background: linear-gradient(180deg, #ffffff 0%, #fffbeb 100%);
}

.confirmation-template-preview-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #64748b;
  text-transform: uppercase;
}

.confirmation-template-preview-card h4 {
  margin-top: 12px;
  font-size: 18px;
  line-height: 1.3;
  color: #0f172a;
}

.confirmation-template-preview-copy {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
}

.confirmation-template-preview-button {
  margin-top: 18px;
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  opacity: 1;
}

@media (max-width: 1100px) {
  .confirmation-templates-layout {
    grid-template-columns: 1fr;
  }

  .confirmation-template-preview-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .confirmation-template-form-grid {
    grid-template-columns: 1fr;
  }

  .confirmation-template-actions,
  .confirmation-templates-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .confirmation-templates-toolbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}
