/* ============================================================ */
/* Reset & Basics                                                 */
/* ============================================================ */

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: #111;
    color: #f5f5f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 17px;
    line-height: 1.4;
    /* iOS Safari: kein Bounce-Scrolling, App-Feel */
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

button, input {
    font: inherit;
    color: inherit;
}

.muted { color: #aaa; }
.error-text { color: #ff8888; margin-top: 1rem; }

[hidden] { display: none !important; }

/* ============================================================ */
/* Screen base                                                    */
/* ============================================================ */

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    /* iOS safe area */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ============================================================ */
/* Setup-Screen                                                   */
/* ============================================================ */

#screen-setup {
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    background: #111;
}

.setup-card {
    width: 100%;
    max-width: 420px;
    background: #1c1c1c;
    border-radius: 14px;
    padding: 2rem 1.5rem;
}

.setup-card h1 {
    margin: 0 0 0.75rem 0;
    font-size: 1.6rem;
}

.label {
    display: block;
    margin: 1.5rem 0 0.5rem 0;
    font-weight: 600;
    color: #ccc;
}

#token-input {
    width: 100%;
    padding: 0.85rem 1rem;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 1rem;
}

#token-input:focus {
    outline: 2px solid #4a9eff;
    outline-offset: 2px;
}

.primary-btn {
    display: block;
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem;
    background: #4a9eff;
    color: #fff;
    border: 0;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
}

.primary-btn:active {
    background: #3a7fcf;
}

/* ============================================================ */
/* Scan-Screen                                                    */
/* ============================================================ */

#screen-scan {
    background: #000;
    overflow: hidden;
}

.scan-stage {
    position: relative;
    flex: 1;
    width: 100%;
    overflow: hidden;
}

#camera-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.viewfinder {
    position: absolute;
    /* Hochkant: Sucher quadratisch, mittig, ca. 70% der Display-Breite */
    top: 50%;
    left: 50%;
    width: 70vmin;
    height: 70vmin;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.viewfinder-corner {
    position: absolute;
    width: 32px;
    height: 32px;
    border-color: rgba(255, 255, 255, 0.85);
    border-style: solid;
    border-width: 0;
}
.viewfinder-corner.tl { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 6px; }
.viewfinder-corner.tr { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 6px; }
.viewfinder-corner.bl { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 6px; }
.viewfinder-corner.br { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 6px; }

.scan-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
    pointer-events: auto;
}

.clock {
    font-variant-numeric: tabular-nums;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.reset-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 0.4rem 0.9rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.scan-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.25rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    text-align: center;
    background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
    color: rgba(255,255,255,0.85);
    font-size: 1rem;
}

/* ============================================================ */
/* Status-Card                                                    */
/* ============================================================ */

.status-card {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    z-index: 10;
    /* Hintergrundfarbe via data-color Attribut */
    background: #444;
    color: #fff;
    /* Sanftes Reinrutschen */
    animation: status-in 0.18s ease-out;
}

@keyframes status-in {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 1; transform: scale(1); }
}

.status-card[data-color="green"]  { background: #1f7a3a; }
.status-card[data-color="amber"]  { background: #c47a00; }
.status-card[data-color="red"]    { background: #b03030; }
.status-card[data-color="grey"]   { background: #555; }

.status-card-inner {
    text-align: center;
    max-width: 100%;
}

.status-card h2 {
    margin: 0 0 1rem 0;
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.1;
}

.status-name {
    margin: 0 0 1.25rem 0;
    font-size: 1.6rem;
    font-weight: 600;
}

.status-reason {
    margin: 0;
    font-size: 1.1rem;
    opacity: 0.92;
    line-height: 1.35;
}

/* ============================================================ */
/* Error-Screen                                                   */
/* ============================================================ */

#screen-error {
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    background: #111;
}

.error-card {
    width: 100%;
    max-width: 420px;
    background: #1c1c1c;
    border-radius: 14px;
    padding: 2rem 1.5rem;
    text-align: center;
}

.error-card h1 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
}

#error-detail {
    margin-bottom: 1.5rem;
}
