/* --- DESIGN SYSTEM & CSS VARIABLES --- */
:root {
    --bg-main: #0b0f19;
    --bg-surface: rgba(17, 24, 39, 0.7);
    --bg-surface-opaque: #111827;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-glow: rgba(99, 102, 241, 0.4);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary-color: #6366f1; /* Indigo */
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.5);
    
    --success-color: #10b981; /* Emerald */
    --success-glow: rgba(16, 185, 129, 0.4);
    
    --danger-color: #ef4444; /* Rose */
    --danger-hover: #dc2626;
    
    --plate-bg: #fdfdfd;
    --plate-text-color: #111111;
    --eu-blue: #003399;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-plate: 6px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* --- LAYOUT CONTAINER --- */
.app-container {
    width: 100%;
    max-width: 480px; /* Mobile width constraint on desktop */
    height: 100vh;
    height: 100dvh;
    background-color: #0d1321;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.1) 0px, transparent 50%);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

/* --- HEADER --- */
.app-header {
    padding: 16px 20px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 1.4rem;
    filter: drop-shadow(0 0 4px var(--primary-glow));
}

.app-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 40%, var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Status Indicator Dot */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.green {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-glow);
}

.status-dot.orange {
    background-color: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
    animation: pulse 1s infinite alternate;
}

.status-text {
    color: var(--text-secondary);
}

/* --- MAIN PANEL SCROLL AREA --- */
.app-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-bottom: 80px; /* Spacer for bottom nav */
}

.panel {
    display: none;
    opacity: 0;
    width: 100%;
    height: 100%;
    animation: fadeIn var(--transition-normal) forwards;
}

.panel.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
}

/* --- CAMERA & VIEWFINDER --- */
.camera-viewport-wrapper {
    width: 100%;
    aspect-ratio: 4/3;
    background-color: #020617;
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

#camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.viewfinder-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, transparent 45%, rgba(2, 6, 23, 0.7) 100%);
    pointer-events: none;
}

.viewfinder-box {
    width: 85%;
    aspect-ratio: 4.5/1; /* Mimics license plate proportion */
    position: relative;
    box-shadow: 0 0 0 9999px rgba(11, 15, 25, 0.4); /* Darkens region outside viewfinder */
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Glowing Corner Brackets */
.corner-border {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 3px solid var(--primary-color);
    box-shadow: 0 0 8px var(--primary-glow);
}

.corner-border.top-left {
    top: -3px;
    left: -3px;
    border-right: none;
    border-bottom: none;
}

.corner-border.top-right {
    top: -3px;
    right: -3px;
    border-left: none;
    border-bottom: none;
}

.corner-border.bottom-left {
    bottom: -3px;
    left: -3px;
    border-right: none;
    border-top: none;
}

.corner-border.bottom-right {
    bottom: -3px;
    right: -3px;
    border-left: none;
    border-top: none;
}

/* Animated Laser Line */
.laser-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--success-color), transparent);
    box-shadow: 0 0 8px var(--success-color);
    animation: laserScan 2s infinite ease-in-out;
}

.viewfinder-hint {
    position: absolute;
    bottom: -28px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Flash effect */
.flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.flash-overlay.flash-active {
    animation: cameraShutter 0.25s ease-out;
}

/* Spinner overlay while running OCR */
.scanner-loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 15, 25, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast) ease;
    z-index: 6;
}

.scanner-loader-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(99, 102, 241, 0.15);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
}

.loader-text {
    margin-top: 14px;
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* --- CONTROLS AREA --- */
.scanner-controls {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-row {
    width: 100%;
    display: flex;
    align-items: center;
}

.camera-selection-row {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    justify-content: space-between;
}

.select-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.custom-select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    text-align: right;
    max-width: 250px;
}

.custom-select option {
    background-color: var(--bg-surface-opaque);
    color: var(--text-primary);
}

/* Buttons */
.main-buttons {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

.btn-icon {
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-glow {
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:active {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:active {
    background: var(--danger-hover);
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
}

/* Real-time Debug Box */
.realtime-debug {
    background: rgba(0, 0, 0, 0.2);
    border: 1px dashed rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}

.debug-title {
    color: var(--text-muted);
}

.debug-value {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

/* --- RESULTS COMPONENT (PHYSICAL PLATE) --- */
.result-container {
    margin: 0 20px 20px 20px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: slideUp var(--transition-normal) cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.result-container.hidden {
    display: none;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-badge {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--success-color);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.btn-close:hover {
    color: var(--text-primary);
}

/* Embossed Plate Card */
.plate-card-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
}

.plate-card {
    background-color: var(--plate-bg);
    color: var(--plate-text-color);
    border: 4px solid #111;
    border-radius: var(--radius-plate);
    height: 70px;
    width: 100%;
    max-width: 380px;
    display: grid;
    grid-template-columns: 36px 1fr;
    position: relative;
    overflow: hidden;
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.2), 
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 -3px 3px rgba(0, 0, 0, 0.15);
    user-select: none;
}

/* EU Blue Stripe */
.eu-strip {
    background-color: var(--eu-blue);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    color: white;
    font-family: var(--font-sans);
}

.eu-stars {
    font-size: 0.35rem;
    line-height: 1.2;
    text-align: center;
    color: #ffd700;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 18px;
}

.country-code {
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}

/* Embossed Plate Text */
.plate-text {
    font-family: var(--font-mono);
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    text-shadow: 
        1px 1px 0px #fff,
        2px 2px 2px rgba(0,0,0,0.35);
    padding-left: 10px;
}

/* Result Actions & Megjegyzés */
.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.btn-action {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.btn-action:active {
    background: rgba(255, 255, 255, 0.08);
}

.note-input-container {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    animation: fadeIn var(--transition-fast) forwards;
}

.note-input-container.hidden {
    display: none;
}

.note-input-container input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
}

.note-input-container input:focus {
    border-color: var(--primary-color);
}

/* --- HISTORY PANEL STYLES --- */
#history-panel {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.history-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.history-header-actions h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.history-buttons {
    display: flex;
    gap: 8px;
}

.history-list-wrapper {
    flex: 1;
    overflow-y: auto;
}

/* Empty State */
.empty-history-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 0;
    text-align: center;
}

.empty-history-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
}

.empty-history-state p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.empty-history-state .empty-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* History List Items */
.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideUp var(--transition-normal);
}

.history-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Small mock plate for history row */
.history-plate-preview {
    background-color: var(--plate-bg);
    color: var(--plate-text-color);
    border: 2px solid #222;
    border-radius: 3px;
    height: 34px;
    width: 140px;
    display: grid;
    grid-template-columns: 16px 1fr;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.history-plate-preview .eu-strip {
    background-color: var(--eu-blue);
    padding: 2px 0;
    grid-column: 1;
}

.history-plate-preview .eu-stars {
    font-size: 0.15rem;
    width: 8px;
    grid-template-columns: repeat(3, 1fr);
}

.history-plate-preview .country-code {
    font-size: 0.45rem;
    font-weight: 800;
}

.history-plate-preview .plate-text {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding-left: 2px;
    text-shadow: none;
}

.history-item-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.history-item-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--success-color);
}

.history-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    padding-top: 8px;
    margin-top: 2px;
}

.history-item-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
}

.history-item-note-empty {
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.btn-history-action {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition-fast);
}

.btn-history-action:hover {
    color: var(--text-primary);
}

.btn-history-action.btn-delete:hover {
    color: var(--danger-color);
}

/* --- BOTTOM TAB NAVIGATION --- */
.app-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 1fr 1fr;
    z-index: 10;
}

.nav-tab {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-tab.active {
    color: var(--primary-color);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    top: 0;
    width: 40px;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 10px var(--primary-glow);
}

.nav-icon {
    font-size: 1.25rem;
}

.nav-text {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* --- KEYFRAME ANIMATIONS --- */
@keyframes laserScan {
    0% {
        top: 0%;
        opacity: 0.3;
    }
    50% {
        top: 100%;
        opacity: 1;
    }
    100% {
        top: 0%;
        opacity: 0.3;
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes cameraShutter {
    0% { opacity: 0; }
    30% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes pulse {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
