/* ═══════════════════════════════════════════════════════
   CDC Vision — Protótipo MVP — Estilos
   ═══════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --card: #1e2230;
    --card-hover: #252a3a;
    --border: #2a2f3f;
    --text: #e8eaf0;
    --text-muted: #8b92a5;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --sidebar-w: 240px;
    --radius: 10px;
    --radius-sm: 6px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon { font-size: 1.4rem; }
.logo-text { font-weight: 700; font-size: 1.1rem; color: var(--accent); }

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--accent); color: white; }
.nav-item.active .nav-badge { background: rgba(255,255,255,0.25); color: white; }

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.nav-label { flex: 1; }

.nav-badge {
    background: var(--card);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
}
.nav-badge.badge-warning { background: var(--warning); color: #000; }
.nav-badge.badge-danger { background: var(--danger); color: white; }

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 0.75rem 0.5rem;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
}

.service-status {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot.green { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.yellow { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.dot.red { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* ═══ MAIN CONTENT ═══ */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 1.5rem 2rem;
    min-height: 100vh;
}

/* ═══ PAGE HEADER ═══ */
.page-header {
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.page-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ═══ KPI CARDS ═══ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.15s;
}
.kpi-card:hover { border-color: var(--accent); }

.kpi-card .kpi-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}
.kpi-card .kpi-value {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
}
.kpi-card .kpi-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.kpi-value.green { color: var(--success); }
.kpi-value.blue { color: var(--accent); }
.kpi-value.yellow { color: var(--warning); }
.kpi-value.red { color: var(--danger); }
.kpi-value.purple { color: var(--purple); }
.kpi-value.cyan { color: var(--cyan); }

/* ═══ CARDS / PANELS ═══ */
.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
}

/* ═══ TABLES ═══ */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    background: var(--surface);
    color: var(--text-muted);
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:hover { background: var(--card-hover); }

/* ═══ BADGES ═══ */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--accent); }
.badge-purple { background: rgba(139,92,246,0.15); color: var(--purple); }
.badge-neutral { background: rgba(139,146,165,0.15); color: var(--text-muted); }

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--card); color: var(--text); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.75rem; }

/* ═══ CAMERA GRID ═══ */
.camera-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.camera-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}
.camera-card:hover { border-color: var(--accent); }
.camera-card.offline { opacity: 0.6; }

.camera-feed {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.camera-feed .feed-placeholder {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

.camera-feed .detection-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.detection-box {
    position: absolute;
    border: 2px solid var(--success);
    border-radius: 3px;
}

.detection-label {
    position: absolute;
    top: -18px;
    left: 0;
    background: var(--success);
    color: white;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}

.camera-info {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.camera-info .cam-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.camera-info .cam-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.camera-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
}

/* ═══ MATCHING / BOARD ═══ */
.match-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: center;
    transition: border-color 0.15s;
}
.match-item:hover { border-color: var(--accent); }
.match-item.divergente { border-left: 3px solid var(--danger); }
.match-item.ok { border-left: 3px solid var(--success); }

.match-col {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.match-col .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}
.match-col .value {
    font-size: 0.9rem;
    font-weight: 600;
}

.match-actions {
    display: flex;
    gap: 0.5rem;
}

/* ═══ PROGRESS BAR ═══ */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.progress-bar .fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s;
}
.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.blue { background: var(--accent); }
.progress-bar .fill.yellow { background: var(--warning); }
.progress-bar .fill.red { background: var(--danger); }

/* ═══ SCORE INDICATOR ═══ */
.score {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}
.score .score-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.score.high .score-dot { background: var(--success); }
.score.medium .score-dot { background: var(--warning); }
.score.low .score-dot { background: var(--danger); }

/* ═══ FILTER BAR ═══ */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    outline: none;
}
.filter-bar select:focus,
.filter-bar input:focus { border-color: var(--accent); }

/* ═══ EVENTS LIST ═══ */
.event-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.event-item:last-child { border-bottom: none; }

.event-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.event-icon.detection { background: rgba(34,197,94,0.15); }
.event-icon.divergence { background: rgba(239,68,68,0.15); }
.event-icon.qr { background: rgba(139,92,246,0.15); }

.event-details { flex: 1; min-width: 0; }
.event-details .event-title { font-size: 0.82rem; font-weight: 500; }
.event-details .event-meta { font-size: 0.72rem; color: var(--text-muted); }

/* ═══ NF CARD ═══ */
.nf-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: border-color 0.15s;
}
.nf-card:hover { border-color: var(--accent); }

.nf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.nf-title {
    font-weight: 700;
    font-size: 1rem;
}

.nf-details {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.nf-field .nf-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}
.nf-field .nf-value {
    font-size: 0.85rem;
    font-weight: 500;
}

/* ═══ GRID LAYOUTS ═══ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

@media (max-width: 1024px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ═══ CATALOG GRID ═══ */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    transition: all 0.15s;
}
.product-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.product-card .product-img {
    width: 100%;
    height: 100px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.product-card .product-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.product-card .product-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* ═══ TOASTS ═══ */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
    max-width: 350px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ═══ PORTA TABS ═══ */
.porta-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.porta-tab {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.porta-tab:hover { background: var(--card); color: var(--text); }
.porta-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ═══ ENTREGA STATUS TIMELINE ═══ */
.timeline {
    position: relative;
    padding-left: 1.5rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
    padding-left: 1rem;
}

/* ═══ LOGIN PAGE ═══ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header .logo-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-group input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
}

.login-btn {
    width: 100%;
    padding: 0.8rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-btn:hover {
    background: var(--accent-hover);
}

.login-btn:active {
    transform: scale(0.98);
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg);
}
.timeline-item.done::before { background: var(--success); }
.timeline-item.active::before { background: var(--warning); box-shadow: 0 0 8px var(--warning); }

/* ═══ SCAN ANIMATION ═══ */
.scan-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(59,130,246,0.1);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--accent);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ═══ IA CONFIG ═══ */
.config-section {
    margin-bottom: 1.5rem;
}

.config-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.config-label {
    font-size: 0.85rem;
    font-weight: 500;
}

.config-value {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: block;
    }
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .camera-grid {
        grid-template-columns: 1fr;
    }
    .match-item {
        grid-template-columns: 1fr;
    }
}
