/* =========================
   CSS RESET & VARIABLES
========================= */
:root {
    --bg: #f4f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #dc2626;
    --accent-2: #f59e0b;
    --accent-gradient: linear-gradient(135deg, #ef4444 0%, #ff8800 100%);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: #e2e8f0;
}

body.dark-mode, html.dark-mode, :root[data-theme="dark"] {
    --bg: #080a0f;
    --card: #10141e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #ef4444;
    --accent-2: #fbbf24;
    --accent-gradient: linear-gradient(135deg, #ef4444 0%, #ff8800 100%);
    --border: rgba(239, 68, 68, 0.25);
}

body.light-mode, html.light-mode {
    --bg: #f4f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #dc2626;
    --accent-2: #f59e0b;
    --accent-gradient: linear-gradient(135deg, #ef4444 0%, #ff8800 100%);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: #e2e8f0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    min-height: 100vh;
}

/* =========================
   LAYOUT
========================= */
.container {
    display: flex;
    justify-content: center;
    padding: 16px;
}

.card {
    width: 100%;
    max-width: 440px;
    background: var(--card);
    border-radius: 24px;
    padding: 1.5rem;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, .2),
        inset 0 1px 1px rgba(255, 255, 255, .1);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

h2 {
    text-align: center;
    margin-bottom: 12px;
}

.subtitle {
    text-align: center;
    color: var(--muted);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

/* =========================
   OPTIONS GRID (FORM)
========================= */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 1.25rem;
    padding: 12px;
    background: rgba(0, 0, 0, .03);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.options-grid.triple {
    grid-template-columns: 1fr 1fr 1fr;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: span 2;
}

.form-group label {
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-group select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

@media (max-width: 400px) {
    .options-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }
}


/* Dark mode: apply when .dark-mode is on html element (scanner website toggle) */
html.dark-mode .options-grid {
    background: rgba(255, 255, 255, .03);
}

/* =========================
   BUTTONS
========================= */
.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.btn-group.vertical {
    flex-direction: column;
}

button {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* =========================
   CAMERA AREA
========================= */
#reader-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: black;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

#reader {
    width: 100%;
    height: 100%;
}

/* Viewfinder overlays */
.viewfinder {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.viewfinder.qr::before {
    content: "";
    width: 65%;
    height: 65%;
    border: 3px dashed var(--success);
    border-radius: 12px;
}

.viewfinder.barcode::before {
    content: "";
    width: 80%;
    height: 35%;
    border: 3px solid var(--accent);
    border-radius: 8px;
}

/* =========================
   STATUS
========================= */
#status-pill {
    margin: 12px 0;
    padding: 10px 16px;
    text-align: center;
    border-radius: 12px;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.05);
    color: var(--muted);
    font-size: 0.85rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}


html.dark-mode #status-pill {
    background: rgba(255, 255, 255, 0.05);
}

/* =========================
   MANUAL INPUT
========================= */
.manual-scan {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.manual-scan input {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
}

/* =========================
   HISTORY
========================= */
.history {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
}

.history h3 {
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 800;
}

.history ul {
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
}

.history li {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.02);
    margin-bottom: 6px;
    font-size: .85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--accent);
    transition: transform 0.2s ease;
}


html.dark-mode .history li {
    background: rgba(255, 255, 255, 0.02);
}

.history li.placeholder {
    color: var(--muted);
    text-align: center;
    display: block;
    border: none;
    background: none;
}

/* =========================
   FLASH OVERLAY
========================= */
#flash {
    position: fixed;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

#flash.active {
    opacity: 1;
}