:root {
    --ink: #0F172A;
    --ink-secondary: #334155;
    --muted: #64748B;
    --paper: #F8FAFC;
    --surface: #FFFFFF;
    --line: #E2E8F0;
    --line-focus: #94A3B8;

    --emerald: #059669;
    --emerald-dark: #047857;
    --emerald-bg: #ECFDF5;
    --emerald-border: #A7F3D0;

    --amber: #D97706;
    --amber-dark: #B45309;
    --amber-bg: #FFFBEB;
    --amber-border: #FDE68A;

    --red: #DC2626;
    --red-dark: #B91C1C;
    --red-bg: #FEF2F2;
    --red-border: #FECACA;

    --violet: #7C3AED;
    --violet-dark: #6D28D9;
    --violet-bg: #F5F3FF;
    --violet-border: #DDD6FE;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; padding: 0; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.gate-body {
    min-height: 100dvh;
    background-color: var(--paper);
    background-image: 
        radial-gradient(at 0% 0%, rgba(5, 150, 105, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(15, 23, 42, 0.03) 0px, transparent 50%);
    color: var(--ink);
}

.gate-shell {
    width: min(100%, 500px);
    min-height: 100dvh;
    margin: 0 auto;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.gate-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--emerald-dark);
    text-transform: uppercase;
}
.brand-badge small {
    background: var(--emerald-bg);
    border: 1px solid var(--emerald-border);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 10px;
}

h1 {
    margin: 4px 0 0;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--ink);
    line-height: 1.15;
}

.operator-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface);
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    width: fit-content;
}
.operator-badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--emerald);
}

.icon-button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    background: var(--surface);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.15s ease;
}
.icon-button:active {
    transform: scale(0.95);
    background: var(--paper);
}

/* ── Gate switch tab ────────────────────────────────────────────── */
.gate-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #E2E8F0;
}
.switch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border-radius: 10px;
    text-align: center;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 700;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.switch.active {
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert {
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}
.alert-success {
    color: var(--emerald-dark);
    background: var(--emerald-bg);
    border: 1px solid var(--emerald-border);
}
.alert-error {
    color: var(--red-dark);
    background: var(--red-bg);
    border: 1px solid var(--red-border);
}

/* ── Main Cards ──────────────────────────────────────────────────── */
.scan-card, .preview-card, .result-card, .login-card, .error-card {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.03);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Camera Scanner Visual ────────────────────────────────────────── */
.scan-visual {
    position: relative;
    overflow: hidden;
    min-height: 270px;
    border-radius: 16px;
    background: #090D14;
    display: grid;
    place-items: center;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}
.scan-visual video {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.scan-visual p {
    position: relative;
    z-index: 3;
    margin: 0;
    padding: 6px 14px;
    color: #F8FAFC;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.scan-frame {
    position: relative;
    z-index: 2;
    width: 62%;
    aspect-ratio: 1;
    border: 2.5px solid #34D399;
    border-radius: 18px;
    box-shadow: 0 0 0 9999px rgba(9, 13, 20, 0.45);
    overflow: hidden;
}
.scan-frame::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, #34D399, #10B981, transparent);
    box-shadow: 0 0 10px #34D399;
    animation: scanLine 2.2s ease-in-out infinite alternate;
}
@keyframes scanLine {
    0% { transform: translateY(0%); opacity: 0.3; }
    50% { opacity: 1; }
    100% { transform: translateY(220px); opacity: 0.3; }
}

.scan-actions {
    display: flex;
    gap: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.button, .decision {
    border: 0;
    border-radius: 14px;
    min-height: 48px;
    padding: 12px 16px;
    font-weight: 800;
    font-size: 0.92rem;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s ease, filter 0.15s ease;
}
.button:active, .decision:active {
    transform: scale(0.98);
}
.button-primary {
    color: #FFFFFF;
    background: var(--emerald);
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
    flex: 1;
}
.button-primary:hover {
    background: var(--emerald-dark);
}
.button-secondary {
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
}
.button-secondary:hover {
    background: #E2E8F0;
}
.button-wide {
    width: 100%;
    color: #FFFFFF;
    background: var(--ink);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
}
.button-wide:hover {
    background: #1E293B;
}
.hidden { display: none !important; }

/* ── Form Inputs ─────────────────────────────────────────────────── */
.token-field, .reason-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink-secondary);
}
textarea, input[type="text"], input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    background: var(--paper);
    font-size: 0.9rem;
    transition: all 0.15s ease;
}
textarea:focus, input:focus {
    outline: none;
    border-color: var(--emerald);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}
textarea { resize: vertical; min-height: 68px; }

/* ── Preview Card & Bento Snapshot ───────────────────────────────── */
.preview-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.preview-heading .eyebrow {
    font-size: 11px;
    font-weight: 800;
    color: var(--emerald);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 0;
}
.preview-heading h2 {
    margin: 3px 0 0;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.status-pill {
    padding: 5px 10px;
    border-radius: 999px;
    color: var(--emerald-dark);
    background: var(--emerald-bg);
    border: 1px solid var(--emerald-border);
    font-size: 0.74rem;
    font-weight: 800;
    white-space: nowrap;
}

/* Bento details */
.snapshot-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0;
}
.snapshot-box {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 9px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.snapshot-box.wide {
    grid-column: 1 / -1;
}
.snapshot-box.highlight {
    background: #F0FDF4;
    border-color: #BBF7D0;
}
dt {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
dd {
    margin: 0;
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}
dd.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    letter-spacing: -0.02em;
}

.expiry {
    margin: 0;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--amber-dark);
    background: var(--amber-bg);
    border: 1px solid var(--amber-border);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.expiry.expired {
    color: var(--red-dark);
    background: var(--red-bg);
    border-color: var(--red-border);
}

/* ── Decision Buttons Grid ───────────────────────────────────────── */
.decision-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}
.decision.allow {
    grid-column: 1 / -1;
    min-height: 52px;
    font-size: 1.05rem;
    color: #FFFFFF;
    background: var(--emerald);
    box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
}
.decision.allow:hover {
    background: var(--emerald-dark);
}
.decision.hold {
    color: var(--amber-dark);
    background: var(--amber-bg);
    border: 1px solid var(--amber-border);
}
.decision.reject {
    color: var(--red-dark);
    background: var(--red-bg);
    border: 1px solid var(--red-border);
}
.decision.exception {
    grid-column: 1 / -1;
    color: var(--violet-dark);
    background: var(--violet-bg);
    border: 1px solid var(--violet-border);
}

.link-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--paper);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    transition: all 0.15s ease;
}
.link-button:active {
    transform: scale(0.98);
    background: #E2E8F0;
}

/* ── Result Card ─────────────────────────────────────────────────── */
.result-card {
    text-align: center;
    padding: 24px 18px;
}
.result-card h2 {
    font-size: 1.5rem;
    margin: 4px 0 8px;
}
.result-card .button {
    margin-top: 14px;
    width: 100%;
}

@media (max-width: 380px) {
    .gate-shell { padding-inline: 12px; }
    .decision-grid, .snapshot-grid { gap: 6px; }
    .decision { font-size: 0.84rem; padding-inline: 10px; }
}

/* ── Login Screen Specifics ───────────────────────────────────────── */
.login-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.login-card {
    width: min(100%, 420px);
    margin: 0 auto;
    padding: 32px 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: 
        0 1px 3px rgba(15, 23, 42, 0.04),
        0 10px 25px -5px rgba(15, 23, 42, 0.08),
        0 20px 40px -15px rgba(15, 23, 42, 0.05);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--emerald-dark);
    text-transform: uppercase;
}
.login-brand-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--emerald);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}
.login-brand small {
    background: var(--emerald-bg);
    border: 1px solid var(--emerald-border);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 10px;
}

.login-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.login-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--ink);
    line-height: 1.2;
}
.login-header p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 4px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-label {
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-secondary);
}

.input-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.input-icon-wrap svg {
    position: absolute;
    left: 14px;
    color: var(--muted);
    pointer-events: none;
    transition: color 0.15s ease;
}
.input-icon-wrap input {
    padding-left: 42px;
    height: 48px;
    border-radius: 12px;
    border: 1.5px solid var(--line);
    background: var(--paper);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.15s ease;
}
.input-icon-wrap input:focus {
    background: #fff;
    border-color: var(--emerald);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}
.input-icon-wrap:focus-within svg {
    color: var(--emerald);
}

.login-submit {
    width: 100%;
    min-height: 48px;
    margin-top: 4px;
    border-radius: 14px;
    font-size: 0.96rem;
    font-weight: 800;
}

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: center;
}

