:root {
    --ui-primary: #2563eb;
    --ui-primary-dark: #1d4ed8;
    --ui-primary-soft: #eff6ff;
    --ui-ink: #1f2937;
    --ui-muted: #6b7280;
    --ui-border: #e5e7eb;
    --ui-surface: #fff;
    --ui-bg: #f3f6fb;
    --ui-danger: #dc2626;
    --ui-success: #059669;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ui-ink); background: var(--ui-bg); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
body, button, input, textarea, select { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body.modal-open { overflow: hidden; }
button { cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease, border-color .16s ease, opacity .16s ease; }
button:not(:disabled):active { transform: scale(.97); }
button:disabled { cursor: not-allowed; opacity: .55; }
.hidden { display: none !important; }

/* OneUI shell */
#page-container.questionnaire-admin { min-width: 1180px; background: var(--ui-bg); }
#page-container.questionnaire-admin #sidebar { width: 248px; background: #111827; box-shadow: 8px 0 24px rgba(15,23,42,.08); }
#page-container.questionnaire-admin #page-header { background: rgba(255,255,255,.94); border-bottom: 1px solid var(--ui-border); box-shadow: 0 2px 10px rgba(15,23,42,.04); }
#page-container.questionnaire-admin #main-container { min-height: calc(100vh - 70px); }
.sidebar-brand-wrap { height: 70px; padding: 0 22px !important; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand { display: inline-flex; align-items: center; gap: 11px; color: #fff; font-size: 19px; font-weight: 700; text-decoration: none; letter-spacing: .02em; }
.brand-mark, .login-brand-mark { display: inline-grid; width: 36px; height: 36px; place-items: center; color: #fff; background: linear-gradient(135deg,#3b82f6,#7c3aed); border-radius: 10px; box-shadow: 0 7px 16px rgba(37,99,235,.28); }
.content-side { padding: 22px 14px 80px; }
.sidebar-heading { padding: 0 12px 12px; color: #94a3b8; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.nav-main { margin: 0; padding: 0; list-style: none; }
.nav-main-item { margin: 3px 0; }
.nav-main-link { display: flex; align-items: center; min-height: 44px; padding: 0 13px; color: #cbd5e1; border-radius: 9px; transition: color .18s ease, background-color .18s ease, transform .18s ease; }
.nav-main-link:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(3px); }
.nav-main-link.active { color: #fff; background: linear-gradient(90deg,rgba(37,99,235,.95),rgba(79,70,229,.8)); box-shadow: 0 8px 18px rgba(37,99,235,.18); }
.nav-main-link-icon { width: 24px; margin-right: 10px; color: #93c5fd; font-size: 15px; text-align: center; }
.nav-main-link.active .nav-main-link-icon { color: #fff; }
.nav-main-link-name { font-size: 14px; }
.sidebar-footer { position: absolute; right: 0; bottom: 0; left: 0; display: flex; align-items: center; gap: 8px; height: 54px; padding: 0 26px; color: #94a3b8; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.status-dot { width: 7px; height: 7px; background: #34d399; border-radius: 50%; box-shadow: 0 0 0 4px rgba(52,211,153,.13); }
#page-container.questionnaire-admin #page-header .content-header { min-height: 70px; padding-right: 34px; padding-left: 34px; }
.header-title-wrap, .header-user { display: flex; align-items: center; }
.header-title-wrap { gap: 10px; }
.header-title-wrap h1 { margin: 0; font-size: 19px; font-weight: 700; }
.header-title-icon { display: inline-grid; width: 28px; height: 28px; place-items: center; color: var(--ui-primary); background: var(--ui-primary-soft); border-radius: 8px; }
.header-user { gap: 10px; }
.user-avatar { display: inline-grid; width: 31px; height: 31px; place-items: center; color: #fff; background: #64748b; border-radius: 50%; }
.admin-name { color: #374151; font-weight: 600; }
.header-logout { margin-left: 14px; padding: 7px 10px; color: #64748b; background: transparent; border: 0; border-radius: 7px; }
.header-logout:hover { color: var(--ui-primary); background: var(--ui-primary-soft); }
.admin-content { padding: 30px 34px 46px; animation: page-enter .28s ease both; }

/* Common controls and blocks */
.block.page-block, .card { overflow: hidden; background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 12px; box-shadow: 0 8px 24px rgba(15,23,42,.045); animation: page-enter .28s ease both; }
.block-header.block-header-default { display: flex; align-items: center; justify-content: space-between; min-height: 82px; padding: 18px 24px; background: #fff; border-bottom: 1px solid var(--ui-border); }
.block-title { margin: 0; color: #111827; font-size: 17px; font-weight: 700; }
.block-subtitle { margin: 5px 0 0; color: var(--ui-muted); font-size: 12px; font-weight: 400; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 17px 22px; background: #fbfcfe; border-bottom: 1px solid var(--ui-border); }
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.toolbar .filters > * { flex-shrink: 0; }
.toolbar .search-control { width: 300px; }
.toolbar .filters > input { width: 200px; margin-top: 0; }
.toolbar .filters > select { width: 215px; margin-top: 0; }
.toolbar .filters > .secondary { min-width: 72px; white-space: nowrap; }
.search-control { position: relative; }
.search-control > i { position: absolute; top: 50%; left: 12px; color: #94a3b8; transform: translateY(-50%); pointer-events: none; }
.search-control input { margin-top: 0; padding-left: 34px !important; }
input, textarea, select { width: 100%; margin-top: 8px; padding: 10px 12px; color: var(--ui-ink); background: #fff; border: 1px solid #d8dee9; border-radius: 7px; outline: 0; transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease; }
input:focus, textarea:focus, select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { min-height: 96px; resize: vertical; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; appearance: none; }
label { display: block; margin-bottom: 16px; font-weight: 600; }
.primary, .secondary, .danger { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 8px 16px; border-radius: 7px; font-weight: 600; }
.primary { color: #fff; background: var(--ui-primary); border: 1px solid var(--ui-primary); box-shadow: 0 5px 12px rgba(37,99,235,.18); }
.primary:hover { color: #fff; background: var(--ui-primary-dark); border-color: var(--ui-primary-dark); box-shadow: 0 7px 17px rgba(37,99,235,.26); }
.secondary { color: #374151; background: #fff; border: 1px solid #d8dee9; }
.secondary:hover { color: var(--ui-primary); border-color: #93c5fd; background: #f8fbff; }
.danger { color: #fff; background: var(--ui-danger); border: 1px solid var(--ui-danger); }
.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.full { width: 100%; }
.link-button { padding: 3px 6px; color: var(--ui-primary); background: transparent; border: 0; }
.link-button:hover { color: var(--ui-primary-dark); text-decoration: underline; }
.danger-link { color: var(--ui-danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 17px; text-align: left; border-bottom: 1px solid #edf0f5; vertical-align: top; }
th { color: #64748b; background: #f8fafc; font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr { transition: background-color .16s ease, transform .16s ease; animation: row-enter .24s ease both; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 62px 20px; color: #94a3b8; text-align: center; }
.tag { display: inline-block; margin: 2px 5px 2px 0; padding: 4px 9px; color: #1d4ed8; background: #eff6ff; border-radius: 20px; }
.status-on { color: var(--ui-success); }
.status-off { color: #94a3b8; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 15px 20px; color: #64748b; border-top: 1px solid var(--ui-border); }
.pagination button, .picker-pages button { min-height: 32px; padding: 5px 11px; color: #475569; background: #fff; border: 1px solid #d8dee9; border-radius: 6px; }
.pagination button:hover:not(:disabled), .picker-pages button:hover:not(:disabled) { color: var(--ui-primary); border-color: #93c5fd; }

/* Intro and fixed type cards */
.type-grid { display: grid; grid-template-columns: repeat(4, minmax(190px,1fr)); gap: 18px; }
.type-card { position: relative; padding: 24px; background: #fff; border: 1px solid var(--ui-border); border-radius: 12px; box-shadow: 0 8px 20px rgba(15,23,42,.04); animation: page-enter .28s ease both; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.type-card:hover { border-color: #bfdbfe; transform: translateY(-4px); box-shadow: 0 14px 28px rgba(37,99,235,.12); }
.type-card h3 { margin: 0 0 8px; color: #111827; font-size: 16px; }
.type-card p { margin: 0; color: #64748b; line-height: 1.7; }

/* Login */
.login-layout { min-height: 100vh; background: radial-gradient(circle at 15% 10%,#dbeafe 0,#f8fafc 40%,#eef2ff 100%); }
.login-layout #main-container { min-height: 100vh; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 28px; }
.login-card-wrap { width: 430px; max-width: 100%; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 13px; margin-bottom: 22px; }
.login-brand-mark { width: 45px; height: 45px; font-size: 20px; border-radius: 13px; }
.login-brand h1 { margin: 0; color: #111827; font-size: 23px; }
.login-brand p { margin: 4px 0 0; color: #64748b; }
.login-card { padding: 30px 32px 26px; background: rgba(255,255,255,.96); border: 1px solid rgba(226,232,240,.92); border-radius: 14px; box-shadow: 0 22px 55px rgba(30,64,175,.13); }
.login-heading { margin-bottom: 23px; }
.login-heading h2 { margin: 0; font-size: 18px; }
.login-heading p { margin: 6px 0 0; color: #94a3b8; }
.field-label { margin: 0 0 7px; color: #475569; font-size: 13px; font-weight: 600; }
.input-icon-wrap { position: relative; margin-bottom: 17px; }
.input-icon-wrap > i { position: absolute; top: 50%; left: 13px; color: #94a3b8; transform: translateY(-50%); }
.input-icon-wrap input { margin: 0; padding-left: 38px; }
.login-submit { margin-top: 5px; min-height: 44px; font-size: 15px; }
.form-error { min-height: 22px; margin: 12px 0 0; color: var(--ui-danger); text-align: center; }
.login-footer { margin-top: 17px; color: #94a3b8; font-size: 12px; text-align: center; }

/* Forms, dialogs and questionnaire editor */
.form-row { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 17px; }
.form-row.three-columns { grid-template-columns: repeat(3,minmax(0,1fr)); }
.form-row.four-columns { grid-template-columns: repeat(4,minmax(0,1fr)); }
.section-title { display: flex; align-items: center; gap: 9px; padding: 17px 24px; color: #111827; font-size: 15px; font-weight: 700; border-bottom: 1px solid var(--ui-border); }
.section-icon { display: inline-grid; width: 28px; height: 28px; place-items: center; color: #2563eb; background: #eff6ff; border-radius: 8px; }
.form-section { padding: 22px 24px; border-bottom: 1px solid var(--ui-border); }
.config-form { width: 100%; max-width: none; }
.config-actions { display: flex; justify-content: flex-end; padding: 18px 24px; }
.check-row { display: flex; align-items: center; gap: 18px; margin: 0 0 18px; }
.check-row label { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 400; }
.check-row input, .question-picker input, .picker-question input { width: auto; margin: 2px 0 0; }
.modal { position: fixed; z-index: 2000; inset: 0; display: grid; place-items: center; padding: 25px; }
.modal-secondary { z-index: 2100; }
.modal-mask { position: absolute; inset: 0; background: rgba(15,23,42,.62); animation: mask-in .2s ease both; }
.modal-panel { position: relative; z-index: 1; display: flex; width: min(780px,calc(100vw - 50px)); max-height: calc(100vh - 50px); flex-direction: column; background: #fff; border: 1px solid rgba(226,232,240,.8); border-radius: 13px; box-shadow: 0 24px 75px rgba(15,23,42,.3); }
.modal:not(.hidden) .modal-panel { animation: modal-in .22s ease both; }
.modal.closing .modal-mask { animation: mask-out .18s ease both; }
.modal.closing .modal-panel { animation: modal-out .18s ease both; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 17px 22px; border-bottom: 1px solid var(--ui-border); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close { padding: 5px 7px; color: #94a3b8; background: transparent; border: 0; border-radius: 6px; font-size: 16px; }
.modal-close:hover { color: var(--ui-danger); background: #fef2f2; }
.modal-body { padding: 22px; overflow-y: auto; }
.form-actions, .questionnaire-editor-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.confirm-text { margin: 3px 0 21px; color: #475569; line-height: 1.8; }
.question-picker { max-height: 260px; overflow: auto; border: 1px solid var(--ui-border); border-radius: 8px; }
.question-picker label { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 10px 12px; border-bottom: 1px solid var(--ui-border); font-weight: 400; }
.question-picker label:last-child { border-bottom: 0; }
.upload-row { display: flex; align-items: flex-end; gap: 8px; }
.upload-row input { flex: 1; }
.detail-head { padding: 15px; margin-bottom: 14px; color: #475569; background: #f8fafc; border-radius: 8px; line-height: 1.8; }
.answer-card { padding: 15px; margin-bottom: 11px; background: #fff; border: 1px solid var(--ui-border); border-radius: 8px; }
.answer-card h4 { margin: 0 0 8px; color: #111827; }
.answer-card p { margin: 0; color: #475569; white-space: pre-wrap; }
.sort-actions { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.sort-actions .link-button { min-width: 30px; }
.questionnaire-editor-modal { width: min(1220px,calc(100vw - 50px)); }
.questionnaire-editor-modal .modal-body, .question-picker-modal .modal-body { padding: 0; }
.questionnaire-editor-form { display: flex; min-height: 610px; max-height: calc(100vh - 115px); flex-direction: column; }
.questionnaire-editor-grid { display: grid; min-height: 0; flex: 1; grid-template-columns: minmax(390px,.9fr) minmax(500px,1.1fr); }
.questionnaire-basic { padding: 23px; overflow-y: auto; border-right: 1px solid var(--ui-border); }
.questionnaire-selected { display: flex; min-width: 0; flex-direction: column; background: #f8fafc; }
.selected-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 18px 21px; background: #fff; border-bottom: 1px solid var(--ui-border); }
.selected-header h3 { margin: 0 0 4px; font-size: 16px; }
.selected-header p { margin: 0; color: #94a3b8; font-size: 12px; }
.selected-question-list { min-height: 240px; padding: 15px; overflow-y: auto; }
.selected-question-item { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; margin-bottom: 9px; padding: 12px; background: #fff; border: 1px solid var(--ui-border); border-radius: 8px; box-shadow: 0 3px 9px rgba(15,23,42,.03); animation: row-enter .22s ease both; }
.selected-question-item.dragging { opacity: .45; }
.drag-handle { color: #94a3b8; cursor: grab; font-size: 18px; text-align: center; }
.selected-question-main { min-width: 0; }
.selected-question-main strong { display: block; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-question-meta { display: flex; gap: 8px; color: #94a3b8; font-size: 12px; }
.remove-question { color: var(--ui-danger); background: transparent; border: 0; }
.selected-empty { display: grid; min-height: 300px; place-items: center; color: #94a3b8; text-align: center; border: 1px dashed #cbd5e1; border-radius: 9px; background: #fff; }
.questionnaire-editor-actions { padding: 14px 20px; background: #fff; border-top: 1px solid var(--ui-border); }
.question-picker-modal { width: min(1020px,calc(100vw - 50px)); }
.picker-layout { display: flex; min-height: 570px; max-height: calc(100vh - 115px); flex-direction: column; }
.picker-toolbar { display: grid; grid-template-columns: 1fr 190px auto; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--ui-border); }
.picker-toolbar input, .picker-toolbar select { margin: 0; }
.picker-summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; color: #64748b; background: #f8fafc; border-bottom: 1px solid var(--ui-border); }
.picker-result { min-height: 0; flex: 1; padding: 12px 18px; overflow-y: auto; }
.picker-question { display: grid; grid-template-columns: 24px 1fr; gap: 9px; align-items: flex-start; margin: 0 0 8px; padding: 12px; background: #fff; border: 1px solid var(--ui-border); border-radius: 8px; font-weight: 400; transition: border-color .16s ease, background-color .16s ease, transform .16s ease; }
.picker-question:hover, .picker-question.checked { border-color: #93c5fd; background: #eff6ff; }
.picker-question strong { display: block; margin-bottom: 5px; }
.picker-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-top: 1px solid var(--ui-border); }
.picker-pages, .picker-actions { display: flex; align-items: center; gap: 8px; }
.toast { position: fixed; z-index: 2200; left: 50%; bottom: 34px; padding: 11px 18px; color: #fff; background: rgba(17,24,39,.94); border-radius: 8px; box-shadow: 0 12px 28px rgba(15,23,42,.18); opacity: 0; transform: translate(-50%,12px); transition: opacity .18s ease, transform .18s ease; }
.toast.toast-show { opacity: 1; transform: translate(-50%,0); }

@keyframes page-enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes row-enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes mask-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes mask-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes modal-out { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(8px) scale(.99); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
