:root {
    --primary: #1261a0;
    --primary-dark: #0a477a;
    --accent: #22a9d6;
    --background: #f4f7fa;
    --surface: #ffffff;
    --surface-alt: #edf3f8;
    --text: #17212b;
    --muted: #607080;
    --border: #dbe4ec;
    --success: #147d4f;
    --warning: #a45a00;
    --danger: #b42318;
    --info: #1261a0;
    --shadow: 0 12px 35px rgba(20, 43, 65, .09);
    --radius: 14px;
}

.theme-safety {
    --primary: #e3a600;
    --primary-dark: #aa7900;
    --accent: #1e252b;
    --background: #f7f5ef;
    --surface-alt: #fff8d9;
}

.theme-fresh {
    --primary: #087f6a;
    --primary-dark: #046253;
    --accent: #49bfa5;
    --background: #f1f8f6;
    --surface-alt: #e5f4f0;
}

.theme-dark {
    --primary: #e36c2f;
    --primary-dark: #bd4e18;
    --accent: #f0a173;
    --background: #171b20;
    --surface: #232930;
    --surface-alt: #2b333c;
    --text: #f5f7f8;
    --muted: #b6c0ca;
    --border: #3b4651;
    --shadow: 0 12px 35px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .7rem; }
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(1.1rem, 3vw, 1.7rem);
}

.button,
button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    min-height: 42px;
    padding: .65rem 1rem;
    border: 0;
    border-radius: 9px;
    color: #fff;
    background: var(--primary);
    font-weight: 700;
    text-decoration: none;
    transition: transform .15s ease, opacity .15s ease;
}

.button:hover { text-decoration: none; opacity: .92; transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button-secondary { color: var(--text); background: var(--surface-alt); border: 1px solid var(--border); }
.button-danger { background: var(--danger); }
.button-small { min-height: 34px; padding: .4rem .7rem; font-size: .86rem; }
.button-large { min-height: 50px; padding: .8rem 1.4rem; }
.button-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.alert {
    margin: 0 0 1rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    border-radius: 10px;
    padding: .8rem 1rem;
    background: var(--surface);
}
.alert-success { border-left-color: var(--success); }
.alert-warning { border-left-color: var(--warning); }
.alert-danger { border-left-color: var(--danger); }

label, fieldset { display: flex; flex-direction: column; gap: .35rem; font-weight: 650; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: .6rem; font-weight: 750; }
label small, .help, .muted { color: var(--muted); font-size: .84rem; font-weight: 400; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    padding: .72rem .78rem;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
input[type="color"] { min-height: 46px; padding: .3rem; }
textarea { min-height: 120px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.span-2 { grid-column: span 2; }
.checkbox-label { flex-direction: row; align-items: flex-start; gap: .65rem; font-weight: 500; }
.checkbox-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .55rem; }
.checkbox-card { flex-direction: row; align-items: center; gap: .6rem; padding: .65rem; border: 1px solid var(--border); border-radius: 9px; }

.setup-shell { background: linear-gradient(145deg, var(--background), color-mix(in srgb, var(--primary) 8%, var(--background))); }
.setup-main { width: min(960px, calc(100% - 2rem)); margin: 0 auto; padding: 3rem 0 4rem; }
.setup-intro { text-align: center; margin-bottom: 2rem; }
.setup-intro p { max-width: 670px; margin-inline: auto; color: var(--muted); }
.eyebrow { display: inline-block; margin-bottom: .8rem; color: var(--primary); font-size: .78rem; font-weight: 850; text-transform: uppercase; letter-spacing: .12em; }
.setup-form { display: grid; gap: 1.2rem; }
.section-heading { display: flex; gap: .85rem; margin-bottom: 1.3rem; }
.section-heading > span { display: grid; place-items: center; flex: 0 0 35px; height: 35px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 850; }
.section-heading p { margin: 0; color: var(--muted); }
.requirements { margin-bottom: 1.2rem; }
.requirement-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; }
.requirement-grid > div { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: .5rem; padding: .45rem 0; }
.requirement-grid strong { font-size: .8rem; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.status-dot.ok { background: var(--success); }
.theme-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.theme-picker legend { grid-column: 1 / -1; }
.theme-option { position: relative; padding: .7rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.theme-option input { position: absolute; top: .55rem; right: .55rem; }
.theme-option > span { height: 40px; border-radius: 7px; margin-bottom: .35rem; background: linear-gradient(135deg, #1261a0 60%, #22a9d6 60%); }
.theme-preview-safety > span { background: linear-gradient(135deg, #e3a600 60%, #1e252b 60%); }
.theme-preview-fresh > span { background: linear-gradient(135deg, #087f6a 60%, #49bfa5 60%); }
.theme-preview-dark > span { background: linear-gradient(135deg, #232930 60%, #e36c2f 60%); }
.setup-submit { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.setup-submit p { margin: 0; color: var(--muted); }
.center-card { max-width: 560px; margin: 3rem auto; text-align: center; }
.success-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 50%; background: var(--success); color: #fff; font-size: 2rem; font-weight: 900; }

.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; flex-direction: column; width: 250px; padding: 1rem; color: #fff; background: #142536; }
.brand { display: flex; align-items: center; gap: .75rem; min-height: 58px; padding: .5rem; color: #fff; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand img { width: 46px; height: 46px; object-fit: contain; border-radius: 7px; background: #fff; padding: 4px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--primary); font-size: 1.3rem; }
.brand small { display: block; opacity: .66; font-size: .72rem; font-weight: 500; }
.sidebar nav { display: grid; gap: .3rem; margin-top: 1.5rem; }
.sidebar nav a { color: rgba(255,255,255,.82); padding: .72rem .8rem; border-radius: 8px; font-weight: 650; }
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
.sidebar-user { margin-top: auto; display: flex; justify-content: space-between; gap: .5rem; padding: .8rem; border-top: 1px solid rgba(255,255,255,.12); font-size: .82rem; }
.sidebar-user a { color: rgba(255,255,255,.72); }
.admin-main { width: calc(100% - 250px); min-height: calc(100vh - 50px); margin-left: 250px; padding: 2rem; }
.mobile-header { display: none; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.4rem; }
.page-header p { margin: 0; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat strong { font-size: 2rem; line-height: 1; }
.stat span { color: var(--muted); }
.dashboard-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 1.2rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .8rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge { display: inline-flex; align-items: center; white-space: nowrap; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 800; background: var(--surface-alt); }
.badge-success { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface)); }
.badge-warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); }
.badge-danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.badge-info { color: var(--info); background: color-mix(in srgb, var(--info) 12%, var(--surface)); }
.badge-muted { color: var(--muted); }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); }
.stack { display: grid; gap: 1rem; }
.split-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .5fr); gap: 1.2rem; align-items: start; }
.sticky-card { position: sticky; top: 1rem; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; background: linear-gradient(145deg, var(--background), color-mix(in srgb, var(--primary) 12%, var(--background))); }
.login-card { width: min(440px, 100%); }
.login-brand { text-align: center; margin-bottom: 1.4rem; }
.login-brand img { max-width: 170px; max-height: 80px; object-fit: contain; }
.login-card form { display: grid; gap: 1rem; }

.editor-toolbar { display: flex; flex-wrap: wrap; gap: .35rem; padding: .55rem; border: 1px solid var(--border); border-bottom: 0; border-radius: 9px 9px 0 0; background: var(--surface-alt); }
.editor-toolbar button { min-width: 34px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: .32rem .5rem; }
.rich-editor { min-height: 260px; padding: 1rem; border: 1px solid var(--border); border-radius: 0 0 9px 9px; background: var(--surface); outline: none; }
.question-builder { display: grid; gap: .8rem; }
.question-card { padding: 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-alt); }
.question-card-head { display: flex; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.question-options { display: grid; gap: .5rem; margin-top: .65rem; }
.option-row { display: grid; grid-template-columns: 22px 1fr auto; gap: .45rem; align-items: center; }

.public-header { display: flex; justify-content: space-between; align-items: center; min-height: 76px; padding: .8rem max(1rem, calc((100% - 960px) / 2)); color: #fff; background: var(--primary-dark); }
.public-brand { display: flex; align-items: center; gap: .75rem; }
.public-brand img { width: 120px; height: 50px; object-fit: contain; border-radius: 6px; background: #fff; padding: 4px; }
.public-header > span { opacity: .8; font-size: .85rem; }
.public-main { width: min(900px, calc(100% - 2rem)); min-height: calc(100vh - 140px); margin: 0 auto; padding: 2rem 0 3rem; }
.toolbox-hero { margin-bottom: 1.1rem; padding: clamp(1.3rem, 5vw, 2.5rem); color: #fff; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.toolbox-hero .eyebrow { color: rgba(255,255,255,.75); }
.toolbox-hero p { max-width: 680px; margin: 0; opacity: .86; }
.content-card { font-size: 1.02rem; }
.content-card h2, .content-card h3 { margin-top: 1.4rem; }
.attachment-viewer { margin-top: 1rem; }
.attachment-viewer iframe { width: 100%; height: 680px; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
.question-block { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.question-block:last-child { border-bottom: 0; }
.question-title { margin-bottom: .7rem; font-weight: 750; }
.answer-option { flex-direction: row; align-items: flex-start; gap: .65rem; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 8px; font-weight: 500; }
.answer-options { display: grid; gap: .5rem; }
.signature-wrap { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
#signature-canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.signature-actions { display: flex; justify-content: flex-end; padding: .45rem; border-top: 1px solid var(--border); background: #f7f9fb; }
.completion-reference { display: inline-block; padding: .5rem .8rem; border-radius: 8px; background: var(--surface-alt); font-family: ui-monospace, monospace; font-weight: 800; }
.footer { min-height: 50px; display: grid; place-items: center; color: var(--muted); font-size: .76rem; }

.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.tabs a { padding: .45rem .7rem; border-radius: 8px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.tabs a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.inline-form { display: inline; }
.copy-input { position: absolute; left: -9999px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 980px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid, .split-layout { grid-template-columns: 1fr; }
    .sticky-card { position: static; }
}

@media (max-width: 760px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    body.menu-open .sidebar { transform: translateX(0); }
    .admin-main { width: 100%; margin-left: 0; padding: 1rem; }
    .mobile-header { display: flex; justify-content: space-between; align-items: center; margin: -1rem -1rem 1rem; padding: .85rem 1rem; color: #fff; background: #142536; }
    .mobile-header button { border: 1px solid rgba(255,255,255,.25); border-radius: 7px; color: #fff; background: transparent; padding: .35rem .6rem; }
    .form-grid, .requirement-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .theme-picker { grid-template-columns: repeat(2, 1fr); }
    .setup-submit, .page-header { flex-direction: column; align-items: stretch; }
    .public-header { align-items: flex-start; padding: .75rem 1rem; }
    .public-header > span { display: none; }
    .attachment-viewer iframe { height: 480px; }
}

@media (max-width: 500px) {
    .stats-grid { grid-template-columns: 1fr; }
    .theme-picker { grid-template-columns: 1fr 1fr; }
    .public-main { width: min(100% - 1rem, 900px); padding-top: .5rem; }
    .public-main .card { border-radius: 10px; }
    .toolbox-hero { margin-inline: -.5rem; border-radius: 0; }
}

@media print {
    .sidebar, .mobile-header, .footer, .button, button { display: none !important; }
    .admin-main, .public-main { width: 100%; margin: 0; padding: 0; }
    .card { box-shadow: none; break-inside: avoid; }
}

