:root {
    --ink: #173b3a;
    --muted: #647c79;
    --teal-900: #0e4744;
    --teal-700: #126b65;
    --teal-500: #2a8f86;
    --teal-100: #dff1ed;
    --cream: #f4f2eb;
    --paper: #fffefb;
    --line: #dbe5e2;
    --warning: #a55a12;
    --warning-bg: #fff3df;
    --danger: #a63f3f;
    --shadow: 0 18px 45px rgba(23, 59, 58, .09);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    background: var(--cream);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
}
a { color: var(--teal-700); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.9rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -.04em; }
h2 { margin-bottom: .35rem; font-size: 1.15rem; }
small { color: var(--muted); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: .72rem 1.05rem;
    border: 1px solid var(--teal-700);
    border-radius: 10px;
    background: var(--teal-700);
    color: white;
    font-weight: 750;
    text-decoration: none;
    transition: .18s ease;
}
.button:hover { transform: translateY(-1px); background: var(--teal-900); }
.button.secondary { background: white; color: var(--teal-900); }
.button.ghost { background: transparent; color: var(--teal-900); border-color: var(--line); }

label { display: grid; gap: .42rem; font-size: .9rem; font-weight: 700; }
label span { color: var(--muted); font-weight: 500; }
input, select, textarea {
    width: 100%;
    border: 1px solid #c8d7d3;
    border-radius: 10px;
    background: white;
    color: var(--ink);
    padding: .72rem .8rem;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(42, 143, 134, .15); }
textarea { resize: vertical; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1rem;
    background: var(--teal-900);
    color: white;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .45rem; color: white; text-decoration: none; }
.brand-mark, .hero-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: #d6a64d;
    color: #173b3a;
    font-weight: 900;
    letter-spacing: -.04em;
}
.brand small { display: block; color: #a7cfca; }
.brand strong { display: block; font-size: 1.08rem; }
.sidebar nav { display: grid; gap: .3rem; margin-top: 2rem; }
.sidebar nav a { padding: .72rem .8rem; border-radius: 9px; color: #cfe2df; text-decoration: none; font-weight: 650; }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,.11); color: white; }
.sidebar-foot { margin-top: auto; display: grid; gap: .2rem; padding: .8rem; border-top: 1px solid rgba(255,255,255,.15); font-size: .82rem; }
.sidebar-foot span { color: #a7cfca; }
.sidebar-foot a { color: white; }
.page { min-width: 0; }
.page-content { max-width: 1450px; margin: auto; padding: 2.4rem clamp(1rem, 3vw, 3rem) 4rem; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.page-header small { display: block; margin-bottom: .45rem; color: var(--teal-700); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.page-header h1 { margin-bottom: .35rem; }
.page-header p { margin-bottom: 0; color: var(--muted); }

.filter-bar {
    display: grid;
    grid-template-columns: 150px 150px minmax(210px, 1fr) auto;
    align-items: end;
    gap: .8rem;
    margin-bottom: 1.2rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--paper);
}
.filter-bar label { gap: .25rem; }
.filter-bar label > span { color: var(--muted); font-size: .74rem; font-weight: 800; text-transform: uppercase; }

.metric-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.metric, .card, .panel, .report-summary, .success-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
}
.metric { display: grid; gap: .2rem; min-height: 150px; padding: 1.15rem; }
.metric span { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.metric strong { align-self: center; font-size: 2rem; line-height: 1.1; }
.metric small { align-self: end; }
.alert { margin: 1rem 0; padding: .9rem 1rem; border-radius: 12px; }
.alert.warning { border: 1px solid #efcf9d; background: var(--warning-bg); color: #78400a; }
.alert.error { border: 1px solid #e5b7b7; background: #fff0f0; color: var(--danger); }
.alert.success { border: 1px solid #acd7cf; background: var(--teal-100); color: var(--teal-900); }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.dashboard-grid.wide-left { grid-template-columns: 1.35fr .65fr; }
.card { min-width: 0; overflow: hidden; margin-bottom: 1rem; }
.card > header { padding: 1rem 1.15rem; border-bottom: 1px solid var(--line); }
.card > header h2, .card > header p { margin-bottom: 0; }
.card > header p { color: var(--muted); font-size: .88rem; }
.card > header.split { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-body { padding: 1.15rem; }

.score-list { display: grid; gap: 1rem; }
.score-label { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .32rem; }
.score-track { height: 9px; overflow: hidden; border-radius: 20px; background: #e8efed; }
.score-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal-500), #d6a64d); }
.distribution { display: grid; gap: .9rem; }
.distribution > div { display: grid; grid-template-columns: 70px 1fr 28px; align-items: center; gap: .5rem; font-size: .82rem; }
.distribution > div > div { height: 18px; overflow: hidden; border-radius: 5px; background: #e8efed; }
.distribution i { display: block; height: 100%; background: var(--teal-500); }
.distribution strong { text-align: right; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .75rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 2rem; }
.issue-list { display: grid; gap: .6rem; }
.issue-list > div { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem .75rem; border-radius: 9px; background: #f2f6f4; }
.issue-list b { white-space: nowrap; color: var(--teal-700); font-size: .8rem; }
.feedback-list { display: grid; gap: .75rem; }
.feedback { display: flex; justify-content: space-between; gap: 1rem; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; }
.feedback p { margin-bottom: .45rem; }
.feedback small { display: block; margin-top: .45rem; }
.low-feedback { margin-top: .35rem; padding: .5rem .65rem; border-left: 3px solid #d6a64d; background: var(--warning-bg); font-size: .86rem; }
.pill { display: inline-block; height: fit-content; padding: .25rem .52rem; border-radius: 999px; background: var(--teal-100); color: var(--teal-900); font-size: .74rem; white-space: nowrap; }

.report-summary { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 1rem; overflow: hidden; }
.report-summary div { display: grid; gap: .2rem; padding: 1rem; border-right: 1px solid var(--line); }
.report-summary div:last-child { border-right: 0; }
.report-summary span { color: var(--muted); font-size: .76rem; font-weight: 750; text-transform: uppercase; }
.report-summary strong { font-size: 1.2rem; }
.findings, .guardrails { display: grid; gap: .8rem; }
.findings > div { padding: .7rem; border-radius: 10px; background: #f2f6f4; }
.findings span { color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.findings p, .guardrails p { margin-bottom: 0; }
.stack { display: grid; gap: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.driver-search-field { position: relative; }
.driver-search-status { min-height: 1.1rem; margin-top: -.55rem; color: var(--muted); font-size: .78rem; }
.driver-results { overflow: hidden; margin-top: -.65rem; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: 0 14px 30px rgba(23, 59, 58, .12); }
.driver-results-heading { margin: 0; padding: .62rem .75rem; background: var(--teal-100); color: var(--teal-900); font-size: .78rem; font-weight: 800; }
.driver-result { display: grid; grid-template-columns: minmax(220px, 1.5fr) minmax(110px, .6fr) minmax(140px, .8fr); gap: .75rem; width: 100%; padding: .72rem .8rem; border: 0; border-top: 1px solid var(--line); background: white; color: var(--ink); text-align: left; }
.driver-result:hover, .driver-result:focus { background: #f1f8f6; outline: none; }
.driver-result strong { min-width: 0; }
.driver-result span { color: var(--muted); font-size: .82rem; }
.autofill-grid { display: grid; grid-template-columns: 1.4fr .8fr 1fr; gap: .8rem; }
.autofill-grid input[readonly], .autofill-grid select:disabled { background: #edf4f2; color: var(--ink); opacity: 1; cursor: default; }
.selected-driver-actions { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .7rem .8rem; border-radius: 10px; background: var(--teal-100); color: var(--teal-900); font-size: .82rem; font-weight: 750; }
.manual-fallback { margin: -.35rem 0 0; color: var(--muted); font-size: .78rem; }
.button.compact { min-height: 34px; padding: .4rem .7rem; font-size: .78rem; }
.driver-filter { display: grid; grid-template-columns: minmax(220px, 1.3fr) minmax(180px, 1fr) 140px auto; align-items: end; gap: .75rem; }
.driver-table td:first-child small { display: block; margin-top: .2rem; }
.driver-actions { white-space: nowrap; }
.driver-actions form { display: inline; margin-left: .75rem; }
.link-button { padding: 0; border: 0; background: none; color: var(--danger); text-decoration: underline; }
.token-action { padding: 0; border: 0; background: none; color: var(--teal-700); text-decoration: underline; }
.manage-token-button { min-height: 34px; margin-left: .75rem; padding: .4rem .7rem; border: 1px solid var(--teal-700); border-radius: 8px; background: white; color: var(--teal-900); font-size: .78rem; font-weight: 750; white-space: nowrap; }
.manage-token-button:hover { background: var(--teal-100); }
.token-download { margin-left: .75rem; color: var(--teal-700); font-weight: 700; white-space: nowrap; }
.token-status small { display: block; margin-top: .3rem; white-space: nowrap; }
.token-flash p { margin: .35rem 0 .7rem; }
.token-copy-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .65rem; }
.qr-generator-panel { display: grid; grid-template-columns: minmax(190px, 260px) minmax(0, 1fr); align-items: center; gap: 1.15rem; margin-top: 1rem; padding: 1rem; border: 1px solid #acd7cf; border-radius: 14px; background: white; color: var(--ink); }
.qr-preview { display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.qr-preview canvas { display: block; width: 100%; height: auto; }
.qr-generator-info h3 { margin: 0 0 .3rem; }
.qr-generator-info p { margin-bottom: .8rem; }
.qr-generator-info small { display: block; margin-top: .65rem; }
.qr-generator-info small.saved { color: var(--teal-700); font-weight: 700; }
.qr-source { position: fixed; left: -10000px; top: 0; width: 1050px; height: 1050px; pointer-events: none; }
.modal.token-manager-modal { width: min(760px, calc(100vw - 2rem)); max-width: calc(100vw - 2rem); max-height: calc(100vh - 2rem); overflow: hidden; }
.token-manager-card { position: relative; display: grid; width: 100%; max-width: 100%; max-height: calc(100vh - 2rem); min-width: 0; gap: 1rem; padding: 1.35rem; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.token-manager-card > *, .token-detail-grid > *, .token-field-row > *, .token-qr-section > * { min-width: 0; }
.token-manager-card > header { padding-right: 2.5rem; }
.token-manager-card > header small { color: var(--teal-700); font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.token-manager-card > header h2 { margin: .2rem 0; font-size: 1.55rem; }
.token-manager-card > header p { margin-bottom: 0; color: var(--muted); }
.token-manager-loading { min-height: 150px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.token-detail-grid { display: grid; gap: .8rem; }
.token-field-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .6rem; }
.token-field-row input { min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }
.token-audit { margin: 0; color: var(--muted); font-size: .8rem; }
.token-qr-section { display: grid; grid-template-columns: 180px minmax(0, 1fr); align-items: center; gap: 1rem; padding: 1rem; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #f6faf8; }
.token-qr-section .qr-preview { width: 180px; max-width: 100%; min-height: 0; aspect-ratio: 14 / 17; margin: 0 auto; }
.token-qr-section .qr-preview canvas,
.token-qr-section .qr-preview img { display: block; width: 100%; max-width: 180px; height: auto; object-fit: contain; }
.token-manager-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .6rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.token-manager-actions form { margin: 0; }
.danger-button { border-color: var(--danger); background: var(--danger); }
.danger-button:hover { background: #812e2e; }
.error-text { color: var(--danger) !important; font-weight: 700; }
.row-inactive { opacity: .58; }
.muted-value { color: var(--muted); font-style: italic; }
.warning-pill { margin-left: .35rem; background: var(--warning-bg); color: var(--warning); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1.15rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }
.pagination div { display: flex; gap: .5rem; }

.survey-page { background: linear-gradient(145deg, #e8eee9, var(--cream) 45%); }
.survey-container { width: min(820px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.survey-hero { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.4rem; }
.survey-hero small { color: var(--teal-700); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.survey-hero h1 { margin: .25rem 0; }
.survey-hero p { margin: 0; color: var(--muted); }
.hero-mark { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 18px; }
.survey-form { display: grid; gap: 1rem; }
.panel { padding: clamp(1rem, 3vw, 1.5rem); }
.panel h2 { margin-bottom: .25rem; }
.panel p { margin-bottom: 0; color: var(--muted); }
.section-heading { padding: .6rem .2rem; }
.section-heading p { color: var(--muted); }
.questions { display: grid; gap: .8rem; }
.rating-item { min-width: 0; }
.rating-item.has-criterion-icon { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: .8rem; }
.criterion-icon { display: grid; justify-items: center; gap: .25rem; color: var(--teal-700); }
.criterion-icon svg { width: 78px; height: 78px; padding: .55rem; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.78); box-shadow: var(--shadow); fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.criterion-icon span { width: 100%; color: var(--muted); font-size: .67rem; font-weight: 800; line-height: 1.15; text-align: center; }
.rating-card { margin: 0; padding: 1.1rem; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.rating-card legend { padding: 0 .4rem; font-weight: 800; }
.rating-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .55rem; }
.rating-option { position: relative; }
.rating-option input { position: absolute; opacity: 0; pointer-events: none; }
.rating-option span { display: grid; place-items: center; height: 48px; border: 1px solid #c8d7d3; border-radius: 11px; background: white; color: var(--ink); font-size: 1rem; font-weight: 850; transition: .15s ease; }
.rating-option input:focus + span { box-shadow: 0 0 0 3px rgba(42,143,134,.18); }
.rating-option:hover span { border-color: var(--teal-500); }
.rating-option input:checked + span { border-color: var(--teal-700); background: var(--teal-700); color: white; }
.rating-ends { display: flex; justify-content: space-between; margin-top: .35rem; color: var(--muted); font-size: .72rem; }
.followup-saved { margin: .55rem 0 0; color: var(--teal-700); font-size: .8rem; font-weight: 750; }
.privacy-note { padding: .8rem; border-radius: 10px; background: var(--teal-100); font-size: .85rem; }
.submit-button { width: 100%; min-height: 54px; font-size: 1rem; }
.survey-container footer { margin-top: 1.2rem; color: var(--muted); text-align: center; font-size: .78rem; }
.success-card { padding: 2.5rem 1.5rem; text-align: center; }
.success-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 50%; background: var(--teal-100); color: var(--teal-700); font-size: 2rem; font-weight: 900; }

.modal { width: min(560px, calc(100% - 1rem)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(8, 37, 35, .67); backdrop-filter: blur(3px); }
.modal-card { position: relative; display: grid; gap: 1rem; padding: 1.5rem; }
.modal-card h2, .modal-card p { margin-bottom: 0; }
.modal-close { position: absolute; top: .65rem; right: .7rem; border: 0; background: none; color: var(--muted); font-size: 1.8rem; }
.warning-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--warning-bg); color: var(--warning); font-size: 1.3rem; font-weight: 900; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.field-error { color: var(--danger); font-size: .82rem; font-weight: 700; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(430px, 100%); padding: 1.5rem; }
.login-card .brand { color: var(--ink); padding: 0; margin-bottom: 1.5rem; }
.login-card .brand small { color: var(--muted); }
.system-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.system-grid ol, .system-grid ul { margin-bottom: 0; padding-left: 1.25rem; }
.system-grid li + li { margin-top: .5rem; }
.status-ok { color: var(--teal-700); }
.status-bad { color: var(--danger); }

@media (max-width: 1050px) {
    .metric-cards { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; padding: .8rem; }
    .sidebar nav { grid-template-columns: repeat(2, 1fr); margin-top: .8rem; }
    .sidebar-foot { display: none; }
    .page-content { padding-top: 1.4rem; }
    .page-header, .card > header.split { align-items: stretch; flex-direction: column; }
    .filter-bar { grid-template-columns: repeat(2, 1fr); }
    .filter-division { grid-column: 1 / -1; }
    .filter-bar .button { grid-column: 1 / -1; }
    .dashboard-grid, .system-grid { grid-template-columns: 1fr; }
    .driver-filter, .autofill-grid { grid-template-columns: 1fr; }
    .report-summary { grid-template-columns: repeat(2, 1fr); }
    .report-summary div:nth-child(2) { border-right: 0; }
    .report-summary div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 520px) {
    .metric-cards, .form-grid { grid-template-columns: 1fr; }
    .survey-hero { align-items: flex-start; }
    .hero-mark { width: 52px; height: 52px; }
    .rating-grid { gap: .32rem; }
    .rating-option span { height: 44px; }
    .driver-result { grid-template-columns: 1fr; gap: .15rem; }
    .selected-driver-actions, .pagination { align-items: stretch; flex-direction: column; }
    .token-copy-row { grid-template-columns: 1fr; }
    .qr-generator-panel { grid-template-columns: 1fr; }
    .qr-preview { width: min(280px, 100%); margin: auto; }
    .modal.token-manager-modal { width: calc(100vw - 1rem); max-width: calc(100vw - 1rem); max-height: calc(100vh - 1rem); }
    .token-manager-card { max-height: calc(100vh - 1rem); padding: 1rem; }
    .token-field-row, .token-qr-section { grid-template-columns: 1fr; }
    .token-qr-section .qr-preview { width: 160px; }
    .token-qr-section .qr-preview canvas,
    .token-qr-section .qr-preview img { max-width: 160px; }
    .token-manager-actions { align-items: stretch; flex-direction: column; }
    .token-manager-actions form, .token-manager-actions .button { width: 100%; }
    .rating-item.has-criterion-icon { grid-template-columns: 56px minmax(0, 1fr); gap: .45rem; }
    .criterion-icon svg { width: 52px; height: 52px; padding: .4rem; border-radius: 14px; }
    .criterion-icon span { display: none; }
    .rating-card { padding: .85rem; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions .button { width: 100%; }
}

/* QR bitmaps are generated and stored for download only, not displayed. */
#tokenManagerDialog .token-qr-section { grid-template-columns: minmax(0, 1fr) !important; }
#tokenManagerDialog .qr-preview,
#tokenManagerDialog #qrLabelCanvas,
#tokenManagerDialog #storedQrPreview { display: none !important; }

@media print {
    body { background: white; }
    .sidebar, .filter-bar, .page-header .button, .form-card { display: none !important; }
    .app-shell { display: block; }
    .page-content { max-width: none; padding: 0; }
    .card, .metric, .report-summary { box-shadow: none; break-inside: avoid; }
}
