/* =================================================================
   ROOT VARIABLES & MODERN THEME SYSTEM
   ================================================================= */
:root {
    --bg-primary: #090d16;
    --bg-secondary: #0f172a;
    --card-bg: rgba(19, 27, 46, 0.75);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-border-glow: rgba(59, 130, 246, 0.3);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    /* Accent & Brand Colors */
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-cyan: #06b6d4;
    --accent-indigo: #6366f1;

    /* Status Colors */
    --status-success: #10b981;
    --status-success-bg: rgba(16, 185, 129, 0.15);
    --status-warning: #f59e0b;
    --status-danger: #ef4444;
    --status-danger-bg: rgba(239, 68, 68, 0.15);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --gradient-card: linear-gradient(145deg, rgba(26, 38, 66, 0.6) 0%, rgba(15, 23, 42, 0.8) 100%);
    --gradient-glow: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, rgba(0, 0, 0, 0) 70%);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.25);
}

/* =================================================================
   BASE & RESET
   ================================================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* Background Ambient Glow */
.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    z-index: 0;
    pointer-events: none;
    opacity: 0.6;
}

.glow-1 {
    width: 450px;
    height: 450px;
    top: -100px;
    left: -100px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.35), transparent 70%);
}

.glow-2 {
    width: 500px;
    height: 500px;
    bottom: -150px;
    right: -100px;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.25), transparent 70%);
}

/* =================================================================
   MAIN LAYOUT
   ================================================================= */
.app-container {
    width: 100%;
    max-width: 1100px;
    padding: 2.5rem 1.5rem;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.app-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #60a5fa;
    padding: 0.35rem 0.9rem;
    border-radius: var(--radius-full);
    font-size: 0.825rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: #38bdf8;
    border-radius: 50%;
    box-shadow: 0 0 10px #38bdf8;
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
    70% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 0 8px rgba(56, 189, 248, 0); }
    100% { transform: scale(0.95); opacity: 0.8; box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

.app-title {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(2rem, 4vw, 2.75rem);
    font-weight: 800;
    background: linear-gradient(180deg, #ffffff 30%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.app-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 620px;
    line-height: 1.6;
}

/* =================================================================
   MAIN CARD & GRID
   ================================================================= */
.main-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.75rem;
    align-items: stretch;
}

@media (max-width: 860px) {
    .main-card {
        grid-template-columns: 1fr;
    }
}

/* Card Containers */
.camera-card, .results-card {
    background: var(--gradient-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-soft);
    position: relative;
    transition: var(--transition);
}

.camera-card:hover, .results-card:hover {
    border-color: rgba(59, 130, 246, 0.2);
}

/* Camera Section */
.camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--text-dim);
    transition: var(--transition);
}

.status-dot.active {
    background-color: var(--status-success);
    box-shadow: 0 0 10px var(--status-success);
}

.status-dot.loading {
    background-color: var(--status-warning);
    box-shadow: 0 0 10px var(--status-warning);
}

.status-dot.error {
    background-color: var(--status-danger);
    box-shadow: 0 0 10px var(--status-danger);
}

.status-text {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

.fps-tag {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
}

/* Webcam Wrapper */
.webcam-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #060911;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.webcam-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.5rem;
    gap: 0.75rem;
    z-index: 1;
}

.icon-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.placeholder-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.placeholder-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 260px;
    line-height: 1.4;
}

/* Video/Canvas Feed */
.webcam-stream {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.webcam-stream canvas, .webcam-stream video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    border-radius: var(--radius-md);
    transform: scaleX(-1); /* Mirror view */
}

/* Scanner Laser & Reticle Overlay */
.scanner-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.scan-frame {
    position: relative;
    width: 75%;
    height: 80%;
    border: 1px dashed rgba(59, 130, 246, 0.35);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: #38bdf8;
    border-style: solid;
}

.corner-tl { top: -1px; left: -1px; border-width: 3px 0 0 3px; border-top-left-radius: 8px; }
.corner-tr { top: -1px; right: -1px; border-width: 3px 3px 0 0; border-top-right-radius: 8px; }
.corner-bl { bottom: -1px; left: -1px; border-width: 0 0 3px 3px; border-bottom-left-radius: 8px; }
.corner-br { bottom: -1px; right: -1px; border-width: 0 3px 3px 0; border-bottom-right-radius: 8px; }

.scan-laser {
    position: absolute;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #38bdf8, #06b6d4, transparent);
    box-shadow: 0 0 12px #38bdf8;
    animation: scanLine 2.8s ease-in-out infinite alternate;
}

@keyframes scanLine {
    0% { top: 0%; opacity: 0.2; }
    50% { opacity: 1; }
    100% { top: 100%; opacity: 0.2; }
}

/* Buttons */
.camera-controls {
    display: flex;
    gap: 0.75rem;
}

.btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    outline: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.btn-primary.btn-active {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.35);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex: 0 0 auto;
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* =================================================================
   RESULTS SECTION
   ================================================================= */
.section-heading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 1.25rem;
}

.section-heading i {
    color: var(--accent-blue);
}

/* Primary Result Box */
.primary-result-box {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.primary-result-box.status-mask {
    border-color: rgba(16, 185, 129, 0.4);
    background: var(--status-success-bg);
}

.primary-result-box.status-nomask {
    border-color: rgba(239, 68, 68, 0.4);
    background: var(--status-danger-bg);
}

.result-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: var(--text-muted);
    transition: var(--transition);
    flex-shrink: 0;
}

.primary-result-box.status-mask .result-icon {
    background: rgba(16, 185, 129, 0.2);
    color: var(--status-success);
}

.primary-result-box.status-nomask .result-icon {
    background: rgba(239, 68, 68, 0.2);
    color: var(--status-danger);
}

.result-details {
    display: flex;
    flex-direction: column;
}

.result-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-class {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0.15rem 0;
}

.result-confidence {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

/* Predictions List */
.predictions-list-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 1.25rem;
}

.subheading {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.predictions-container {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.empty-state-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--text-dim);
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(255, 255, 255, 0.05);
}

/* Dynamic Prediction Item */
.pred-item {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    transition: var(--transition);
}

.pred-item.is-highest {
    border-color: rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.08);
}

.pred-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.45rem;
}

.pred-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.pred-percent {
    font-weight: 700;
    font-size: 0.95rem;
    color: #38bdf8;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width 0.15s ease-out;
}

.pred-item.is-highest .progress-fill {
    background: linear-gradient(90deg, #3b82f6 0%, #10b981 100%);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

/* Info Footer */
.info-footer {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    background: rgba(59, 130, 246, 0.06);
    border: 1px solid rgba(59, 130, 246, 0.15);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.info-footer i {
    color: var(--accent-blue);
    margin-top: 2px;
}

/* Toast Message */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #f8fafc;
    padding: 0.85rem 1.4rem;
    border-radius: var(--radius-full);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 100;
    transition: var(--transition);
}

.toast.toast-error {
    border-color: rgba(239, 68, 68, 0.4);
    background: #2b1318;
    color: #fca5a5;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 20px);
}

/* App Footer */
.app-footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.825rem;
    padding-top: 1rem;
}
