:root {
  --navy: #141f3a;
  --navy-2: #202d4d;
  --gold: #ffbd1a;
  --gold-soft: #fff4ca;
  --ink: #172033;
  --muted: #697184;
  --line: #e1e5ec;
  --line-dark: #cfd5df;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --surface-blue: #eef2f8;
  --success: #198754;
  --danger: #ba2d37;
  --shadow: 0 18px 50px rgba(20, 31, 58, 0.09);
  --radius: 18px;
  --sidebar: 250px;
  --topbar: 76px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-soft); }
body { margin: 0; min-height: 100vh; color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--surface-soft); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(420px, 0.88fr); }
.auth-brand-panel { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 52px clamp(42px, 7vw, 110px); color: white; background: var(--navy); }
.auth-brand-panel::before { content: ""; position: absolute; width: 430px; height: 430px; border: 90px solid rgba(255, 189, 26, .95); border-radius: 50%; right: -230px; top: -180px; }
.auth-brand-panel::after { content: ""; position: absolute; width: 250px; height: 250px; border-radius: 28px; background: rgba(255,255,255,.035); transform: rotate(28deg); left: -100px; bottom: 90px; }
.auth-brand-panel > * { position: relative; z-index: 1; }
.auth-copy { max-width: 720px; margin: 80px 0; }
.auth-copy h1 { max-width: 690px; margin: 12px 0 22px; font-size: clamp(2.7rem, 5vw, 5.2rem); line-height: .99; letter-spacing: -.055em; }
.auth-copy > p:last-child { max-width: 620px; color: rgba(255,255,255,.73); font-size: 1.12rem; line-height: 1.7; }
.auth-feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.auth-feature-grid div { padding: 18px 20px; border: 1px solid rgba(255,255,255,.14); border-radius: 15px; background: rgba(255,255,255,.055); backdrop-filter: blur(6px); }
.auth-feature-grid strong { display: block; color: var(--gold); font-size: 1.35rem; }
.auth-feature-grid span { display: block; margin-top: 4px; color: rgba(255,255,255,.7); font-size: .83rem; }
.auth-form-panel { display: grid; place-items: center; padding: 40px; background: #fff; }
.login-card { width: min(460px, 100%); }
.login-card h2 { margin: 8px 0 10px; color: var(--navy); font-size: 2.15rem; letter-spacing: -.035em; }
.mobile-brand { display: none !important; margin-bottom: 45px; }

.brand-lockup { display: inline-flex; align-items: center; gap: 12px; color: var(--navy); }
.brand-lockup-light { color: white; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--navy); background: var(--gold); font-size: .9rem; font-weight: 900; letter-spacing: -.03em; box-shadow: 0 8px 20px rgba(255,189,26,.18); }
.brand-lockup strong, .brand-lockup small { display: block; line-height: 1.1; }
.brand-lockup strong { font-size: .95rem; }
.brand-lockup small { margin-top: 3px; opacity: .66; font-size: .74rem; }
.eyebrow { margin: 0; color: #9a6c00; font-size: .71rem; font-weight: 850; letter-spacing: .16em; }
.auth-brand-panel .eyebrow { color: var(--gold); }
.muted { color: var(--muted); line-height: 1.55; }
.field-label { display: block; margin: 24px 0 8px; color: var(--navy); font-size: .82rem; font-weight: 760; }
input, textarea, select { width: 100%; border: 1px solid var(--line-dark); border-radius: 11px; padding: 13px 14px; color: var(--ink); background: #fff; outline: none; transition: border-color .18s, box-shadow .18s, background .18s; }
input:focus, textarea:focus, select:focus { border-color: var(--navy); box-shadow: 0 0 0 4px rgba(20,31,58,.08); }
textarea { min-height: 104px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #a0a6b2; }
.form-error { min-height: 20px; color: var(--danger); font-size: .82rem; }
.legal-small { margin-top: 22px; color: var(--muted); font-size: .76rem; line-height: 1.55; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; padding: 0 18px; border: 1px solid transparent; border-radius: 10px; font-weight: 760; transition: transform .14s, box-shadow .14s, background .14s, border-color .14s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button-primary { color: var(--navy); background: var(--gold); box-shadow: 0 8px 20px rgba(255,189,26,.22); }
.button-primary:hover { background: #ffc72f; }
.button-secondary { color: var(--navy); border-color: var(--line-dark); background: #fff; }
.button-secondary:hover { border-color: var(--navy); }
.button-ghost { color: var(--navy); background: transparent; }
.button-full { width: 100%; margin-top: 26px; }
.button-small { min-height: 38px; padding: 0 14px; font-size: .82rem; }

.app-shell { min-height: 100vh; }
.topbar { position: fixed; z-index: 30; inset: 0 0 auto 0; height: var(--topbar); display: flex; align-items: center; justify-content: space-between; padding: 0 26px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.save-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .78rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.save-status.saving .status-dot { background: var(--gold); animation: pulse 1s infinite; }
.save-status.error .status-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
.user-chip { display: inline-flex; align-items: center; gap: 9px; padding: 5px 10px 5px 5px; border: 0; border-radius: 999px; color: var(--navy); background: var(--surface-blue); font-size: .78rem; font-weight: 720; }
.user-chip > span:first-child { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; color: var(--navy); background: var(--gold); font-weight: 900; }
.user-menu { position: fixed; z-index: 60; top: 65px; right: 24px; min-width: 185px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.user-menu button { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; text-align: left; color: var(--ink); background: transparent; }
.user-menu button:hover { background: var(--surface-soft); }

.sidebar { position: fixed; z-index: 20; top: var(--topbar); bottom: 0; left: 0; width: var(--sidebar); display: flex; flex-direction: column; justify-content: space-between; padding: 26px 16px 18px; border-right: 1px solid var(--line); background: #fff; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; text-align: left; font-weight: 700; }
.nav-item span { width: 20px; color: inherit; text-align: center; }
.nav-item:hover { color: var(--navy); background: var(--surface-soft); }
.nav-item.active { color: var(--navy); background: var(--gold-soft); }
.mini-card { display: flex; gap: 11px; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.mini-icon { display: grid; place-items: center; flex: 0 0 27px; height: 27px; border-radius: 50%; color: var(--navy); background: var(--gold); font-size: .75rem; font-weight: 900; }
.mini-card strong { display: block; color: var(--navy); font-size: .75rem; line-height: 1.35; }
.mini-card p { margin: 5px 0 0; color: var(--muted); font-size: .69rem; line-height: 1.45; }

.main-content { margin-left: var(--sidebar); padding: calc(var(--topbar) + 34px) clamp(24px, 4vw, 58px) 56px; }
.panel { display: none; max-width: 1420px; margin: 0 auto; }
.active-panel { display: block; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.page-heading h1 { margin: 7px 0 8px; color: var(--navy); font-size: clamp(2rem, 3vw, 3.1rem); line-height: 1.05; letter-spacing: -.045em; }
.page-heading p:last-child { max-width: 760px; margin: 0; color: var(--muted); }
.heading-actions { display: flex; gap: 10px; flex: 0 0 auto; }

.admin-edit-banner { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; padding: 13px 16px; border: 1px solid #f1d071; border-radius: 12px; background: #fff8df; color: var(--navy); }
.admin-edit-banner strong, .admin-edit-banner span { display: block; }
.admin-edit-banner span { margin-top: 2px; color: var(--muted); font-size: .8rem; }
.admin-edit-banner button { border: 0; color: var(--navy); background: transparent; font-weight: 760; }
.progress-card { margin-bottom: 22px; padding: 18px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 8px 26px rgba(20,31,58,.045); }
.progress-copy { display: flex; justify-content: space-between; margin-bottom: 10px; color: var(--navy); font-size: .83rem; font-weight: 730; }
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #eceff3; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--gold); transition: width .3s ease; }
.progress-card p { margin: 9px 0 0; color: var(--muted); font-size: .75rem; }
.builder-layout { display: grid; grid-template-columns: 265px minmax(0, 1fr); gap: 22px; align-items: start; }
.steps-card, .question-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 10px 30px rgba(20,31,58,.05); }
.steps-card { position: sticky; top: calc(var(--topbar) + 26px); padding: 12px; }
.step-list { display: grid; gap: 4px; }
.step-button { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 11px 10px; border: 0; border-radius: 10px; text-align: left; color: var(--muted); background: transparent; }
.step-button:hover { background: var(--surface-soft); }
.step-button.active { color: var(--navy); background: var(--gold-soft); }
.step-number { display: grid; place-items: center; width: 29px; height: 29px; border: 1px solid var(--line-dark); border-radius: 9px; font-size: .72rem; font-weight: 820; }
.step-button.active .step-number { border-color: var(--gold); background: var(--gold); }
.step-copy strong, .step-copy small { display: block; }
.step-copy strong { font-size: .79rem; }
.step-copy small { margin-top: 2px; color: var(--muted); font-size: .66rem; }
.step-check { color: var(--success); font-weight: 900; }
.question-card { min-height: 600px; padding: clamp(24px, 4vw, 44px); }
.question-header { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.question-header h2 { margin: 7px 0 7px; color: var(--navy); font-size: 1.75rem; letter-spacing: -.03em; }
.question-header p:last-child { margin: 0; }
.step-count { align-self: flex-start; padding: 6px 10px; border-radius: 999px; color: var(--navy); background: var(--surface-blue); font-size: .72rem; font-weight: 750; white-space: nowrap; }
.question-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 18px; padding: 28px 0; }
.question-field.full { grid-column: 1 / -1; }
.question-field label { display: flex; align-items: baseline; gap: 6px; margin-bottom: 7px; color: var(--navy); font-size: .82rem; font-weight: 760; }
.required-mark { color: #a56f00; }
.question-field .helper { min-height: 17px; margin: 7px 2px 0; color: var(--muted); font-size: .7rem; line-height: 1.45; }
.variable-chip { margin-left: auto; color: #7a8291; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .61rem; font-weight: 500; }
.question-footer { display: flex; justify-content: space-between; padding-top: 20px; border-top: 1px solid var(--line); }

.document-heading { margin-bottom: 20px; }
.document-toolbar { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.segmented { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.segmented button { padding: 8px 13px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: .78rem; font-weight: 730; }
.segmented button.active { color: var(--navy); background: var(--gold); }
.document-workspace { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.document-meta { display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 18px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.document-meta span, .document-meta strong { display: block; }
.document-meta span { color: var(--muted); font-size: .67rem; }
.document-meta strong { margin-top: 2px; color: var(--navy); font-size: .79rem; }
.legal-warning { padding-left: 16px; border-left: 4px solid var(--gold); }
.document-preview { min-height: 680px; max-height: calc(100vh - 280px); margin: 0; overflow: auto; padding: 40px clamp(24px, 5vw, 68px); color: #242b39; background: white; font: 14px/1.72 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.document-frame { width: 100%; min-height: 750px; border: 0; background: white; }

.admin-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; margin-bottom: 20px; }
.admin-stats div { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.admin-stats span, .admin-stats strong { display: block; }
.admin-stats span { color: var(--muted); font-size: .75rem; }
.admin-stats strong { margin-top: 8px; color: var(--navy); font-size: 1.85rem; }
.table-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 10px 30px rgba(20,31,58,.05); }
.table-tools { padding: 16px; border-bottom: 1px solid var(--line); }
.table-tools input { max-width: 420px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 17px; border-bottom: 1px solid var(--line); text-align: left; font-size: .8rem; }
th { color: var(--muted); background: var(--surface-soft); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
td strong, td small { display: block; }
td strong { color: var(--navy); }
td small { margin-top: 3px; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; justify-content: flex-end; gap: 7px; }
.table-button { padding: 7px 10px; border: 1px solid var(--line-dark); border-radius: 8px; color: var(--navy); background: #fff; font-size: .7rem; font-weight: 730; }
.table-button.primary { border-color: var(--gold); background: var(--gold); }
.role-badge { display: inline-block; margin-top: 5px; padding: 2px 7px; border-radius: 999px; color: var(--navy); background: var(--gold-soft); font-size: .61rem; font-weight: 800; }
.empty-row { padding: 40px; text-align: center; color: var(--muted); }

.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: 360px; padding: 13px 17px; border-radius: 11px; color: white; background: var(--navy); box-shadow: var(--shadow); font-size: .82rem; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.modal { width: min(440px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 16px; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(10,17,33,.6); backdrop-filter: blur(3px); }
.modal form { padding: 24px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; }
.modal-heading h2 { margin: 0; color: var(--navy); }
.modal-heading button { border: 0; color: var(--muted); background: transparent; font-size: 1.6rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

@media (max-width: 1050px) {
  :root { --sidebar: 205px; }
  .builder-layout { grid-template-columns: 215px minmax(0,1fr); }
  .question-fields { grid-template-columns: 1fr; }
  .question-field.full { grid-column: auto; }
  .auth-shell { grid-template-columns: 1fr 440px; }
  .auth-brand-panel { padding: 42px; }
}

@media (max-width: 820px) {
  .auth-shell { display: block; background: #fff; }
  .auth-brand-panel { display: none; }
  .auth-form-panel { min-height: 100vh; padding: 28px; }
  .mobile-brand { display: inline-flex !important; }
  :root { --topbar: 68px; }
  .topbar { padding: 0 14px; }
  .topbar > .brand-lockup span:last-child { display: none; }
  #user-email-top, .save-status { display: none; }
  .sidebar { position: fixed; z-index: 35; top: auto; right: 0; bottom: 0; width: 100%; height: 66px; padding: 7px 10px; border-top: 1px solid var(--line); border-right: 0; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .nav-item { justify-content: center; padding: 10px 7px; font-size: .69rem; }
  .nav-item span { width: auto; }
  .sidebar-bottom { display: none; }
  .main-content { margin-left: 0; padding: calc(var(--topbar) + 24px) 16px 90px; }
  .page-heading { display: block; }
  .heading-actions { margin-top: 18px; }
  .builder-layout { display: block; }
  .steps-card { position: static; margin-bottom: 14px; overflow-x: auto; }
  .step-list { display: flex; min-width: max-content; }
  .step-button { width: 170px; }
  .step-check { display: none; }
  .question-card { min-height: 0; padding: 24px 19px; }
  .document-toolbar { align-items: flex-start; flex-direction: column; }
  .document-meta { grid-template-columns: 1fr; }
  .legal-warning { padding: 10px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .admin-stats { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  #download-top { display: none; }
  .page-heading h1 { font-size: 2.15rem; }
  .heading-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .heading-actions .button { padding: 0 12px; }
  .question-header { display: block; }
  .step-count { display: inline-block; margin-top: 12px; }
  .question-footer { gap: 8px; }
  .question-footer .button { flex: 1; padding: 0 10px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .document-preview { padding: 25px 18px; }
  .admin-edit-banner { align-items: flex-start; flex-direction: column; }
}
