/* =====================================================================
   Theodoro ANPR - Tema visual
   Paleta institucional Colegio Theodoro Hertzl:
   morado #633761 · crema #FEE6C4 · verde #30574E · salvia #91ABA5
   ===================================================================== */

:root {
    --cth-primary: #633761;
    --cth-primary-dark: #4a2949;
    --cth-primary-light: #7d4a7a;
    --cth-cream: #FEE6C4;
    --cth-green: #30574E;
    --cth-sage: #91ABA5;
    --cth-teal: #41BAAE;
    --cth-bg: #f7f4f8;
    --cth-surface: #ffffff;
    --cth-text: #2c2230;
    --cth-muted: #7a6f80;
    --cth-border: #e5dcea;

    /* Colores de estado (sección 17 de la especificación) */
    --st-authorized: #1e8e3e;
    --st-unauthorized: #d93025;
    --st-review: #f2b100;
    --st-manual: #1a73e8;
    --st-duplicate: #80868b;
    --st-expired: #f57c00;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    background: var(--cth-bg);
    color: var(--cth-text);
    min-height: 100vh;
}

/* ------------------------------- Barra superior ---------------------- */

.topbar {
    background: linear-gradient(135deg, var(--cth-primary-dark), var(--cth-primary));
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    box-shadow: 0 2px 8px rgba(74, 41, 73, .35);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .3px;
    white-space: nowrap;
}

.topbar .brand .logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--cth-cream);
    color: var(--cth-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.15rem;
}

.topbar nav {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex: 1;
}

.topbar nav a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: .92rem;
    transition: background .15s;
    white-space: nowrap;
}

.topbar nav a:hover { background: rgba(255,255,255,.12); }
.topbar nav a.active {
    background: var(--cth-cream);
    color: var(--cth-primary-dark);
    font-weight: 600;
}

.topbar .user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .88rem;
}

.topbar .user-box .role-badge {
    background: rgba(255,255,255,.18);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .75rem;
}

.btn-logout {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 8px;
    padding: 5px 12px;
    cursor: pointer;
    font-size: .85rem;
}
.btn-logout:hover { background: rgba(255,255,255,.15); }

main { padding: 22px; max-width: 1500px; margin: 0 auto; }

h1.page-title {
    font-size: 1.35rem;
    margin: 0 0 18px;
    color: var(--cth-primary-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ------------------------------- Tarjetas ----------------------------- */

.card {
    background: var(--cth-surface);
    border: 1px solid var(--cth-border);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 1px 4px rgba(99, 55, 97, .06);
}

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat-card {
    border-radius: 12px;
    padding: 12px 16px;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-card .num { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-card .lbl { font-size: .8rem; opacity: .92; }

/* ------------------------------- Estados ----------------------------- */

.status-authorized { background: var(--st-authorized); }
.status-unauthorized, .status-rejected, .status-inactive_vehicle { background: var(--st-unauthorized); }
.status-pending_review, .status-low_confidence { background: var(--st-review); color: #4d3a00; }
.status-manual_authorization { background: var(--st-manual); }
.status-duplicate, .status-unknown_camera, .status-system_error { background: var(--st-duplicate); }
.status-expired_permission, .status-outside_schedule { background: var(--st-expired); }

.badge-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .3px;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-status.status-pending_review,
.badge-status.status-low_confidence { color: #4d3a00; }

/* ------------------------------- Panel en vivo ------------------------ */

.panel-grid {
    display: grid;
    grid-template-columns: minmax(340px, 1.4fr) 1fr;
    gap: 18px;
    align-items: start;
}
@media (max-width: 980px) { .panel-grid { grid-template-columns: 1fr; } }

.live-event {
    border-radius: 16px;
    overflow: hidden;
    border: 3px solid var(--cth-border);
    transition: border-color .2s;
}

.live-event .head {
    padding: 14px 18px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.live-event .plate {
    font-family: 'Courier New', monospace;
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 4px;
    background: #fff;
    color: #111;
    border: 3px solid #111;
    border-radius: 8px;
    padding: 2px 18px;
}

.live-event .verdict { font-size: 1.35rem; font-weight: 800; text-transform: uppercase; }

.live-event .body {
    background: var(--cth-surface);
    padding: 14px 18px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
@media (max-width: 640px) { .live-event .body { grid-template-columns: 1fr; } }

.live-event img {
    width: 100%;
    border-radius: 10px;
    background: #eee;
    max-height: 340px;
    object-fit: contain;
}

.meta-list { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.meta-list li { padding: 4px 0; border-bottom: 1px dashed var(--cth-border); display: flex; justify-content: space-between; gap: 10px; }
.meta-list li span:first-child { color: var(--cth-muted); }
.meta-list li span:last-child { font-weight: 600; text-align: right; }

.feed { display: flex; flex-direction: column; gap: 10px; max-height: 78vh; overflow-y: auto; }

.feed-item {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--cth-surface);
    border: 1px solid var(--cth-border);
    border-left: 6px solid var(--cth-sage);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: transform .1s;
}
.feed-item:hover { transform: translateX(3px); }
.feed-item .plate-sm {
    font-family: 'Courier New', monospace;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 2px;
}
.feed-item .time { color: var(--cth-muted); font-size: .8rem; }
.feed-item img { width: 66px; height: 48px; object-fit: cover; border-radius: 6px; background: #eee; }

.feed-item.st-authorized { border-left-color: var(--st-authorized); }
.feed-item.st-unauthorized, .feed-item.st-rejected, .feed-item.st-inactive_vehicle { border-left-color: var(--st-unauthorized); }
.feed-item.st-pending_review, .feed-item.st-low_confidence { border-left-color: var(--st-review); }
.feed-item.st-manual_authorization { border-left-color: var(--st-manual); }
.feed-item.st-duplicate, .feed-item.st-unknown_camera { border-left-color: var(--st-duplicate); }
.feed-item.st-expired_permission, .feed-item.st-outside_schedule { border-left-color: var(--st-expired); }

/* ------------------------------- Tablas ------------------------------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    background: var(--cth-surface);
}
table.data th {
    background: var(--cth-primary);
    color: #fff;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    white-space: nowrap;
}
table.data th:first-child { border-top-left-radius: 10px; }
table.data th:last-child { border-top-right-radius: 10px; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--cth-border); vertical-align: middle; }
table.data tr:hover td { background: #faf6fb; }

/* ------------------------------- Formularios -------------------------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

label.fld { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--cth-muted); }

input, select, textarea {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--cth-border);
    border-radius: 8px;
    background: #fff;
    color: var(--cth-text);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--cth-primary-light);
    border-color: var(--cth-primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 9px;
    border: none;
    cursor: pointer;
    background: var(--cth-primary);
    color: #fff;
    transition: filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn.secondary { background: var(--cth-sage); color: #1d2f2b; }
.btn.success { background: var(--st-authorized); }
.btn.danger { background: var(--st-unauthorized); }
.btn.warning { background: var(--st-review); color: #4d3a00; }
.btn.info { background: var(--st-manual); }
.btn.outline { background: transparent; color: var(--cth-primary); border: 1.5px solid var(--cth-primary); }
.btn.sm { padding: 4px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }

/* ------------------------------- Modal -------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(44, 34, 48, .55);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 4vh 16px;
    z-index: 500;
    overflow-y: auto;
}
.modal-backdrop.open { display: flex; }

.modal {
    background: var(--cth-surface);
    border-radius: 14px;
    width: 100%;
    max-width: 720px;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
    overflow: hidden;
}
.modal .modal-head {
    background: var(--cth-primary);
    color: #fff;
    padding: 13px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}
.modal .modal-head button {
    background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer;
}
.modal .modal-body { padding: 18px; }
.modal .modal-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--cth-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ------------------------------- Login -------------------------------- */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(140deg, var(--cth-primary-dark) 0%, var(--cth-primary) 55%, var(--cth-green) 100%);
    padding: 20px;
}
.login-card {
    background: var(--cth-surface);
    border-radius: 18px;
    padding: 34px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 18px 60px rgba(0,0,0,.35);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-card .logo-big {
    width: 64px; height: 64px;
    border-radius: 16px;
    background: var(--cth-cream);
    color: var(--cth-primary);
    font-size: 2rem;
    font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto;
}
.login-card h1 { text-align: center; font-size: 1.25rem; margin: 0; color: var(--cth-primary-dark); }
.login-card .sub { text-align: center; color: var(--cth-muted); font-size: .85rem; margin-top: -8px; }

/* ------------------------------- Varios -------------------------------- */

.alert {
    padding: 10px 14px;
    border-radius: 9px;
    font-size: .9rem;
    margin-bottom: 12px;
}
.alert.error { background: #fde8e6; color: #a01c12; border: 1px solid #f5b9b3; }
.alert.ok { background: #e4f4e8; color: #135d2b; border: 1px solid #b0dfbd; }
.alert.info { background: var(--cth-cream); color: #6b4d18; border: 1px solid #ecd3a7; }

.offline-banner {
    display: none;
    background: var(--st-unauthorized);
    color: #fff;
    text-align: center;
    padding: 6px;
    font-size: .85rem;
    font-weight: 600;
}
body.offline .offline-banner { display: block; }

.muted { color: var(--cth-muted); font-size: .85rem; }
.mt { margin-top: 14px; }
.text-center { text-align: center; }
img.thumb { width: 90px; height: 62px; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: #eee; }
