/* ============================================
   PAD Detection v3.0 - Port Autonome de Douala
   Interface professionnelle haute précision

   Palette:
   - Bleu marine:  #003366
   - Bleu PAD:     #0066aa
   - Cyan:         #00a8e8
   - Or:           #d4a843
   - Fond:         #0a1018 → #111b2b
   ============================================ */

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

:root {
    --pad-navy: #003366;
    --pad-blue: #0066aa;
    --pad-cyan: #00a8e8;
    --pad-gold: #d4a843;
    --pad-light: #e8f0f8;

    --bg: #0a1018;
    --bg-card: #0f1923;
    --bg-card-hover: #152030;
    --text: #e8ecf2;
    --text-muted: #6a7f98;
    --danger: #ff4757;
    --success: #2ed573;
    --warning: #ffa502;
    --border: #1a2a40;
    --radius: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 100vw;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

/* ========== HEADER ========== */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--pad-navy), #001d3d);
    border-bottom: 1px solid var(--pad-blue);
    z-index: 10;
}

#brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

#logo {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
    padding: 2px;
    box-shadow: 0 2px 8px rgba(0,102,170,0.3);
}

#brand h1 {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
    letter-spacing: 0.5px;
}

#brand h1 .accent {
    color: var(--pad-cyan);
    font-weight: 600;
}

.tagline {
    font-size: 0.55rem;
    color: var(--pad-light);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    font-weight: 400;
    opacity: 0.6;
}

#stats-bar {
    display: flex;
    gap: 5px;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--success);
}

.timer-pill {
    color: var(--pad-cyan);
}

.stat-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ========== QUICK STATS ========== */
#quick-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}

.quick-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    background: var(--bg-card);
    gap: 2px;
}

.qs-value {
    font-size: 1.2rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #fff;
    line-height: 1;
}

.qs-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

#qs-total .qs-value { color: var(--pad-cyan); }
#qs-vehicles .qs-value { color: #1e90ff; }
#qs-persons .qs-value { color: #ff4757; }
#qs-perf .qs-value { color: var(--pad-gold); font-size: 0.9rem; }

/* ========== VIDEO ========== */
#video-container {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 280px;
    background: #000;
    overflow: hidden;
}

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

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Scan line */
#scan-line {
    position: absolute;
    top: 0;
    left: 5%;
    width: 90%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--pad-cyan) 20%, var(--pad-cyan) 80%, transparent);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
    box-shadow: 0 0 12px var(--pad-cyan), 0 0 4px var(--pad-cyan);
}

#scan-line.active {
    opacity: 0.6;
    animation: scanDown 4s ease-in-out infinite;
}

@keyframes scanDown {
    0% { top: 0; }
    50% { top: 100%; }
    100% { top: 0; }
}

/* Loading overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, rgba(0,40,80,0.97), rgba(10,16,24,0.98));
    z-index: 5;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-logo {
    width: 68px;
    height: 68px;
    margin-bottom: 20px;
    border-radius: 14px;
    background: #fff;
    padding: 6px;
    box-shadow: 0 8px 32px rgba(0,102,170,0.4);
    animation: logoPulse 2.5s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(0,102,170,0.3); }
    50% { transform: scale(1.04); box-shadow: 0 12px 44px rgba(0,168,232,0.4); }
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--pad-cyan);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-bottom: 14px;
}

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

#loading-text {
    font-size: 0.88rem;
    color: #fff;
    font-weight: 500;
}

.loading-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 6px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* ========== DETECTIONS PANEL ========== */
#detections-panel {
    padding: 10px 14px;
    overflow-y: auto;
    max-height: 150px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

#detections-panel h3 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.badge {
    font-size: 0.58rem;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--pad-blue);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge.mode-yolo {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.badge.mode-demo {
    background: linear-gradient(135deg, var(--pad-blue), #2980b9);
}

#detections-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detection-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 10px;
    background: var(--bg);
    border-radius: 8px;
    border-left: 3px solid var(--pad-cyan);
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.det-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.det-icon {
    font-size: 0.9rem;
}

.det-label {
    font-weight: 600;
    font-size: 0.82rem;
}

.det-count {
    font-size: 0.7rem;
    background: var(--pad-navy);
    color: var(--pad-cyan);
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 700;
}

.det-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.det-conf-bar {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
}

.det-conf-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.det-conf-text {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    min-width: 30px;
    text-align: right;
}

.no-detection {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 8px;
    opacity: 0.6;
}

/* Couleurs par classe */
.detection-item[data-class="person"]        { border-left-color: #ff4757; }
.detection-item[data-class="car"]           { border-left-color: #1e90ff; }
.detection-item[data-class="truck"]         { border-left-color: #2980b9; }
.detection-item[data-class="bus"]           { border-left-color: #ffa502; }
.detection-item[data-class="motorcycle"]    { border-left-color: #ff6348; }
.detection-item[data-class="bicycle"]       { border-left-color: #a55eea; }
.detection-item[data-class="traffic light"] { border-left-color: #2ed573; }
.detection-item[data-class="stop sign"]     { border-left-color: #ff3838; }
.detection-item[data-class="boat"]          { border-left-color: #00d2d3; }
.detection-item[data-class="train"]         { border-left-color: #5f27cd; }

/* ========== CONTROLS ========== */
#controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    align-items: center;
}

.btn {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card-hover);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.94); }
.btn svg { flex-shrink: 0; }

.btn-primary {
    background: linear-gradient(135deg, var(--pad-blue), var(--pad-navy));
    border-color: rgba(0,168,232,0.3);
    color: #fff;
    box-shadow: 0 2px 12px rgba(0,102,170,0.2);
}

.btn-primary:active { background: var(--pad-cyan); }

.btn-active {
    background: linear-gradient(135deg, #c0392b, var(--danger));
    border-color: rgba(255,71,87,0.3);
    color: #fff;
    box-shadow: 0 2px 12px rgba(231,76,60,0.2);
}

.slider-group {
    flex: 1;
    min-width: 120px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--pad-cyan);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0,168,232,0.4);
    border: 2px solid #fff;
}

/* ========== DEMO BANNER ========== */
#demo-banner {
    padding: 5px 14px;
    background: var(--pad-navy);
    text-align: center;
    font-size: 0.68rem;
    color: var(--pad-gold);
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* ========== FOOTER ========== */
#footer {
    padding: 12px 14px;
    text-align: center;
    background: linear-gradient(135deg, var(--pad-navy), #001020);
    border-top: 1px solid rgba(0,102,170,0.3);
}

.footer-logo {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: #fff;
    padding: 2px;
    margin-bottom: 4px;
    opacity: 0.7;
}

#footer p {
    font-size: 0.65rem;
    color: var(--pad-light);
    letter-spacing: 0.5px;
    font-weight: 500;
    opacity: 0.7;
}

.footer-sub {
    font-size: 0.55rem !important;
    color: var(--text-muted) !important;
    margin-top: 2px;
    opacity: 0.4 !important;
}

/* ========== RESPONSIVE ========== */
@media (min-width: 768px) {
    #app {
        max-width: 840px;
        margin: 20px auto;
        border-radius: 12px;
        border: 1px solid rgba(0,102,170,0.3);
        overflow: hidden;
        min-height: auto;
        box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,102,170,0.15);
    }

    #video-container {
        aspect-ratio: 16/9;
        flex: none;
        min-height: auto;
    }

    #header { border-radius: 12px 12px 0 0; }
    #footer { border-radius: 0 0 12px 12px; }

    .quick-stat { padding: 10px 8px; }
    .qs-value { font-size: 1.4rem; }
}

@media (max-width: 380px) {
    #brand h1 { font-size: 0.95rem; }
    .tagline { display: none; }
    .stat-pill { font-size: 0.65rem; padding: 3px 6px; }
    .btn { padding: 8px 10px; font-size: 0.75rem; }
    #logo { width: 30px; height: 30px; }
    .qs-value { font-size: 1rem; }
    .qs-label { font-size: 0.5rem; }
    /* Garder le texte visible sur petits ecrans, juste reduire */
    .btn span { font-size: 0.65rem; }
}

@media (max-width: 340px) {
    #quick-stats { grid-template-columns: repeat(2, 1fr); }
    .btn span { display: none; } /* Seulement sur tres petits ecrans, aria-label prend le relais */
}
