:root {
    --navy: #16324f;
    --navy-dark: #10253a;
    --navy-soft: #eaf0f6;
    --teal: #0f8b8d;
    --teal-dark: #0b6f71;
    --gold: #e6a23c;
    --red: #d94b4b;
    --green: #208a5b;
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --line: #dde5ec;
    --text: #1f2d3d;
    --muted: #6b7b8d;
    --shadow: 0 14px 35px rgba(22, 50, 79, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 265px;
    display: flex;
    flex-direction: column;
    color: #fff;
    background: linear-gradient(180deg, var(--navy-dark), var(--navy));
    box-shadow: 10px 0 35px rgba(16, 37, 58, .12);
}
.brand { display: flex; gap: 12px; align-items: center; min-height: 88px; padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-mark { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; font-weight: 800; color: var(--navy-dark); background: #fff; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.68); font-size: 11px; }
.nav-list { flex: 1; padding: 18px 12px; }
.nav-link { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; padding: 11px 13px; border-radius: 11px; color: rgba(255,255,255,.76); font-weight: 650; transition: .2s ease; }
.nav-link span { width: 22px; text-align: center; font-size: 18px; }
.nav-link:hover, .nav-link.active { color: #fff; background: rgba(255,255,255,.12); transform: translateX(2px); }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.1); }
.user-mini { display: flex; gap: 10px; align-items: center; }
.user-mini strong, .user-mini small { display: block; }
.user-mini strong { font-size: 13px; }
.user-mini small { color: rgba(255,255,255,.65); font-size: 11px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--navy); background: #fff; font-weight: 800; }
.logout-link { display: block; margin-top: 12px; padding: 9px 11px; border-radius: 9px; text-align: center; color: #fff; background: rgba(255,255,255,.1); }
.logout-link:hover { background: rgba(255,255,255,.17); }
.main-area { min-width: 0; flex: 1; margin-left: 265px; }
.topbar { min-height: 88px; display: flex; align-items: center; gap: 14px; padding: 16px 30px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.menu-toggle { display: none; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--navy); }
.content { max-width: 1500px; margin: 0 auto; padding: 28px 30px 50px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head h2 { margin: 0; font-size: 23px; }
.page-head p { margin: 5px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.card-header h3 { margin: 0; font-size: 16px; }
.card-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.card-body { padding: 20px; }
.card + .card { margin-top: 18px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { position: relative; overflow: hidden; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
.stat-card::after { content: ""; position: absolute; width: 90px; height: 90px; right: -32px; top: -34px; border-radius: 50%; background: var(--navy-soft); }
.stat-card .label { color: var(--muted); font-size: 12px; font-weight: 650; }
.stat-card .value { margin-top: 5px; font-size: 27px; font-weight: 800; color: var(--navy); }
.stat-card .meta { margin-top: 6px; color: var(--muted); font-size: 11px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, .8fr); gap: 18px; }
.grid-equal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 14px; border: 1px solid transparent; border-radius: 10px; font-weight: 700; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--navy); }
.btn-primary:hover { background: var(--navy-dark); }
.btn-accent { color: #fff; background: var(--teal); }
.btn-accent:hover { background: var(--teal-dark); }
.btn-light { color: var(--navy); background: #fff; border-color: var(--line); }
.btn-light:hover { background: var(--surface-2); }
.btn-danger { color: #fff; background: var(--red); }
.btn-warning { color: #fff; background: var(--gold); }
.btn-sm { min-height: 34px; padding: 7px 10px; border-radius: 8px; font-size: 12px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #536579; background: var(--surface-2); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr:hover { background: #fbfcfd; }
tbody tr:last-child td { border-bottom: 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.badge-success { color: #176a47; background: #e5f6ee; }
.badge-warning { color: #8b5a08; background: #fff2d7; }
.badge-info { color: #275b82; background: #e9f2f9; }
.badge-danger { color: #983838; background: #fdeaea; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
label { display: block; margin-bottom: 6px; color: #3c4d60; font-size: 12px; font-weight: 750; }
.input, input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea { width: 100%; min-height: 42px; padding: 10px 12px; color: var(--text); background: #fff; border: 1px solid #ccd7e1; border-radius: 9px; outline: none; transition: .15s ease; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,139,141,.12); }
.help { margin-top: 5px; color: var(--muted); font-size: 11px; }
.required { color: var(--red); }

.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 10px; border: 1px solid; font-weight: 650; }
.alert-success { color: #176a47; background: #edf9f3; border-color: #bce6d2; }
.alert-danger { color: #8f3434; background: #fff0f0; border-color: #f1c1c1; }
.alert-info { color: #275b82; background: #edf6fc; border-color: #c9deed; }

.empty-state { padding: 42px 22px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--text); font-size: 16px; }

.project-row-title { font-weight: 800; color: var(--navy); }
.project-row-title small { display: block; margin-top: 2px; color: var(--muted); font-weight: 500; }
.quick-list { list-style: none; margin: 0; padding: 0; }
.quick-list li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.quick-list li:last-child { border-bottom: 0; }

.dynamic-list { display: grid; gap: 12px; }
.dynamic-item { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.dynamic-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.sub-list { margin-top: 12px; padding-left: 16px; border-left: 3px solid var(--navy-soft); }
.sub-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-top: 9px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tab { padding: 9px 13px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #fff; font-weight: 700; }
.tab.active { color: #fff; background: var(--navy); border-color: var(--navy); }
.matrix-card { margin-bottom: 18px; overflow: hidden; }
.matrix-card h4 { margin: 0; }
.matrix-scroll { overflow: auto; max-height: 520px; }
.matrix-table { min-width: 650px; }
.matrix-table th:first-child, .matrix-table td:first-child { position: sticky; left: 0; z-index: 2; background: #fff; min-width: 190px; }
.matrix-table thead th:first-child { z-index: 3; background: var(--surface-2); }
.matrix-table select { min-width: 118px; }
.consistency-box { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-top: 12px; }
.progress { width: 100%; height: 9px; overflow: hidden; border-radius: 999px; background: #edf1f4; }
.progress > span { display: block; height: 100%; background: var(--teal); border-radius: inherit; }
.rank-number { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: #fff; background: var(--navy); font-weight: 800; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; background: #fff; }
.login-visual { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 54px; color: #fff; background: linear-gradient(145deg, var(--navy-dark), var(--navy) 58%, var(--teal-dark)); }
.login-visual::before, .login-visual::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255,255,255,.08); }
.login-visual::before { width: 420px; height: 420px; right: -140px; top: -140px; }
.login-visual::after { width: 280px; height: 280px; left: -100px; bottom: -90px; }
.login-brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; }
.login-brand .brand-mark { background: #fff; }
.login-copy { position: relative; z-index: 1; max-width: 560px; }
.login-copy h1 { margin: 0 0 14px; font-size: clamp(34px, 5vw, 62px); line-height: 1.05; }
.login-copy p { max-width: 500px; margin: 0; color: rgba(255,255,255,.76); font-size: 16px; }
.login-note { position: relative; z-index: 1; color: rgba(255,255,255,.62); font-size: 12px; }
.login-panel { display: grid; place-items: center; padding: 40px; background: var(--bg); }
.login-card { width: min(430px, 100%); padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 25px 55px rgba(22,50,79,.12); }
.login-card h2 { margin: 0; font-size: 25px; }
.login-card > p { margin: 7px 0 24px; color: var(--muted); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; }

.public-shell { min-height: 100vh; background: var(--bg); }
.public-header { padding: 22px 30px; color: #fff; background: var(--navy); }
.public-header-inner { max-width: 1250px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.public-main { max-width: 1250px; margin: auto; padding: 28px 24px 50px; }
.public-title { margin: 0; font-size: 20px; }
.public-subtitle { margin: 3px 0 0; color: rgba(255,255,255,.7); font-size: 12px; }

.print-only { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2, .grid-equal { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(-102%); transition: transform .22s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(11,27,43,.48); }
    .sidebar-backdrop.show { display: block; }
    .main-area { margin-left: 0; }
    .menu-toggle { display: inline-grid; place-items: center; }
    .content { padding: 22px 18px 40px; }
    .topbar { padding: 14px 18px; min-height: 76px; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .login-page { grid-template-columns: 1fr; }
    .login-visual { min-height: 290px; padding: 34px 28px; }
    .login-copy h1 { font-size: 38px; }
    .login-panel { padding: 28px 18px; }
}

@media (max-width: 600px) {
    .stats-grid, .form-grid { grid-template-columns: 1fr; }
    .card-header { align-items: flex-start; flex-direction: column; }
    .card-body { padding: 16px; }
    .actions { width: 100%; }
    .actions .btn { flex: 1; }
    .dynamic-row { grid-template-columns: 1fr; }
    .sub-item { grid-template-columns: 1fr; }
    .public-header-inner { align-items: flex-start; flex-direction: column; }
}

@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
    .main-area { margin-left: 0; }
    .content { max-width: none; padding: 0; }
    .card { box-shadow: none; border-color: #bbb; }
    .print-only { display: block; }
    .page-break { break-before: page; }
}

/* Source selection and reporting */
.source-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.source-option { position: relative; display: block; cursor: pointer; }
.source-option input { position: absolute; opacity: 0; pointer-events: none; }
.source-option-content { display: flex; min-height: 112px; flex-direction: column; justify-content: center; gap: 7px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; transition: .2s ease; }
.source-option-content strong { color: var(--navy); font-size: 16px; }
.source-option-content small { color: var(--muted); line-height: 1.55; }
.source-option:hover .source-option-content { border-color: #a9bac9; transform: translateY(-1px); }
.source-option input:checked + .source-option-content { border-color: var(--teal); background: #eefaf8; box-shadow: 0 0 0 3px rgba(20, 140, 128, .10); }
.source-option input:focus-visible + .source-option-content { outline: 3px solid rgba(22, 50, 79, .18); outline-offset: 2px; }
.respondent-identity { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.respondent-identity span, .respondent-identity small { color: rgba(255,255,255,.7); font-size: 12px; }
.questionnaire-intro { margin-bottom: 20px; }
.instruction-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.instruction-grid > div { display: flex; flex-direction: column; gap: 5px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.instruction-grid strong { color: var(--navy); }
.instruction-grid span { color: var(--muted); font-size: 12px; line-height: 1.45; }
.questionnaire-submit-bar { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.94); box-shadow: 0 12px 30px rgba(22,50,79,.12); backdrop-filter: blur(8px); }
.respondent-grid { grid-template-columns: minmax(0, 1.55fr) minmax(310px, .65fr); }
.ranking-row { display: grid; grid-template-columns: 42px minmax(0,1fr) 80px; gap: 12px; align-items: center; margin-bottom: 16px; }
.report-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.report-summary-grid > div { display: flex; flex-direction: column; gap: 6px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.report-summary-grid span { color: var(--muted); font-size: 12px; }
.report-summary-grid strong { color: var(--navy); }
.report-print-header { margin-bottom: 22px; padding-bottom: 16px; border-bottom: 2px solid #222; }
.report-print-header h1 { margin: 0 0 5px; font-size: 24px; }
.report-print-header p { margin: 0; }
.print-meta { display: flex; justify-content: space-between; gap: 20px; margin-top: 12px; font-size: 12px; }

@media (max-width: 900px) {
    .source-options, .instruction-grid, .report-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .respondent-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .source-options, .instruction-grid, .report-summary-grid { grid-template-columns: 1fr; }
    .respondent-identity { align-items: flex-start; text-align: left; }
    .questionnaire-submit-bar .btn { flex: 0 0 100%; }
    .ranking-row { grid-template-columns: 34px minmax(0,1fr) 64px; gap: 8px; }
}

@media print {
    .report-summary-card { break-inside: avoid; }
    .ranking-row { break-inside: avoid; }
    .table-wrap { overflow: visible; }
    table { font-size: 10px; }
    .progress { border: 1px solid #777; }
    .progress > span { background: #555 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
.final-result-row td { background: #eef6f5; border-top: 2px solid var(--teal); }
