:root {
    --bg-primary: #090d16;
    --bg-surface: rgba(18, 24, 38, 0.85);
    --bg-surface-elevated: rgba(28, 36, 56, 0.95);
    --color-primary: #10b981;
    --color-primary-glow: rgba(16, 185, 129, 0.4);
    --color-success: #10b981;
    --color-success-glow: rgba(16, 185, 129, 0.35);
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    --color-text: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-border: rgba(255, 255, 255, 0.12);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-full: 9999px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100dvh;
    background-color: var(--bg-primary);
    font-family: var(--font-family);
    color: var(--color-text);
    overflow: hidden;
    position: fixed;
}

/* Scanner Layout & Viewport */
.scanner-container {
    position: relative;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #000;
}

#preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* Overlay & Viewfinder */
.scanner-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: radial-gradient(circle, transparent 40%, rgba(0, 0, 0, 0.65) 75%);
}

.viewfinder {
    position: relative;
    width: min(72vw, 280px);
    height: min(72vw, 280px);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    transition: box-shadow 0.25s ease;
}

.viewfinder-corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border: 3.5px solid #10b981;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
    z-index: 4;
    transition: all 0.2s ease;
}

.corner-tl { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: var(--radius-md); }
.corner-tr { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: var(--radius-md); }
.corner-bl { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: var(--radius-md); }
.corner-br { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: var(--radius-md); }

.viewfinder.scan-success .viewfinder-corner {
    border-color: #10b981;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.8);
}
.viewfinder.scan-success {
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.45), 0 0 30px rgba(16, 185, 129, 0.5);
}

.laser-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #10b981, #34d399, #10b981, transparent);
    box-shadow: 0 0 14px 3px rgba(16, 185, 129, 0.85);
    animation: scanLaser 2.2s ease-in-out infinite alternate;
    z-index: 3;
}

@keyframes scanLaser {
    0% { top: 8%; opacity: 0.8; }
    50% { opacity: 1; }
    100% { top: 92%; opacity: 0.8; }
}

/* Header & Status Bar */
.scanner-header {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--color-border);
    padding: 6px 14px;
    border-radius: var(--radius-full);
}

.brand-dot {
    width: 8px;
    height: 8px;
    background-color: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--color-success-glow);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

.brand-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--color-text);
}

.status-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-text-muted);
    font-weight: 500;
}

.scan-hint {
    margin-top: 18px;
    font-size: 13px;
    font-weight: 500;
    color: #e2e8f0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

/* Controls */
.scanner-controls {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0) 100%);
}

.ctrl-btn {
    min-width: 52px;
    min-height: 52px;
    border-radius: 50%;
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ctrl-btn:active {
    transform: scale(0.92);
    background: var(--bg-surface-elevated);
}

.ctrl-btn.active {
    background: #f59e0b;
    border-color: #fbbf24;
    color: #000;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.5);
}

.ctrl-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* SweetAlert2 Modal & Scanned Code Box */
.custom-swal-popup {
    background: rgba(15, 23, 42, 0.96) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 24px !important;
    padding: 24px 20px 20px !important;
    width: min(90vw, 360px) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6) !important;
    color: #f8fafc !important;
}

.custom-swal-success-only {
    background: rgba(15, 23, 42, 0.88) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(16, 185, 129, 0.35) !important;
    border-radius: 28px !important;
    padding: 16px 24px !important;
    width: auto !important;
    min-width: 130px !important;
    max-width: 180px !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
}

.custom-swal-success-only .swal2-icon {
    margin: 8px auto !important;
}

.custom-swal-title {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #f8fafc !important;
    margin-top: 12px !important;
    margin-bottom: 6px !important;
}

.custom-swal-html {
    font-size: 14px !important;
    line-height: 1.5 !important;
    color: #94a3b8 !important;
    margin-top: 6px !important;
}

.custom-swal-btn {
    border-radius: 12px !important;
    padding: 12px 24px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    background: #10b981 !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35) !important;
    border: none !important;
    cursor: pointer !important;
    min-height: 44px !important;
}

.scanned-code-box {
    margin-top: 14px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    text-align: left;
}

.code-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #10b981;
    margin-bottom: 6px;
}

.code-content {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    color: #e2e8f0;
    word-break: break-all;
    max-height: 80px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.04);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    user-select: all;
    -webkit-user-select: all;
}

.code-details {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    color: var(--color-text-muted);
}

.code-details strong {
    color: #10b981;
}
