/* =========================================
   VARIABLES & THEMES
   ========================================= */
:root {
    --bg-main: #f8fafc;
    --glass-bg: 255, 255, 255;
    --glass-border: 226, 232, 240;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --plate-bg: #F4C430;
    --plate-text: #000000;
    --pass: #16a34a; --pass-bg: #dcfce7;
    --fail: #ef4444; --fail-bg: #fee2e2; --fail-bar: rgba(239, 68, 68, 0.15);
    --warning: #eab308; --warning-bg: #fef08a; --warning-bar: rgba(234, 179, 8, 0.15);
    --info: #0ea5e9; --info-bg: #e0f2fe;
    --success: #10b981; --success-bg: #d1fae5;
    --shadow: 0 10px 25px -5px rgba(0,0,0,0.05);
    --bg-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2364748b' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

[data-theme="dark"] {
    --bg-main: #0b1120;
    --glass-bg: 30, 41, 59;
    --glass-border: 51, 65, 85;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --pass: #4ade80; --pass-bg: rgba(74, 222, 128, 0.15);
    --fail: #f87171; --fail-bg: rgba(248, 113, 113, 0.15); --fail-bar: rgba(248, 113, 113, 0.15);
    --warning: #facc15; --warning-bg: rgba(250, 204, 21, 0.15); --warning-bar: rgba(250, 204, 21, 0.15);
    --info: #38bdf8; --info-bg: rgba(56, 189, 248, 0.15);
    --success: #34d399; --success-bg: rgba(52, 211, 153, 0.15);
    --shadow: 0 20px 25px -5px rgba(0,0,0,0.5);
    --bg-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2394a3b8' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* =========================================
   BASE STYLES
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: 'Inter', system-ui, sans-serif; 
    background-color: var(--bg-main); 
    color: var(--text-main); 
    line-height: 1.5; 
    background-image: var(--bg-pattern); 
    transition: background-color 0.3s, color 0.3s; 
    padding-bottom: 4rem;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.03em; color: var(--text-main); }
a { text-decoration: none; color: inherit; }

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.animate-up { animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards; opacity: 0; }
.delay-1 { animation-delay: 0.1s; } 
.delay-2 { animation-delay: 0.2s; } 
.delay-3 { animation-delay: 0.3s; }

/* =========================================
   GLASSMORPHISM & LAYOUT
   ========================================= */
.glass-panel { 
    background: rgba(var(--glass-bg), 0.7); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px); 
    border: 1px solid rgba(var(--glass-border), 1); 
    box-shadow: var(--shadow); 
    border-radius: 20px; 
    padding: 2rem;
    margin-bottom: 1.5rem;
}

.bento-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.5rem; }
.bento-card { display: flex; flex-direction: column; justify-content: center; }
.col-span-4 { grid-column: span 4; }
.col-span-6 { grid-column: span 6; }
.col-span-8 { grid-column: span 8; }
.col-span-12 { grid-column: span 12; }

/* =========================================
   HEADER & NAV
   ========================================= */
.global-header { 
    position: sticky; top: 0; z-index: 100; 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 1rem 2rem; border-radius: 0 0 20px 20px; 
    border-top: none; margin-bottom: 3rem;
}
.navbar-brand { font-size: 1.25rem; display: flex; align-items: center; gap: 0.75rem; font-weight: 800;}
.nav-menu { display: flex; gap: 2rem; list-style: none; align-items: center; margin: 0;}
.nav-item a { font-weight: 600; font-size: 0.95rem; color: var(--text-muted); transition: 0.2s; }
.nav-item a:hover { color: var(--text-main); }
.header-controls { display: flex; align-items: center; gap: 1.5rem; }
.theme-toggle { 
    background: rgba(var(--glass-border), 0.3); border: 1px solid rgba(var(--glass-border), 0.5); 
    cursor: pointer; color: var(--text-main); padding: 0.5rem; border-radius: 10px; 
    display: flex; align-items: center; transition: 0.2s; 
}
.theme-toggle:hover { background: rgba(var(--glass-border), 0.6); }

.header-search { text-align: center; padding: 3rem 1rem 3rem; }
.header-search h1 { font-size: 3rem; margin-bottom: 1rem; }
.header-search p { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 3rem; max-width: 600px; margin-inline: auto;}
.header-text h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.header-text p { color: var(--text-muted); font-size: 1.1rem; }

/* =========================================
   FORM & PLATES
   ========================================= */
.uk-plate-container {
    display: flex; background: var(--plate-bg); border-radius: 8px; border: 4px solid #000;
    max-width: 400px; width: 100%; margin: 0 auto 1.5rem; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}
.uk-plate-blue-strip {
    background: #003399; color: white; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 0.5rem; width: 55px; font-weight: bold;
}
.uk-plate-container input {
    background: transparent; border: none; color: var(--plate-text); font-family: monospace; 
    font-size: 3.5rem; font-weight: bold; text-align: center; text-transform: uppercase;
    width: 100%; padding: 0.5rem; outline: none; letter-spacing: 2px;
}
.uk-plate-container input::placeholder { color: rgba(0,0,0,0.15); }

.submit-btn {
    background: var(--primary); color: white; border: none; padding: 1rem 2.5rem; 
    font-size: 1.1rem; border-radius: 999px; cursor: pointer; font-weight: 600;
    display: flex; align-items: center; gap: 0.75rem; transition: transform 0.2s, background 0.2s; margin: 0 auto;
}
.submit-btn:hover { background: var(--primary-hover); transform: translateY(-2px); }

/* =========================================
   FULL SCREEN LOADING OVERLAY
   ========================================= */
#loading {
    display: none; /* Toggled to 'flex' by JavaScript */
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 17, 32, 0.85); /* Deep dark overlay */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#loading h3 {
    color: #fff;
    margin-top: 1rem;
    font-size: 1.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* =========================================
   DASHBOARD COMPONENTS
   ========================================= */
.summary-dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.summary-card { padding: 2rem; display: flex; flex-direction: column; gap: 0.5rem;}
.summary-card .icon-wrapper { padding: 0.75rem; border-radius: 12px; display: inline-flex; width: fit-content; margin-bottom: 0.5rem; }
.summary-card h4 { font-size: 0.875rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px;}
.summary-card h2 { font-size: 2.5rem; margin: 0; line-height: 1;}

.status-valid .icon-wrapper { background: var(--pass-bg); color: var(--pass); }
.status-valid h2 { color: var(--pass); }
.status-expired .icon-wrapper { background: var(--fail-bg); color: var(--fail); }
.status-expired h2 { color: var(--fail); }

.stat-icon { padding: 1.25rem; border-radius: 16px; display: inline-flex; margin-bottom: 1rem; }
.stat-value { font-size: 2.75rem; font-weight: 800; line-height: 1; margin-bottom: 0.5rem; letter-spacing: -0.03em;}
.stat-label { color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }

.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1.5rem; }
.data-item { display: flex; flex-direction: column; gap: 4px; padding: 1rem; background: rgba(var(--glass-border), 0.2); border-radius: 8px;}
.data-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;}
.data-value { font-size: 1.1rem; font-weight: 500; }

/* =========================================
   MOT HISTORY & DEFECTS
   ========================================= */
.mot-test { border-bottom: 1px solid rgba(var(--glass-border), 0.5); padding: 2rem 0; }
.mot-test:last-child { border-bottom: none; }
.status-badge { padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; display: inline-flex; align-items: center; gap: 0.25rem;}
.status-badge.pass { background: var(--pass-bg); color: var(--pass); }
.status-badge.fail { background: var(--fail-bg); color: var(--fail); }

.defects-accordion { margin-top: 1.5rem; background: rgba(var(--glass-border), 0.15); border-radius: 12px; }
.defects-accordion summary { cursor: pointer; font-weight: 600; padding: 1.25rem; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.defects-accordion summary::-webkit-details-marker { display: none; }
.defects-accordion ul { padding: 0 1.5rem 1.5rem 1.5rem; margin: 0; color: var(--text-muted); font-size: 0.95rem; list-style: none;}
.defects-accordion li { padding: 0.75rem; border-radius: 8px; margin-bottom: 0.5rem; background: var(--bg-main); display: flex; gap: 0.75rem; align-items: flex-start;}

.category-header { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; margin: 1rem 0 0.5rem 1.5rem; font-weight: 700; }
.category-fail { color: var(--fail); }
.category-adv { color: var(--warning); }

.badge-type { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; flex-shrink: 0;}
.badge-fail { background: var(--fail-bg); color: var(--fail); }
.badge-adv { background: var(--warning-bg); color: var(--warning); }

/* =========================================
   ANALYTICS FAULT LISTS
   ========================================= */
.fault-list { list-style: none; display: flex; flex-direction: column; gap: 0.75rem;}
.fault-item {
    position: relative; z-index: 1; padding: 1.25rem; border-radius: 12px;
    display: flex; align-items: center; gap: 1.25rem; overflow: hidden;
    background: rgba(var(--glass-border), 0.1); border: 1px solid rgba(var(--glass-border), 0.3);
}
.fault-bar { position: absolute; top: 0; left: 0; height: 100%; z-index: -1; border-radius: 12px; transition: width 1s ease-out; width: 0%;}
.fault-bar.fail { background: var(--fail-bar); }
.fault-bar.adv { background: var(--warning-bar); }

.fault-rank-circle { 
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; font-weight: 900; flex-shrink: 0;
    background: rgba(var(--glass-border), 0.3); color: var(--text-main);
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.1), 0 2px 4px rgba(0,0,0,0.1);
}
.rank-1 { background: rgba(var(--glass-border), 0.8); }
.rank-2 { background: rgba(var(--glass-border), 0.6); }
.rank-3 { background: rgba(var(--glass-border), 0.4); }

.fault-content { flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 1rem;}
.fault-text { font-size: 0.95rem; font-weight: 500; color: var(--text-main); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;}
.fault-count { font-size: 1.1rem; font-weight: 700; background: rgba(var(--glass-bg), 0.8); padding: 0.25rem 0.75rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); flex-shrink: 0;}

/* =========================================
   UTILITIES
   ========================================= */
.alert-box { background: var(--fail-bg); color: var(--fail); padding: 1rem; border-radius: 12px; margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.75rem; border: 1px solid rgba(var(--fail), 0.2);}
.cache-indicator { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; background: var(--info-bg); color: var(--info); border-radius: 12px; margin-bottom: 1.5rem; font-size: 0.9rem; font-weight: 500;}
.cache-indicator form { margin: 0; }
.cache-indicator button { background: none; border: none; color: var(--info); text-decoration: underline; cursor: pointer; font-weight: 600; }
.empty-state { text-align: center; padding: 3rem 1rem; opacity: 0.7; }
.empty-state svg { width: 120px; height: 120px; color: var(--text-muted); margin-bottom: 1rem; }
.chart-container { height: 320px; width: 100%; }

#loading { display: none; text-align: center; padding: 4rem; }
.spinner { animation: spin 1s linear infinite; color: var(--primary); margin-bottom: 1rem; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* =========================================
   MOBILE RESPONSIVENESS
   ========================================= */
@media (max-width: 1024px) {
    .col-span-4 { grid-column: span 6; }
    .col-span-8 { grid-column: span 12; }
}

@media (max-width: 768px) {
    .container { padding: 0 1rem; }
    .col-span-4, .col-span-6, .col-span-8, .col-span-12 { grid-column: span 12; }
    .nav-menu { display: none; }
    
    .glass-panel { padding: 1.25rem; border-radius: 16px; }
    .global-header { padding: 1rem; margin-bottom: 2rem; border-radius: 0 0 16px 16px; }
    .bento-grid { gap: 1rem; }
    
    .stat-card { padding: 1.25rem; flex-direction: row; gap: 1.25rem; align-items: center; }
    .stat-icon { padding: 1rem; margin-bottom: 0; }
    .stat-icon svg { width: 24px; height: 24px; }
    .stat-value { font-size: 2rem; margin-bottom: 0; }
    .stat-label { font-size: 0.75rem; }
    
    .header-text h1, .header-search h1 { font-size: 2rem !important; }
    .header-text p, .header-search p { font-size: 1rem !important; }
    
    .fault-item { padding: 1rem; gap: 0.75rem; }
    .fault-rank-circle { width: 30px; height: 30px; font-size: 0.95rem; }
    .fault-text { font-size: 0.85rem; -webkit-line-clamp: 3; }
    .fault-count { font-size: 0.95rem; padding: 0.2rem 0.6rem; }
    
    .chart-container { height: 240px; }
}

@media (max-width: 480px) {
    .fault-content { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .fault-count { align-self: flex-start; font-size: 0.85rem; }
    .stat-card { flex-direction: column; align-items: flex-start; text-align: left; gap: 0.75rem; }
    .navbar-brand { font-size: 1.1rem; }
    .cache-indicator { flex-direction: column; gap: 1rem; text-align: center; }
}