/* ==========================================================
   Электронная очередь — стили
   ========================================================== */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --fill: rgba(118, 118, 128, 0.12);
    --fill-press: rgba(118, 118, 128, 0.2);
    --ink: #1d1d1f;
    --ink-2: #6e6e73;
    --ink-3: #86868b;
    --sep: rgba(60, 60, 67, 0.14);
    --blue: #0071e3;
    --blue-press: #0062c4;
    --green: #1a8f45;
    --red: #d70015;
    --red-fill: rgba(215, 0, 21, 0.08);

    --r-xl: 28px;
    --r-l: 20px;
    --r-m: 14px;

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
    --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;

    --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --surface: #1c1c1e;
        --fill: rgba(118, 118, 128, 0.24);
        --fill-press: rgba(118, 118, 128, 0.36);
        --ink: #f5f5f7;
        --ink-2: #a1a1a6;
        --ink-3: #8e8e93;
        --sep: rgba(84, 84, 88, 0.6);
        --blue: #2997ff;
        --blue-press: #0a84ff;
        --green: #30d158;
        --red: #ff453a;
        --red-fill: rgba(255, 69, 58, 0.14);
    }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.022em;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, p, ol, ul, dl, dd { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; letter-spacing: inherit; }

.num { font-variant-numeric: tabular-nums; }
.issued-number, .pass-number, .now-number, .tv-number, .state-number { white-space: nowrap; }

/* ---------- Каркас ---------- */
.view { display: none; }
.view.active { display: block; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 56px 24px 64px; }
.wrap-narrow { max-width: 560px; margin: 0 auto; padding: 56px 24px 64px; }

/* ---------- Типографика ---------- */
.title-xl {
    font-family: var(--font-display);
    font-size: clamp(40px, 6vw, 56px);
    font-weight: 700;
    line-height: 1.07;
    letter-spacing: -0.035em;
}
.title-l {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    line-height: 1.14;
    letter-spacing: -0.03em;
}
.lead { font-size: 21px; line-height: 1.38; color: var(--ink-2); letter-spacing: -0.02em; }
.meta { font-size: 15px; color: var(--ink-2); letter-spacing: -0.01em; }
.place { font-size: 17px; font-weight: 600; color: var(--ink-2); }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 22px;
    border: 0;
    border-radius: 980px;
    background: var(--fill);
    color: var(--ink);
    font-size: 17px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s var(--ease), transform 0.12s var(--ease), opacity 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--fill-press); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn:focus-visible, .tile:focus-visible, .field:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--blue) 60%, transparent);
    outline-offset: 3px;
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-press); }
.btn-plain { background: transparent; color: var(--blue); padding-left: 12px; padding-right: 12px; font-weight: 400; }
.btn-plain:hover { background: transparent; text-decoration: underline; }
.btn-destructive { color: var(--red); }
.btn-tinted-red { background: var(--red-fill); color: var(--red); }
.btn-tinted-red:hover { background: color-mix(in srgb, var(--red) 16%, transparent); }
.btn-xl { min-height: 64px; padding: 18px 36px; font-size: 21px; }
.btn-block { width: 100%; }

/* ---------- Поле ввода ---------- */
.field {
    width: 100%;
    min-height: 52px;
    padding: 14px 18px;
    border: 1px solid var(--sep);
    border-radius: var(--r-m);
    background: var(--surface);
    font-size: 17px;
    outline: none;
    transition: border-color 0.2s var(--ease);
}
.field:focus { border-color: var(--blue); }
.field-error { margin-top: 10px; font-size: 15px; color: var(--red); }

/* ---------- Сгруппированный список (как в настройках) ---------- */
.group { background: var(--surface); border-radius: var(--r-l); overflow: hidden; }
.group > li {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 52px;
    padding: 12px 20px;
    position: relative;
}
.group > li + li::before {
    content: "";
    position: absolute;
    top: 0; left: 20px; right: 0;
    border-top: 1px solid var(--sep);
}
.group .row-code { font-weight: 600; font-variant-numeric: tabular-nums; }
.group .row-pos { width: 22px; color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 15px; }
.group .row-detail { margin-left: auto; color: var(--ink-2); font-size: 15px; text-align: right; }
.group .row-empty { color: var(--ink-3); }
.group-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 20px 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-2);
}
.group-title .count { color: var(--ink-3); font-weight: 400; font-variant-numeric: tabular-nums; }

/* ---------- Экран выбора ---------- */
.chooser-head { max-width: 640px; margin-bottom: 48px; }
.chooser-head .lead { margin-top: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 200px;
    padding: 24px;
    border-radius: var(--r-l);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    transition: transform 0.2s var(--ease);
}
.tile:active { transform: scale(0.98); }
.tile svg { width: 34px; height: 34px; margin-bottom: auto; color: var(--blue); }
.tile h2 { font-size: 21px; font-weight: 600; letter-spacing: -0.025em; margin-top: 24px; }
.tile p { font-size: 15px; color: var(--ink-2); line-height: 1.4; }
.tile-staff svg { color: var(--ink-2); }

/* ---------- Терминал ---------- */
.kiosk { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 48px 24px; }
.kiosk-inner { max-width: 620px; display: flex; flex-direction: column; align-items: center; }
.kiosk .title-xl { margin-top: 10px; }
.kiosk .lead { margin-top: 16px; max-width: 500px; }
.kiosk .btn-xl { margin-top: 48px; min-width: 300px; }
.kiosk .meta { margin-top: 20px; min-height: 22px; }

.issued-number {
    font-family: var(--font-display);
    font-size: clamp(96px, min(18vw, 24vh), 220px);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.05em;
    font-variant-numeric: tabular-nums;
    margin: 8px 0 28px;
}
.issued-qr { padding: 16px; background: #fff; border-radius: var(--r-l); }
.issued-qr img, .issued-qr canvas { display: block; }
.kiosk-result .meta { max-width: 360px; }

/* ---------- Талон пациента ---------- */
.pass {
    background: var(--surface);
    border-radius: var(--r-xl);
    padding: 28px 28px 24px;
    text-align: left;
}
.pass-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 980px;
    background: var(--fill);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.005em;
    white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.pass-label { margin-top: 44px; font-size: 15px; color: var(--ink-2); }
.pass-number {
    font-family: var(--font-display);
    font-size: clamp(64px, 22vw, 150px);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: -0.055em;
    font-variant-numeric: tabular-nums;
    margin: 4px 0 36px -4px;
}
.pass-head .place { font-size: 15px; }
.pass-facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--sep);
    padding-top: 18px;
}
.pass-facts div + div { border-left: 1px solid var(--sep); padding-left: 16px; }
.pass-facts dt { font-size: 13px; color: var(--ink-2); }
.pass-facts dd { white-space: nowrap; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 2px; }
.pass-note { margin: 20px 4px 0; font-size: 15px; color: var(--ink-2); text-align: center; }

.state-screen {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
    background: var(--bg);
    color: var(--ink);
    animation: fade 0.4s var(--ease);
}
.state-screen .state-number {
    font-family: var(--font-display);
    font-size: clamp(96px, 30vw, 180px);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.055em;
    font-variant-numeric: tabular-nums;
}
.state-screen .state-title { margin-top: 24px; font-family: var(--font-display); font-size: 34px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.state-screen .state-text { margin-top: 12px; font-size: 19px; opacity: 0.8; max-width: 420px; }
.state-screen.is-serving { background: var(--green); color: #fff; }
.state-screen.is-missed { background: var(--red); color: #fff; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card svg { width: 44px; height: 44px; color: var(--ink-3); }
.login-card .title-l { margin-top: 16px; }
.login-card .meta { margin-top: 8px; margin-bottom: 28px; }
.login-card .btn { margin-top: 14px; }
.login-back { display: inline-block; margin-top: 28px; }

/* ---------- Верхняя панель (врач, админ) ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--sep);
}
.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.topbar h1 { font-size: 21px; font-weight: 600; letter-spacing: -0.025em; }
.topbar .meta { font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ---------- Панель врача ---------- */
.doctor-grid {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px 64px;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr);
    gap: 32px;
    align-items: start;
}
.now-panel {
    background: var(--surface);
    border-radius: var(--r-xl);
    padding: 32px;
    display: flex;
    flex-direction: column;
}
.now-panel .label { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.now-number {
    font-family: var(--font-display);
    font-size: clamp(96px, 12vw, 160px);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.055em;
    font-variant-numeric: tabular-nums;
    margin: 16px 0 8px -4px;
}
.now-number.is-empty { color: var(--ink-3); opacity: 0.5; }
.now-panel .meta { min-height: 22px; }
.now-panel .btn-xl { margin-top: 36px; }
.action-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.action-row .btn { min-height: 52px; padding: 10px 12px; font-size: 15px; }
.now-panel .btn-plain { align-self: center; margin-top: 16px; }

.side { display: flex; flex-direction: column; gap: 28px; }
.side .waiting .group > li { min-height: 56px; }
.side .waiting .row-code { font-size: 21px; letter-spacing: -0.02em; }
.side .waiting li:first-child .row-detail { color: var(--blue); font-weight: 600; }
.side .btn-plain { align-self: flex-start; }

/* ---------- Админ панель ---------- */
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 32px 24px 64px; }
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border-radius: var(--r-xl);
    padding: 28px 0;
}
.stat { padding: 0 28px; }
.stat + .stat { border-left: 1px solid var(--sep); }
.stat dt { font-size: 15px; color: var(--ink-2); }
.stat dd {
    font-family: var(--font-display);
    font-size: 48px;
    font-weight: 700;
    letter-spacing: -0.04em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    margin-top: 6px;
}
.stat dd small { font-size: 21px; font-weight: 600; color: var(--ink-2); letter-spacing: -0.02em; margin-left: 4px; }
.admin-meta { margin: 16px 20px 40px; }
.admin-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: start; }
.date-field { min-height: 40px; padding: 6px 12px; border-radius: 10px; width: auto; font-size: 15px; }

/* ---------- QR ---------- */
.qr-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 48px 24px; }
.qr-page .lead { margin-top: 14px; }
.qr-box { display: inline-block; margin-top: 40px; padding: 24px; background: #fff; border-radius: var(--r-xl); }
.qr-box img, .qr-box canvas { display: block; }

/* ---------- Табло ---------- */
body.mode-display { background: #000; color: #f5f5f7; overflow: hidden; }
#display-view.active {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: clamp(24px, 3.5vw, 56px);
    color: #f5f5f7;
    background: #000;
}
.tv-head { display: flex; align-items: center; gap: 24px; }
.tv-place { font-size: clamp(20px, 1.8vw, 30px); font-weight: 600; color: #86868b; letter-spacing: -0.02em; }
.tv-clock { margin-left: auto; font-size: clamp(20px, 1.8vw, 30px); font-weight: 600; font-variant-numeric: tabular-nums; }
.tv-mute {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border: 0; border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #f5f5f7;
    cursor: pointer;
}
.tv-mute svg { width: 22px; height: 22px; }

.tv-main { display: grid; grid-template-columns: 1.5fr 1fr; gap: clamp(32px, 4vw, 80px); min-height: 0; padding: clamp(24px, 3vw, 48px) 0; }
.tv-now {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-radius: 40px;
    padding: clamp(32px, 4vw, 64px);
    background: #1c1c1e;
    overflow: hidden;
}
.tv-label { font-size: clamp(22px, 2.2vw, 36px); font-weight: 600; color: #86868b; letter-spacing: -0.02em; }
.tv-number {
    font-family: var(--font-display);
    font-size: clamp(110px, 14vw, 300px);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: -0.055em;
    font-variant-numeric: tabular-nums;
    margin: 0.08em 0 0.1em -0.04em;
}
.tv-number.is-empty { color: #3a3a3c; }
.tv-hint { font-size: clamp(22px, 2.2vw, 36px); color: #f5f5f7; letter-spacing: -0.02em; min-height: 1.3em; }

/* Единственная анимация: момент вызова */
.tv-now::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(120% 90% at 0% 100%, rgba(41, 151, 255, 0.55), transparent 60%);
    opacity: 0;
    pointer-events: none;
}
.tv-now.is-calling::after { animation: call-glow 1.6s var(--ease) 3; }
.tv-now.is-calling .tv-number { animation: call-in 0.7s var(--ease); }
@keyframes call-glow { 0%, 100% { opacity: 0; } 40% { opacity: 1; } }
@keyframes call-in { from { opacity: 0; transform: translateY(0.12em) scale(0.96); } to { opacity: 1; transform: none; } }

.tv-queue { display: flex; flex-direction: column; min-height: 0; }
.tv-queue-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.tv-queue-head h2 { font-size: clamp(22px, 2.2vw, 36px); font-weight: 600; color: #86868b; letter-spacing: -0.02em; }
.tv-queue-head p { font-size: clamp(18px, 1.6vw, 26px); color: #86868b; font-variant-numeric: tabular-nums; }
.tv-list { display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.tv-list li {
    display: flex;
    align-items: baseline;
    gap: 20px;
    padding: clamp(12px, 1.3vw, 22px) clamp(20px, 2vw, 32px);
    border-radius: 20px;
    background: #1c1c1e;
    font-size: clamp(32px, 3.4vw, 60px);
    font-weight: 700;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}
.tv-list li .pos { font-size: 0.45em; font-weight: 600; color: #636366; width: 1.6em; }
.tv-list li.tv-more { background: transparent; color: #86868b; font-size: clamp(20px, 1.8vw, 30px); font-weight: 600; padding-top: 4px; }
.tv-list li.tv-empty { background: transparent; color: #636366; font-size: clamp(22px, 2vw, 32px); font-weight: 500; padding: 0; }
.tv-foot { font-size: clamp(16px, 1.4vw, 24px); color: #86868b; letter-spacing: -0.015em; }

/* ---------- Звук, связь, уведомления ---------- */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    cursor: pointer;
}
.sheet-card {
    width: 100%;
    max-width: 360px;
    padding: 32px 28px 24px;
    border-radius: var(--r-xl);
    background: var(--surface);
    color: var(--ink);
    text-align: center;
}
.sheet-card svg { width: 44px; height: 44px; color: var(--blue); }
.sheet-card h2 { margin-top: 14px; font-size: 21px; font-weight: 600; letter-spacing: -0.025em; }
.sheet-card p { margin-top: 8px; font-size: 15px; color: var(--ink-2); }
.sheet-card .btn { margin-top: 24px; }

.banner {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    padding: 10px 20px;
    border-radius: 980px;
    background: rgba(29, 29, 31, 0.88);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    white-space: nowrap;
}
.banner::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 10px; border-radius: 50%; background: #ff453a; vertical-align: 1px; }

.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    max-width: calc(100% - 48px);
    padding: 14px 22px;
    border-radius: 980px;
    background: rgba(29, 29, 31, 0.92);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    animation: toast-in 0.3s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
    .doctor-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); row-gap: 24px; }
    .stat:nth-child(3) { border-left: 0; }
    .admin-lists { grid-template-columns: 1fr; }
    .tv-main { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
    .wrap, .wrap-narrow { padding-top: 32px; }
    .pass { padding: 24px 22px 20px; }
    .action-row { grid-template-columns: 1fr; }
    .now-panel { padding: 24px; }
    .stat { padding: 0 20px; }
    .stat dd { font-size: 36px; }
    .topbar-inner { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Печатный талон (термопринтер 80 или 58 мм) ---------- */
.print-ticket { display: none; }

@media print {
    @page { margin: 0; }
    html, body { background: #fff !important; color: #000 !important; min-height: 0; }
    body > *:not(#print-ticket) { display: none !important; }
    #print-ticket { display: block; }
}

/* Предпросмотр на экране: ?view=register&mode=kiosk&print=1&preview=1 */
body.print-preview > *:not(#print-ticket) { display: none !important; }
body.print-preview { background: #e5e5ea; }
body.print-preview #print-ticket { display: block; margin: 24px auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }

.print-ticket {
    width: var(--paper-width, 72mm);
    padding: 4mm 3mm 8mm;
    color: #000;
    font-family: Arial, "Helvetica Neue", sans-serif;
    text-align: center;
    letter-spacing: 0;
}
.print-ticket p { margin: 0; }
.pt-place { font-size: 13pt; font-weight: 700; }
.pt-label { margin-top: 3mm; font-size: 10pt; }
.pt-number { font-size: 44pt; font-weight: 900; line-height: 1.05; letter-spacing: -0.02em; white-space: nowrap; }
.pt-line { font-size: 11pt; font-weight: 700; margin-top: 1mm; }
.pt-line:empty { display: none; }
.pt-qr { display: flex; justify-content: center; margin: 4mm 0 2mm; }
.pt-qr img, .pt-qr canvas { width: 30mm !important; height: 30mm !important; image-rendering: pixelated; }
.pt-note { font-size: 8.5pt; line-height: 1.3; }
.pt-date { margin-top: 3mm; font-size: 9pt; }
.paper-58 .print-ticket { --paper-width: 48mm; }
.paper-58 .pt-number { font-size: 34pt; }
.paper-58 .pt-qr img, .paper-58 .pt-qr canvas { width: 26mm !important; height: 26mm !important; }
.paper-58 .pt-place { font-size: 11pt; }
.paper-58 .pt-line { font-size: 9.5pt; }
