/* TicketCheck v2 – scanner UI. Dark theme, brand colours #00549f / #f5a623. No external resources. */

:root {
    --primary: #00549f;
    --primary-hi: #2f7fd0;
    --accent: #f5a623;
    --bg: #0b1522;
    --surface: #14233a;
    --surface-2: #1c304d;
    --line: #2c4366;
    --text: #f1f5f9;
    --muted: #a9b9cf;
    --ok: #0b7a34;
    --bad: #b3001b;
    --bad-dark: #7a0019;
    --warn: #f08c00;
    --net: #1f3a5f;
    --gold: #c9a227;
    --gold-hi: #f3d98b;
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

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

[hidden] { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.35;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: none;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* Android-App (WebView): Platz für die System-Navigationsleiste wie 2025 */
body.in-app { padding-bottom: 52px; }

input, select, textarea {
    -webkit-user-select: text;
    user-select: text;
    font: inherit;
}

button { font: inherit; }

/* ------------------------------------------------------------------ generic pieces */

.view {
    max-width: 720px;
    margin: 0 auto;
    padding: 10px 12px 18px;
}

.card, .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}

.panel { margin-top: 10px; }

.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1 1 0; min-width: 0; }

label {
    display: block;
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 5px;
}
.opt { font-weight: 400; opacity: 0.8; }

input[type="text"], select {
    display: block;
    width: 100%;
    min-height: 52px;
    padding: 10px 12px;
    font-size: 1.15rem; /* >= 16px: kein iOS-Zoom */
    color: var(--text);
    background: #0d1a2c;
    border: 2px solid var(--line);
    border-radius: 10px;
    outline: none;
}
input[type="text"]::placeholder { color: #6f829c; }
input[type="text"]:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.3);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 10px 16px;
    border: 2px solid transparent;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    background: var(--surface-2);
    cursor: pointer;
    text-align: center;
}
.btn:focus { outline: none; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:active { transform: scale(0.98); filter: brightness(1.15); }
.btn[disabled] { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--primary); border-color: var(--primary-hi); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: transparent; border-color: #c2475a; color: #ffc9d1; width: 100%; margin-top: 10px; }
.btn-danger[data-armed="1"] { background: var(--bad); border-color: #fff; color: #fff; }
.btn-xl { width: 100%; min-height: 64px; font-size: 1.25rem; }

.msg {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.98rem;
    border-left: 6px solid transparent;
}
.msg-error { background: #3a0f18; border-left-color: #ff5a73; color: #ffd9df; }
.msg-warn { background: #3a2a08; border-left-color: var(--accent); color: #ffe7b8; }
.msg-info { background: #10263f; border-left-color: var(--primary-hi); color: #cfe2f7; }

.fatal {
    position: fixed;
    left: 0; right: 0; top: 0;
    z-index: 100;
    padding: calc(12px + var(--safe-top)) 14px 12px;
    background: var(--bad);
    color: #fff;
    font-size: 1rem;
}
.fatal strong, .fatal span { display: block; }

/* ------------------------------------------------------------------ login */

.view-login { padding-top: 0; }

.brand {
    margin: 0 -12px 16px;
    padding: 22px 16px 20px;
    text-align: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 0 0 18px 18px;
}
.brand h1 { margin: 0; font-size: 1.9rem; letter-spacing: 0.01em; }
.brand p { margin: 4px 0 0; font-size: 0.95rem; }

.hint { color: var(--muted); font-size: 0.9rem; margin: 14px 4px 0; }

.apk { margin-top: 18px; text-align: center; font-size: 0.9rem; }
.apk a { color: var(--muted); text-decoration: underline; display: inline-block; padding: 12px; }
.apk p { color: var(--muted); margin: 4px 0 0; }

.foot { margin-top: 22px; text-align: center; color: #6f829c; font-size: 0.78rem; }

/* ------------------------------------------------------------------ scan view: header + counter */

.top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 2px 8px;
}
.top-main { flex: 1 1 auto; min-width: 0; }
.ev-name {
    font-size: 1.15rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ev-meta { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}
.conn-dot { width: 12px; height: 12px; border-radius: 50%; background: #6f829c; }
.conn[data-state="online"] .conn-dot { background: #35d07f; }
.conn[data-state="slow"] .conn-dot { background: var(--accent); border-radius: 2px; }
.conn[data-state="offline"] { border-color: #ff5a73; color: #ffd9df; background: #3a0f18; font-weight: 700; }
.conn[data-state="offline"] .conn-dot { background: #ff5a73; border-radius: 0; transform: rotate(45deg); }

.counter {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 14px 12px;
}
.counter-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.counter-label { color: var(--muted); font-size: 0.95rem; }
.counter-num { font-size: 1.5rem; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.counter-num b { font-size: 2.4rem; line-height: 1; color: var(--text); }
.bar {
    height: 14px;
    margin: 8px 0 8px;
    border-radius: 7px;
    background: #0d1a2c;
    border: 1px solid var(--line);
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    width: 0;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(135deg, var(--primary-hi), var(--accent));
    transition: width 0.35s ease;
}
.counter-sub { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.counter-sub b { color: var(--text); font-size: 1.1rem; }

/* ------------------------------------------------------------------ mode chips */

.modes { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: 0.88rem;
    color: var(--muted);
}
.chip-dot { width: 10px; height: 10px; border-radius: 50%; background: #6f829c; }
.chip[data-state="on"] { color: var(--text); border-color: #2f9e64; }
.chip[data-state="on"] .chip-dot { background: #35d07f; }
.chip[data-state="paused"] { color: var(--text); border-color: var(--accent); }
.chip[data-state="paused"] .chip-dot { background: var(--accent); border-radius: 2px; }
.chip[data-state="error"] { color: #ffd9df; border-color: #ff5a73; }
.chip[data-state="error"] .chip-dot { background: #ff5a73; border-radius: 0; }

/* ------------------------------------------------------------------ camera */

.cam { margin-bottom: 10px; }
.cam-view {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-width: min(420px, 46vh); /* leave room for the result card on small screens */
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--line);
}
@supports not (aspect-ratio: 1 / 1) {
    .cam-view { height: 0; padding-bottom: 100%; }
}
.cam-view video {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cam-frame {
    position: absolute;
    left: 12%; top: 12%;
    width: 76%; height: 76%;
    border: 3px solid rgba(255, 255, 255, 0.85);
    border-radius: 18px;
    box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.28);
    pointer-events: none;
}
.cam-paused {
    position: absolute;
    left: 0; top: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.7);
}
.cam-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.cam-tools .btn { flex: 1 1 0; min-width: 110px; font-size: 0.95rem; }
.cam-tools .btn[aria-pressed="true"] { background: var(--accent); color: #111; border-color: var(--accent); }

body.hw #btn-cam-start {
    min-height: 52px;
    font-size: 1rem;
    background: transparent;
    border-color: var(--line);
    color: var(--muted);
}

/* ------------------------------------------------------------------ last result card */

.ic { display: none; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.ic .fill { fill: currentColor; stroke-width: 1; }
[data-kind="idle"] > .last-icon > .ic-idle,
[data-kind="ok"] .ic-ok,
[data-kind="vip"] .ic-vip,
[data-kind="used"] .ic-used,
[data-kind="invalid"] .ic-invalid,
[data-kind="cancelled"] .ic-cancelled,
[data-kind="wrong"] .ic-wrong,
[data-kind="net"] .ic-net { display: block; }

.last {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding: 14px;
    min-height: 104px;
    border-radius: var(--radius);
    border: 2px solid var(--line);
    background: var(--surface);
}
body.hw .last { min-height: 190px; }
.last-icon { flex: 0 0 56px; width: 56px; height: 56px; color: var(--muted); }
.last-body { flex: 1 1 auto; min-width: 0; }
.last-title { font-size: 1.35rem; font-weight: 900; letter-spacing: 0.02em; }
.last-name { font-size: 1.2rem; font-weight: 700; overflow-wrap: anywhere; word-break: break-word; }
.last-sub { font-size: 0.95rem; color: var(--muted); overflow-wrap: anywhere; }
body.hw .last-title { font-size: 1.7rem; }
body.hw .last-name { font-size: 1.45rem; }

.last[data-kind="ok"] { background: #0c3a1f; border-color: #2fb866; }
.last[data-kind="ok"] .last-icon { color: #5fe39a; }
.last[data-kind="vip"] { background: #0a0a0f; border-color: var(--gold); }
.last[data-kind="vip"] .last-icon, .last[data-kind="vip"] .last-title { color: var(--gold-hi); }
.last[data-kind="used"], .last[data-kind="invalid"], .last[data-kind="cancelled"] { background: #3a0f18; border-color: #ff5a73; }
.last[data-kind="used"] .last-icon, .last[data-kind="invalid"] .last-icon, .last[data-kind="cancelled"] .last-icon { color: #ff8a9c; }
.last[data-kind="wrong"] { background: #3a2a08; border-color: var(--warn); }
.last[data-kind="wrong"] .last-icon { color: var(--warn); }
.last[data-kind="net"] { background: var(--net); border-style: dashed; border-color: #9fc0ea; }
.last[data-kind="net"] .last-icon { color: #cfe2f7; }
.last[data-kind="ok"] .last-sub, .last[data-kind="vip"] .last-sub, .last[data-kind="used"] .last-sub,
.last[data-kind="invalid"] .last-sub, .last[data-kind="cancelled"] .last-sub, .last[data-kind="wrong"] .last-sub,
.last[data-kind="net"] .last-sub { color: #e2e8f0; }

.btn-undo {
    flex: 0 0 auto;
    background: #fff;
    color: #111;
    border-color: #fff;
    min-height: 60px;
}

/* ------------------------------------------------------------------ tool bar, panels, search */

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-tool { flex: 1 1 0; min-width: 96px; font-size: 0.95rem; padding: 8px 6px; }
.btn-tool[aria-expanded="true"], .btn-tool[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.inline-form { margin-bottom: 14px; }
.inline-row { display: flex; gap: 8px; }
.inline-row input { flex: 1 1 auto; min-width: 0; }
.inline-row .btn { flex: 0 0 auto; }

.results { list-style: none; margin: 0; padding: 0; }
.results li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}
.res-main { flex: 1 1 auto; min-width: 0; }
.res-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.res-meta { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.res-state { font-size: 0.85rem; font-weight: 700; }
.res-state[data-status="valid"] { color: #5fe39a; }
.res-state[data-status="used"] { color: #ff8a9c; }
.res-state[data-status="cancelled"] { color: #ff8a9c; text-decoration: line-through; }
.results .btn { flex: 0 0 auto; }

.check { display: flex; align-items: center; gap: 12px; color: var(--text); margin-bottom: 14px; min-height: 48px; }
.check input { width: 26px; height: 26px; flex: 0 0 auto; }
.dev-info { margin: 12px 0 0; font-size: 0.8rem; color: #6f829c; overflow-wrap: anywhere; }
#btn-test-sound { width: 100%; }

/* ------------------------------------------------------------------ history */

.history { margin-top: 16px; }
.history h2 { margin: 0 0 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.history-empty { margin: 0; color: #6f829c; font-size: 0.9rem; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 7px 0;
    border-top: 1px solid #1c2c44;
    font-size: 0.92rem;
}
.h-time { flex: 0 0 auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.h-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-res { flex: 0 0 auto; font-weight: 700; font-size: 0.8rem; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); }
.h-res[data-kind="ok"] { color: #5fe39a; border-color: #2f9e64; }
.h-res[data-kind="vip"] { color: var(--gold-hi); border-color: var(--gold); }
.h-res[data-kind="used"], .h-res[data-kind="invalid"], .h-res[data-kind="cancelled"] { color: #ff8a9c; border-color: #ff5a73; }
.h-res[data-kind="wrong"] { color: var(--warn); border-color: var(--warn); }
.h-res[data-kind="net"] { color: #cfe2f7; border-style: dashed; }
.h-res[data-kind="undo"] { color: var(--muted); }

/* ------------------------------------------------------------------ keyboard wedge sink */

.wedge-sink {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: 0;
    border: 0;
    opacity: 0;
    font-size: 16px;
    color: transparent;
    background: transparent;
    caret-color: transparent;
    pointer-events: none;
    outline: none;
}

/* ------------------------------------------------------------------ full-screen result overlay */

.overlay {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
    color: #fff;
    background: var(--ok);
    cursor: pointer;
}
.ov-box { width: 100%; max-width: 900px; }
.ov-icon { width: 30vmin; height: 30vmin; max-width: 240px; max-height: 240px; min-width: 96px; min-height: 96px; margin: 0 auto 2vmin; }
.ov-icon .ic { stroke-width: 3; }
.ov-title { font-size: 11vmin; font-size: clamp(2.2rem, 11vmin, 6rem); font-weight: 900; line-height: 1.02; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.ov-main { margin-top: 2.5vmin; font-size: 7vmin; font-size: clamp(1.5rem, 7vmin, 3.6rem); font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; word-break: break-word; }
.ov-sub { margin-top: 2vmin; font-size: 4.6vmin; font-size: clamp(1.1rem, 4.6vmin, 2.2rem); font-weight: 600; overflow-wrap: anywhere; }
.ov-extra { margin-top: 1.5vmin; font-size: 3.6vmin; font-size: clamp(0.95rem, 3.6vmin, 1.6rem); opacity: 0.92; overflow-wrap: anywhere; }
.ov-main:empty, .ov-sub:empty, .ov-extra:empty { display: none; }

.overlay[data-kind="ok"] { background: var(--ok); }
.overlay[data-kind="vip"] {
    background: radial-gradient(circle at 50% 30%, #1d1a10 0, #06060a 70%);
    color: var(--gold-hi);
    box-shadow: inset 0 0 0 10px var(--gold);
}
.overlay[data-kind="vip"] .ov-title { font-family: Georgia, "Times New Roman", Times, serif; }
.overlay[data-kind="vip"] .ov-main { color: #fff; }
.overlay[data-kind="used"] {
    background: var(--bad);
    background-image: repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.22) 0, rgba(0, 0, 0, 0.22) 22px, transparent 22px, transparent 44px);
}
.overlay[data-kind="invalid"] { background: var(--bad); }
.overlay[data-kind="cancelled"] { background: var(--bad-dark); box-shadow: inset 0 0 0 10px #ff5a73; }
.overlay[data-kind="wrong"] { background: var(--warn); color: #111; }
.overlay[data-kind="net"] { background: var(--net); box-shadow: inset 0 0 0 8px #0b1522, inset 0 0 0 12px #9fc0ea; }
.overlay[data-kind="net"] .ov-title { font-size: 9vmin; font-size: clamp(1.9rem, 9vmin, 5rem); }

/* ------------------------------------------------------------------ dialog + toast */

.dialog {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.72);
}
.dialog-box {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}
.dialog-box h2 { margin: 0 0 8px; font-size: 1.3rem; }
.dialog-box p { margin: 0 0 14px; overflow-wrap: anywhere; }
.dialog-buttons { display: flex; gap: 10px; }
.dialog-buttons .btn { flex: 1 1 0; min-height: 60px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 70;
    max-width: 92vw;
    padding: 12px 18px;
    border-radius: 12px;
    background: #f1f5f9;
    color: #0b1522;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
body.in-app .toast { bottom: 74px; }

/* ------------------------------------------------------------------ small screens / landscape / motion */

@media (max-width: 359px) {
    .view { padding-left: 8px; padding-right: 8px; }
    .counter-num b { font-size: 2rem; }
    .btn-tool { min-width: 70px; font-size: 0.85rem; }
    .field-row { flex-direction: column; gap: 0; }
}

@media (orientation: landscape) and (max-height: 520px) {
    .cam-view { max-width: 260px; }
    .ov-icon { width: 20vmin; height: 20vmin; min-width: 56px; min-height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
    .bar-fill { transition: none; }
    .btn:active { transform: none; }
}
