:root {
    --bg: #f8fafc;
    --bg-grad-from: #eef2ff;
    --bg-grad-to: #f8fafc;
    --card: #ffffff;
    --ink: #0f172a;
    --ink-soft: #475569;
    --muted: #94a3b8;
    --line: #e2e8f0;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --accent: #eef2ff;
    --ok: #16a34a;
    --warn: #b45309;
    --err: #dc2626;
    --radius: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 10px 30px rgba(15, 23, 42, 0.06);
    --shadow-pop: 0 4px 12px rgba(79, 70, 229, 0.15), 0 10px 30px rgba(79, 70, 229, 0.08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg-grad-from) 0%, var(--bg-grad-to) 400px);
    color: var(--ink);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }
body.admin .wrap { max-width: 1280px; padding-bottom: 40px; }
.brand {
    display: flex; align-items: center; gap: 10px; margin-bottom: 24px;
}
.brand-name { font-weight: 800; font-size: 22px; color: var(--primary); letter-spacing: -0.5px; }
.brand-logo { height: 48px; width: auto; display: block; }
.intro-card { text-align: center; padding: 40px 28px; }
.intro-logo { display: block; margin: 0 auto 20px; width: 220px; max-width: 80%; height: auto; }
.brand-sub  { color: var(--muted); font-size: 14px; font-weight: 500; }

h1 { font-size: 26px; margin: 0 0 12px; color: var(--ink); font-weight: 800; letter-spacing: -0.5px; line-height: 1.25; }
h2 { font-size: 20px; margin: 0 0 12px; color: var(--ink); font-weight: 700; letter-spacing: -0.3px; }
p  { margin: 0 0 14px; color: var(--ink-soft); font-size: 16px; }
a  { color: var(--primary); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
code { background: var(--accent); padding: 2px 6px; border-radius: 6px; font-size: 13px; font-family: "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); font-size: 14px; }
.hint  { color: var(--muted); font-size: 14px; margin: -4px 0 10px; font-style: italic; }

.card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 24px; margin-bottom: 14px; border: 1px solid var(--line);
    transition: box-shadow 0.2s;
}
.card.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }

/* Question card */
.q-card {
    border-left: none;
    position: relative;
    overflow: hidden;
}
.q-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary) 0%, #8b5cf6 100%);
    border-radius: 0 4px 4px 0;
}
legend, .q-title {
    font-weight: 700; color: var(--ink); padding: 0; font-size: 18px;
    display: block; margin-bottom: 6px; line-height: 1.35;
}
fieldset { border: none; padding: 0; margin: 0; }

/* Progress bar */
.progress {
    position: sticky; top: 0; z-index: 10;
    background: rgba(248, 250, 252, 0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    padding: 10px 0; margin: -20px -16px 16px; padding-left: 16px; padding-right: 16px;
    border-bottom: 1px solid var(--line);
}
.progress-track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.progress-label { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 4px; text-align: right; }

/* Options (radio/checkbox pills) */
.opt {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 16px 18px; margin: 10px 0; border: 2px solid var(--line);
    border-radius: 14px; cursor: pointer; user-select: none;
    background: #fff; transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 15.5px; color: var(--ink);
    position: relative;
}
.opt:active { transform: scale(0.98); }
.opt:hover { border-color: #cbd5e1; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .dot {
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid #cbd5e1;
    flex-shrink: 0; margin-top: 1px; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
    background: #fff;
}
.opt.check .dot { border-radius: 7px; }
.opt .dot::after {
    content: ""; width: 10px; height: 10px; border-radius: 50%;
    background: var(--primary); transform: scale(0);
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.opt.check .dot::after { border-radius: 3px; }
.opt input:checked ~ .dot {
    border-color: var(--primary); background: var(--primary-soft);
}
.opt input:checked ~ .dot::after { transform: scale(1); background: var(--primary); }
.opt input:checked ~ span.lbl { color: var(--primary); font-weight: 600; }
.opt:has(input:checked) {
    border-color: var(--primary); background: var(--primary-soft);
    box-shadow: var(--shadow-pop);
}
.opt-end { background: #fff7f5; border-color: #fecaca; }
.opt-end:has(input:checked) { background: #fef2f2; border-color: #dc2626; }
.opt-end:has(input:checked) span.lbl { color: #dc2626; }

.lbl { flex: 1; line-height: 1.45; }

/* Chip selector (Q2B) */
.chip-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 8px; margin-top: 8px; }
.chip {
    display: flex; align-items: center; justify-content: center;
    padding: 14px 8px; border: 2px solid var(--line); border-radius: 12px;
    cursor: pointer; background: #fff; transition: all 0.15s;
    font-weight: 700; font-size: 15px; color: var(--ink-soft);
    user-select: none;
}
.chip:active { transform: scale(0.95); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) {
    border-color: var(--primary); background: var(--primary);
    color: #fff; box-shadow: var(--shadow-pop);
    transform: scale(1.02);
}

/* Apartment cards (Q3) */
.apt-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 6px; }
.apt {
    display: block; padding: 0; border: 2px solid var(--line); border-radius: 14px;
    background: #fff; cursor: pointer; transition: all 0.15s;
    overflow: hidden; position: relative;
}
.apt:active { transform: scale(0.98); }
.apt input { position: absolute; opacity: 0; pointer-events: none; }
.apt-body { padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
.apt-icon {
    width: 44px; height: 44px; border-radius: 10px; background: var(--primary-soft);
    display: flex; align-items: center; justify-content: center; font-size: 22px;
    flex-shrink: 0; transition: all 0.15s;
}
.apt-info { flex: 1; min-width: 0; }
.apt-title { font-weight: 700; font-size: 16px; color: var(--ink); margin-bottom: 2px; }
.apt-meta { font-size: 13px; color: var(--muted); }
.apt-price { font-size: 18px; font-weight: 800; color: var(--primary); letter-spacing: -0.3px; margin-left: auto; flex-shrink: 0; }
.apt:has(input:checked) {
    border-color: var(--primary); background: var(--primary-soft);
    box-shadow: var(--shadow-pop);
}
.apt:has(input:checked) .apt-icon { background: var(--primary); color: #fff; }
.apt:has(input:checked) .apt-title { color: var(--primary); }
.apt.apt-none { border-style: dashed; }

.sub-field {
    margin-top: 12px; padding: 14px; background: var(--primary-soft); border-radius: 10px;
    animation: slideDown 0.25s ease;
}
.sub-field label { display: block; font-weight: 600; color: var(--ink); font-size: 14px; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

textarea, input[type=text], input[type=password] {
    width: 100%; padding: 12px 14px; margin-top: 8px; border: 2px solid var(--line);
    border-radius: 10px; font: inherit; background: #fff; color: var(--ink);
    font-size: 16px; transition: border-color 0.15s;
    -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 80px; }
textarea:focus, input:focus { outline: none; border-color: var(--primary); }

/* Inline action row (submit / review buttons) */
.actions-inline { margin-top: 8px; }
.actions-inline .btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.actions-inline .btn-row > * { flex: 1; min-width: 140px; }

/* Review / verification panel */
.review-panel { background: var(--accent); border: 2px solid var(--primary); }
.review-panel h2 { color: var(--primary); margin-bottom: 14px; }
.review-list { list-style: none; padding: 0; margin: 0 0 18px; }
.review-list > li { padding: 12px 0; border-bottom: 1px solid rgba(124,58,237,0.15); }
.review-list > li:last-child { border-bottom: none; }
.review-q { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 4px; }
.review-a { font-size: 16px; color: var(--text); line-height: 1.45; }
.review-a.empty { color: var(--muted); font-style: italic; }
.review-a ul { list-style: disc; padding-left: 20px; margin: 4px 0 0; }
.review-a .review-sub { display: block; margin-top: 4px; padding-left: 10px; border-left: 2px solid var(--primary); font-size: 14px; color: var(--muted); }

/* Field validation errors */
.field-error { display: none; color: var(--err); font-size: 14px; margin-top: 8px; font-weight: 600; }
.field-error.show { display: block; }
.q-card.has-error { border-color: var(--err); box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }

.btn-primary, .btn-secondary, .btn-danger {
    display: block; width: 100%; padding: 16px 24px; border: none; border-radius: 12px;
    font-size: 17px; font-weight: 700; cursor: pointer; transition: all 0.15s;
    letter-spacing: -0.2px; font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%); color: #fff; box-shadow: var(--shadow-pop); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn-secondary:hover { background: var(--accent); }
.btn-secondary:active { transform: scale(0.98); }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #991b1b; }

/* flashes */
.flash { padding: 14px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; font-size: 15px; }
.flash-success { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.flash-warning { background: #fffbeb; color: var(--warn); border: 1px solid #fef3c7; }
.flash-error   { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding-top: 24px; }

/* Revealed section animation */
.reveal { opacity: 0; transform: translateY(12px); transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.reveal.active { opacity: 1; transform: translateY(0); }

/* Mode badge */
.mode-badge { padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; margin-left: auto; }
.mode-test { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }

/* Gallery */
.gallery {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0;
}
.gallery-thumb {
    border: 0; padding: 0; background: none; cursor: pointer; border-radius: 10px;
    overflow: hidden; aspect-ratio: 1; transition: transform 0.15s;
}
.gallery-thumb:active { transform: scale(0.95); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.pdf-links { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 10px; }
.pdf-chip {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border: 2px solid var(--line); border-radius: 12px; background: #fff;
    text-decoration: none; transition: all 0.15s;
}
.pdf-chip:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }
.pdf-chip:active { transform: scale(0.98); }
.pdf-icon { font-size: 26px; flex-shrink: 0; }
.pdf-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pdf-title { font-weight: 700; color: var(--ink); font-size: 15px; }
.pdf-sub { font-size: 12px; color: var(--muted); }

.lightbox {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.95);
    z-index: 100; display: flex; align-items: center; justify-content: center;
    padding: 20px; animation: fadeIn 0.2s ease;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 90vh; object-fit: contain; border-radius: 8px; }
.lightbox-close {
    position: absolute; top: 16px; right: 16px; width: 44px; height: 44px;
    border-radius: 50%; background: rgba(255, 255, 255, 0.15); color: #fff;
    border: none; font-size: 28px; cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Admin */
.admin-nav {
    display: flex; gap: 6px; padding: 8px; background: #fff;
    border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px;
    box-shadow: var(--shadow-sm); overflow-x: auto; scrollbar-width: none;
}
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav a { padding: 8px 14px; border-radius: 10px; color: var(--ink-soft); font-weight: 600; white-space: nowrap; font-size: 14px; }
.admin-nav a.active { background: var(--primary-soft); color: var(--primary); }
.admin-nav a.right { margin-left: auto; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat-grid > div { background: var(--primary-soft); border-radius: 12px; padding: 18px; text-align: center; }
.stat-grid strong { display: block; font-size: 32px; color: var(--primary); font-weight: 800; letter-spacing: -1px; }
.stat-grid span { color: var(--muted); font-size: 13px; font-weight: 500; }

.bar-list { list-style: none; padding: 0; margin: 0; }
.bar-list li { margin: 12px 0; }
.bar-row { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.bar-label { color: var(--ink-soft); font-size: 14px; }
.bar-count { font-weight: 700; color: var(--primary); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); border-radius: 4px; transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); }

.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8fafc; font-weight: 600; color: var(--ink-soft); font-size: 13px; text-transform: uppercase; letter-spacing: 0.3px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.pill { background: var(--primary-soft); color: var(--primary); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: #f0fdf4; color: var(--ok); }
.pill.err { background: #fef2f2; color: var(--err); }
.pill-test { background: #fff7ed; color: #c2410c; }

.link-btn {
    background: none; border: 0; color: var(--primary); cursor: pointer;
    padding: 4px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; font-family: inherit;
}
.link-btn:hover { background: var(--primary-soft); }
.link-btn.danger { color: var(--err); }
.link-btn.danger:hover { background: #fef2f2; }
.actions-cell { white-space: nowrap; }

.two-col {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
}

.table-header {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.table-header h2 { margin: 0; }
.table-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-search { width: 220px; margin: 0; padding: 8px 12px; font-size: 14px; }
.chkbox { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.chkbox input { accent-color: var(--primary); width: 16px; height: 16px; }
.btn-sm { padding: 8px 14px !important; font-size: 14px !important; width: auto !important; }

.table-wrap.scrollable { max-height: 70vh; overflow: auto; }
.table-wrap.scrollable thead th {
    position: sticky; top: 0; background: #f8fafc; z-index: 5;
    box-shadow: 0 1px 0 var(--line);
}
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.cell-wrap { max-width: 260px; word-wrap: break-word; white-space: normal; }
.cell-item { font-size: 13px; line-height: 1.4; }
.cell-other { color: var(--muted); font-style: italic; margin-top: 4px; }
.col-sort::after { content: " ↕"; opacity: 0.3; font-size: 11px; }
.col-sort.sorted-asc::after { content: " ↑"; opacity: 1; color: var(--primary); }
.col-sort.sorted-desc::after { content: " ↓"; opacity: 1; color: var(--primary); }

.row.gap { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { font-weight: 500; color: var(--ink); display: block; }

@media (max-width: 480px) {
    h1 { font-size: 22px; }
    h2 { font-size: 17px; }
    .card { padding: 18px; }
    .opt { padding: 14px 16px; font-size: 15px; }
    .stat-grid strong { font-size: 26px; }
    legend, .q-title { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
