:root {
    --bg: #f6f7f7;
    --surface: #ffffff;
    --surface-2: #eef2f1;
    --border: #dfe5e3;
    --text: #14201d;
    --text-2: #4b5a56;
    --muted: #6b7a76;
    --accent: #0f766e;
    --accent-ink: #ffffff;
    --accent-soft: #dff3ef;
    --chart: #0d9488;
    --pref: #9a3412;
    --pref-soft: #fdeee4;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --ok: #15803d;
    --shadow: 0 1px 2px rgb(16 24 22 / .06), 0 4px 16px rgb(16 24 22 / .06);
    --radius: 14px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1312;
        --surface: #151d1b;
        --surface-2: #1c2624;
        --border: #2a3633;
        --text: #e8efed;
        --text-2: #b3c1bd;
        --muted: #8a9995;
        --accent: #2dd4bf;
        --accent-ink: #062b27;
        --accent-soft: #123631;
        --chart: #0d9488;
        --pref: #fb923c;
        --pref-soft: #3a2316;
        --danger: #f87171;
        --danger-soft: #3a1b1b;
        --ok: #4ade80;
        --shadow: 0 1px 2px rgb(0 0 0 / .4);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0d1312; --surface: #151d1b; --surface-2: #1c2624; --border: #2a3633;
    --text: #e8efed; --text-2: #b3c1bd; --muted: #8a9995; --accent: #2dd4bf; --accent-ink: #062b27;
    --accent-soft: #123631; --chart: #0d9488; --pref: #fb923c; --pref-soft: #3a2316;
    --danger: #f87171; --danger-soft: #3a1b1b; --ok: #4ade80; --shadow: 0 1px 2px rgb(0 0 0 / .4);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: -.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Topo ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    padding: .65rem max(16px, calc((100% - 1100px) / 2));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
    display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 800;
}
.nav { display: flex; gap: .25rem; flex-wrap: wrap; margin-left: auto; }
.nav a {
    padding: .4rem .7rem; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; font-size: .95rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

main { padding: 1.5rem 16px 3rem; max-width: 1100px; margin: 0 auto; }
body.kiosk main { max-width: none; padding: 0; }

/* ---------- Componentes ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.25rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.big { font-size: 1.15rem; padding: .9rem 1.4rem; min-height: 56px; }
.btn.ghost { background: transparent; border-color: transparent; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=date], select {
    width: 100%; padding: .6rem .75rem; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; min-height: 42px;
}
.check { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.badge {
    display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700;
    background: var(--surface-2); color: var(--text-2);
}
.badge.pref { background: var(--pref-soft); color: var(--pref); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }

.code { font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

#toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
    background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px;
    box-shadow: var(--shadow); max-width: calc(100% - 32px); font-weight: 500;
}
#toast.error { background: var(--danger); color: #fff; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.notice { padding: .9rem 1rem; border-radius: 10px; background: var(--accent-soft); color: var(--text); }
.notice.warn { background: var(--pref-soft); }

/* ---------- Início ---------- */
.hero { padding: 2rem 0 1.5rem; max-width: 720px; }
.hero p { font-size: 1.1rem; color: var(--text-2); }
.eyebrow { color: var(--accent); font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: .5rem; }
.feature h3 { margin-bottom: .25rem; }
.feature p { color: var(--text-2); margin: 0; font-size: .95rem; }
.feature .icon { font-size: 1.5rem; margin-bottom: .5rem; }
.device { display: flex; flex-direction: column; gap: .75rem; }
.device .qr { width: 120px; align-self: flex-start; background: #fff; padding: 6px; border-radius: 8px; }
.steps { margin: 0; padding-left: 1.2rem; color: var(--text-2); }
.steps li { margin-bottom: .35rem; }
.footer { margin-top: 3rem; color: var(--muted); font-size: .875rem; text-align: center; }

/* ---------- Totem ---------- */
.totem { min-height: 100vh; display: flex; flex-direction: column; padding: clamp(16px, 4vw, 48px); gap: 1.5rem; }
.totem-head { text-align: center; }
.totem-head h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
.totem-services { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); flex: 1; align-content: center; max-width: 1000px; width: 100%; margin: 0 auto; }
.totem-btn {
    display: flex; flex-direction: column; align-items: flex-start; gap: .35rem;
    padding: 1.5rem; border-radius: 18px; border: 2px solid var(--border); background: var(--surface);
    color: var(--text); font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow); min-height: 130px;
}
.totem-btn:hover { border-color: var(--accent); }
.totem-btn .name { font-size: 1.5rem; font-weight: 700; }
.totem-btn .meta { color: var(--muted); }
.totem-btn .letter {
    display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
    background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 1.3rem;
}
.totem-btn.pref .letter { background: var(--pref-soft); color: var(--pref); }
.totem-ticket { text-align: center; max-width: 520px; margin: auto; width: 100%; }
.totem-ticket .code { font-size: clamp(4rem, 18vw, 7.5rem); line-height: 1; color: var(--accent); margin: .5rem 0; }
.totem-ticket .qr { width: 180px; margin: 1rem auto; background: #fff; padding: 8px; border-radius: 10px; }
.totem-foot { text-align: center; color: var(--muted); font-size: .9rem; }

/* ---------- Painel ---------- */
.panel {
    min-height: 100vh; display: grid; grid-template-columns: 1.6fr 1fr; grid-template-rows: auto 1fr auto;
    gap: clamp(12px, 2vw, 24px); padding: clamp(12px, 2.5vw, 32px);
}
.panel-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.panel-head .unit { font-size: clamp(1.1rem, 2.4vw, 1.8rem); font-weight: 700; }
.panel-head .clock { font-size: clamp(1.4rem, 3vw, 2.4rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.panel-current {
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
    background: var(--accent); color: var(--accent-ink); border-radius: 24px; padding: 2rem;
}
.panel-current .label { font-size: clamp(1rem, 2.2vw, 1.8rem); font-weight: 600; opacity: .85; text-transform: uppercase; letter-spacing: .1em; }
.panel-current .code { font-size: clamp(5rem, 16vw, 14rem); line-height: 1; margin: .5rem 0; }
.panel-current .counter { font-size: clamp(1.8rem, 5vw, 4.5rem); font-weight: 800; }
.panel-current .service { font-size: clamp(1rem, 2vw, 1.6rem); opacity: .85; margin-top: .5rem; }
.panel-current.flash { animation: flash 1s ease-in-out 3; }
@keyframes flash { 50% { filter: brightness(1.35); transform: scale(1.015); } }
@media (prefers-reduced-motion: reduce) { .panel-current.flash { animation: none; } }
.panel-history { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; }
.panel-history h2 { font-size: clamp(1rem, 1.8vw, 1.4rem); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.panel-history ol { list-style: none; margin: 0; padding: 0; }
.panel-history li { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); font-size: clamp(1.2rem, 2.6vw, 2.2rem); }
.panel-history li:last-child { border-bottom: 0; }
.panel-history .code { font-size: 1em; }
.panel-history .counter { color: var(--text-2); font-weight: 600; font-size: .8em; }
.panel-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .75rem; }
.panel-foot .wait { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem 1rem; font-size: clamp(.9rem, 1.6vw, 1.2rem); }
.panel-foot .wait b { font-variant-numeric: tabular-nums; }
.overlay {
    position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
    background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(4px);
}
.overlay .card { max-width: 440px; text-align: center; }
@media (max-width: 760px) {
    .panel { grid-template-columns: 1fr; }
}

/* ---------- Guichê ---------- */
.desk { display: grid; gap: 1rem; grid-template-columns: 1.2fr 1fr; align-items: start; }
@media (max-width: 860px) { .desk { grid-template-columns: 1fr; } }
.desk-current { text-align: center; padding: 2rem 1.25rem; }
.desk-current .code { font-size: clamp(3.5rem, 10vw, 5.5rem); line-height: 1; color: var(--accent); }
.desk-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin-top: 1.25rem; }
.queue-list { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow: auto; }
.queue-list li { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.queue-list li .code { min-width: 4.5rem; }
.queue-list li .grow { flex: 1; color: var(--text-2); font-size: .9rem; }
.kbd { font: 600 .75rem/1 ui-monospace, monospace; padding: .15rem .35rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; color: var(--text-2); }
.service-picks { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }

/* ---------- Acompanhamento (QR) ---------- */
.track { max-width: 460px; margin: 0 auto; text-align: center; }
.track .code { font-size: clamp(4rem, 22vw, 6.5rem); line-height: 1; color: var(--accent); margin: .5rem 0; }
.track .status { font-size: 1.25rem; font-weight: 700; }
.track .called { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.track .called .code { color: var(--accent-ink); }
.ahead { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }

/* ---------- Relatórios ---------- */
.kpis { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi .value { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--chart); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.15); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .value-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.tooltip {
    position: absolute; pointer-events: none; z-index: 5; background: var(--text); color: var(--bg);
    padding: .4rem .6rem; border-radius: 8px; font-size: .8rem; white-space: nowrap; transform: translate(-50%, calc(-100% - 8px));
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: .5rem .85rem; font: inherit; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

/* ---------- Impressão (cupom 80 mm) ---------- */
.print-ticket { display: none; }
@media print {
    @page { size: 80mm auto; margin: 4mm; }
    body * { visibility: hidden; }
    body { background: #fff; min-height: 0; }
    .print-ticket, .print-ticket * { visibility: visible; }
    .print-ticket {
        display: block; position: absolute; left: 0; top: 0; width: 72mm;
        color: #000; text-align: center; font-family: Arial, sans-serif;
    }
    .print-ticket .p-unit { font-size: 12pt; font-weight: 700; }
    .print-ticket .p-service { font-size: 11pt; margin-top: 2mm; }
    .print-ticket .p-code { font-size: 40pt; font-weight: 800; margin: 2mm 0; }
    .print-ticket .p-pref { font-size: 10pt; font-weight: 700; border: 1px solid #000; display: inline-block; padding: 0 2mm; }
    .print-ticket .p-qr { width: 32mm; margin: 3mm auto 1mm; }
    .print-ticket .p-small { font-size: 8pt; }
}
.qr-link { display: block; width: fit-content; margin: 0 auto; }
