:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-sec: #475569;
    --text-muted: #94a3b8;
    --nav-bg: #1e293b;
    --radius: 0.5rem;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ── */
.navbar { background: var(--nav-bg); color: #fff; position: sticky; top: 0; z-index: 100; }
.navbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; padding: 0 1.25rem; height: 56px; gap: 1.5rem; }
.navbar-brand { color: #fff; font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.navbar-brand:hover { text-decoration: none; color: #fff; }
.navbar-toggle { display: none; background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; font-size: 1.3rem; padding: .25rem .55rem; border-radius: 4px; cursor: pointer; }
.navbar-menu { display: flex; gap: .25rem; flex: 1; }
.navbar-menu a { color: rgba(255,255,255,.75); padding: .4rem .75rem; border-radius: 4px; font-size: .9rem; white-space: nowrap; }
.navbar-menu a:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
.navbar-menu a.active { color: #fff; background: var(--primary); }
.navbar-user { display: flex; align-items: center; gap: .75rem; font-size: .875rem; color: rgba(255,255,255,.7); white-space: nowrap; }
.logout-link { color: rgba(255,255,255,.7); }
.logout-link:hover { color: #fff; }

@media (max-width: 768px) {
    .navbar-inner { flex-wrap: wrap; height: auto; padding: .75rem 1rem; }
    .navbar-toggle { display: block; margin-left: auto; }
    .navbar-menu { display: none; flex-basis: 100%; flex-direction: column; gap: .15rem; padding: .5rem 0; }
    .navbar-menu.open { display: flex; }
    .navbar-user { display: none; }
}

/* ── Layout ── */
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--text); }

/* ── Stats Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }

@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .stats-grid { grid-template-columns: 1fr; } }

/* ── Cards ── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 1.25rem; }

.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
@media (max-width: 900px) { .chart-row { grid-template-columns: 1fr; } }
.chart-container { position: relative; height: 300px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td { padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8fafc; font-weight: 600; color: var(--text-sec); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.actions { white-space: nowrap; }
.data-table td.center, .data-table th.center { text-align: center; }
.data-table td.right, .data-table th.right { text-align: right; }

/* ── Heatmap ── */
.heatmap-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.heatmap-table th, .heatmap-table td { padding: .6rem .75rem; text-align: center; border: 1px solid var(--border); }
.heatmap-table th { background: #f8fafc; font-weight: 600; font-size: .8rem; }
.heatmap-table th.area-label { text-align: left; min-width: 160px; }
.heatmap-green { background: var(--success); color: #fff; font-weight: 600; }
.heatmap-amber { background: var(--warning); color: #fff; font-weight: 600; }
.heatmap-red { background: var(--danger); color: #fff; font-weight: 600; }
.heatmap-na { background: #f1f5f9; color: var(--text-muted); font-style: italic; font-size: .8rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-weight: 600; font-size: .875rem; margin-bottom: .3rem; color: var(--text-sec); }
.form-control { display: block; width: 100%; padding: .55rem .75rem; font-size: .925rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--text); transition: border-color .15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-row .flex-2 { flex: 2; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }
.form-inline { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.form-inline .form-group { margin-bottom: 0; }

@media (max-width: 600px) { .form-row { flex-direction: column; gap: 0; } }

/* ── Filters ── */
.filters { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; margin-bottom: 1.5rem; padding: 1rem 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters .form-group { margin-bottom: 0; min-width: 180px; }
.filters .btn { align-self: end; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: .5rem 1rem; font-size: .875rem; font-weight: 600; border: 1px solid transparent; border-radius: 4px; cursor: pointer; transition: background .15s, border-color .15s; text-decoration: none; line-height: 1.5; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--text-sec); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-lg { padding: .7rem 2rem; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn + .btn { margin-left: .25rem; }

/* ── Alerts ── */
.alert { padding: .85rem 1.1rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-size: .9rem; }
.alert-success { background: var(--success-light); color: #15803d; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-light); color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #93c5fd; }

/* ── Badges ── */
.badge { display: inline-block; padding: .15rem .55rem; font-size: .75rem; font-weight: 600; border-radius: 50px; }
.badge-success { background: var(--success-light); color: #15803d; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger { background: var(--danger-light); color: #b91c1c; }
.badge-secondary { background: #f1f5f9; color: var(--text-sec); }

/* ── Decision Support ── */
.decision-box { padding: 1rem 1.25rem; border-radius: var(--radius); border-left: 4px solid var(--primary); background: var(--primary-light); margin: 1rem 0; font-size: .9rem; line-height: 1.7; }
.decision-box em { display: block; margin-top: .5rem; font-size: .825rem; color: var(--text-muted); }

/* ── Competency Scores ── */
.score-grid { display: grid; gap: .75rem; margin: 1rem 0; }
.score-row { display: flex; align-items: center; gap: 1rem; }
.score-row .label { flex: 1; font-size: .9rem; }
.score-row .value { font-weight: 700; font-size: 1rem; min-width: 2.5rem; text-align: center; }
.score-bar { flex: 0 0 120px; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 4px; transition: width .3s; }

/* ── KPI Row ── */
.kpi-row { display: flex; align-items: end; gap: .75rem; margin-bottom: .5rem; }
.kpi-row .form-group { margin-bottom: 0; }
.kpi-row .btn-danger { align-self: center; }

/* ── Login Page ── */
.login-page { background: var(--nav-bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { background: var(--card); border-radius: var(--radius); padding: 2.5rem 2rem; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,.15); text-align: center; }
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; color: var(--text); }
.login-subtitle { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.75rem; }
.login-card .form-group { text-align: left; }
.login-card .btn { margin-top: .5rem; }
.login-card .alert { text-align: left; }

/* ── Survey Form (mobile-first) ── */
.survey-page { background: #fff; min-height: 100vh; }
.survey-container { max-width: 640px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.survey-header { text-align: center; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 2px solid var(--primary-light); }
.survey-header h1 { font-size: 1.5rem; color: var(--text); margin-bottom: .75rem; }
.anon-notice { background: var(--success-light); color: #15803d; padding: .85rem 1rem; border-radius: var(--radius); font-size: .9rem; font-weight: 500; line-height: 1.5; margin-bottom: .75rem; }
.survey-header .time-est { color: var(--text-muted); font-size: .85rem; }

.survey-section { margin-bottom: 2rem; }
.survey-section-title { font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); margin-bottom: 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.survey-question { margin-bottom: 1.25rem; }
.survey-question p { font-size: .95rem; margin-bottom: .6rem; line-height: 1.5; color: var(--text); }

.rating-group { display: flex; gap: .5rem; }
.rating-group input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.rating-group label { display: flex; align-items: center; justify-content: center; min-width: 48px; height: 48px; border: 2px solid var(--border); border-radius: var(--radius); font-size: 1rem; font-weight: 600; cursor: pointer; transition: all .15s; background: #fff; color: var(--text-sec); flex: 1; max-width: 70px; }
.rating-group label:hover { border-color: var(--primary); color: var(--primary); }
.rating-group input[type="radio"]:checked + label { background: var(--primary); color: #fff; border-color: var(--primary); }

.rating-legend { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); margin-top: .3rem; padding: 0 .15rem; }

.residence-options { display: flex; flex-direction: column; gap: .5rem; }
.residence-options label { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 1rem; transition: all .15s; }
.residence-options label:hover { border-color: var(--primary); }
.residence-options input[type="radio"]:checked + span { font-weight: 600; }
.residence-options input[type="radio"] { width: 20px; height: 20px; accent-color: var(--primary); }

.enps-question { margin-bottom: 1.5rem; }
.enps-question > p { font-size: .95rem; margin-bottom: .75rem; line-height: 1.5; }
.enps-group { display: flex; gap: .35rem; flex-wrap: wrap; }
.enps-group input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.enps-group label { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 2px solid var(--border); border-radius: 50%; font-size: .95rem; font-weight: 600; cursor: pointer; transition: all .15s; background: #fff; color: var(--text-sec); }
.enps-group label:hover { border-color: var(--primary); color: var(--primary); }
.enps-group input[type="radio"]:checked + label { background: var(--primary); color: #fff; border-color: var(--primary); }
.enps-legend { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); margin-top: .4rem; }

.comment-section textarea { width: 100%; padding: .85rem; font-size: .95rem; border: 1px solid var(--border); border-radius: var(--radius); resize: vertical; min-height: 100px; font-family: inherit; }
.comment-section textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.comment-warning { font-size: .85rem; color: var(--warning); margin-bottom: .5rem; }

.submit-section { text-align: center; margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.submit-section .btn { padding: .85rem 3rem; font-size: 1.1rem; }

.thank-you { text-align: center; padding: 4rem 1rem; }
.thank-you h1 { font-size: 1.75rem; color: var(--success); margin-bottom: 1rem; }
.thank-you p { font-size: 1rem; color: var(--text-sec); max-width: 400px; margin: 0 auto; }

.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 1.5rem; color: var(--danger); margin-bottom: .75rem; }
.error-page p { color: var(--text-sec); }

/* ── Token List ── */
.token-list { font-family: "Courier New", monospace; font-size: .85rem; background: #f8fafc; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); max-height: 400px; overflow-y: auto; line-height: 1.8; word-break: break-all; }
.token-used { color: var(--text-muted); text-decoration: line-through; }

/* ── Utilities ── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.d-flex { display: flex; }
.gap-1 { gap: .5rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ── Comparison side-by-side ── */
.block-header td { background: var(--primary-light); font-weight: 700; color: var(--primary-dark); font-size: .85rem; padding: .5rem .85rem; }
.block-avg td { background: #f8fafc; }
.diff-zero { color: var(--success); font-weight: 600; }
.diff-small { color: var(--warning); font-weight: 600; }
.diff-large { color: var(--danger); font-weight: 700; }

.token-display input[type="text"] { font-family: "Courier New", monospace; font-size: .85rem; background: #f8fafc; }

.attendance-note { font-size: .8rem; color: var(--text-muted); margin-top: .5rem; }

/* ── Print ── */
@media print {
    .navbar, .filters, .btn, .form-actions { display: none; }
    .container { max-width: 100%; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
