:root {
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --primary: #0056b3;
    --secondary: #e2e8f0;
    --text: #333333;
    --border: #cccccc;
    --ok: #1b7a3d;
    --warn: #8a6d00;
    --bad: #a61b1b;
}

* { box-sizing: border-box; font-family: 'Segoe UI', system-ui, sans-serif; }
body {
    background-color: var(--bg-color);
    color: var(--text);
    padding: 10px;
    margin: 0;
    padding-bottom: env(safe-area-inset-bottom);
}
.container { max-width: 860px; margin: auto; }
.mt-0 { margin-top: 0; }
.table-wrap { overflow-x: auto; }
.tabla-casos { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla-casos th, .tabla-casos td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid var(--secondary);
    white-space: nowrap;
}
.tabla-casos th { font-size: 12px; color: #555; }
#ui_rol, #ui_unidad { display: block; opacity: 0.92; }

.card {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--secondary);
}
h1, h2, h3 { margin-top: 0; }
h3 { font-size: 16px; border-bottom: 1px solid var(--secondary); padding-bottom: 5px; }
.color-primary { color: var(--primary); }
.color-white { color: white; }
.hint { font-size: 13px; color: #555; font-weight: normal; margin: 8px 0 0; }

label { font-weight: bold; font-size: 14px; display: block; margin: 10px 0 5px; }
input[type="text"], input[type="password"], select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkbox-group label { font-weight: normal; margin: 0; display: flex; align-items: center; }
.checkbox-group input { width: 20px; height: 20px; margin-right: 8px; }

button {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
button:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-primario { background-color: var(--primary); color: white; margin-top: 10px; }
.btn-secundario { background-color: var(--secondary); color: var(--text); }

.header-nav {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    background: var(--primary);
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 12px;
}
.nav-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.btn-nav { width: auto; padding: 8px 12px; font-size: 13px; color: white; }
.btn-success { background: #28a745; }
.btn-info { background: #17a2b8; }
.btn-danger { background: #dc3545; }

.barra-estado {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    background: #d9f2e3;
    color: var(--ok);
}
.barra-estado.offline {
    background: #f8e3e3;
    color: var(--bad);
}
.barra-estado.sync {
    background: #fff3c4;
    color: var(--warn);
}
.cola-card { border-left: 4px solid var(--warn); }

.hidden { display: none !important; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.mt-50 { margin-top: 50px; }
.mt-20 { margin-top: 20px; }
.mt-10 { margin-top: 10px; }
.m-0 { margin: 0; }
.p-5-15 { padding: 5px 15px; width: auto; }
.btn-primario.mt-0 { margin-top: 0; }
.btn-guardar { position: sticky; bottom: 8px; z-index: 2; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-col { flex-direction: column; }
.chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    margin: 0;
    background: #fff;
}
.chip input { width: 18px; height: 18px; }
.chip:has(input:checked) { border-color: var(--primary); background: #e8f1fb; }
.chip-ok:has(input:checked) { border-color: var(--ok); background: #e7f6ec; }
.chip-warn:has(input:checked) { border-color: #c9a227; background: #fff6d6; }
.chip-bad:has(input:checked) { border-color: var(--bad); background: #fde8e8; }
.exito-ficha {
    background: #fff;
    border: 2px solid var(--ok);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    margin-bottom: 15px;
}
.exito-numero {
    font-size: 64px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--primary);
    line-height: 1.1;
}
.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}
.kpi {
    background: #fff;
    border: 1px solid var(--secondary);
    border-radius: 10px;
    padding: 14px 10px;
    text-align: center;
    font-size: 13px;
    color: #555;
}
.kpi-n { display: block; font-size: 28px; font-weight: 800; color: var(--text); }
.kpi-ok { border-color: #b7e0c2; }
.kpi-warn { border-color: #ead48a; }
.kpi-bad { border-color: #f0b4b4; }
.resultados-ficha button {
    width: 100%;
    text-align: left;
    margin-top: 6px;
    font-size: 14px;
    padding: 10px;
}
.btn-peligro {
    background: #fff;
    color: #a61b1b;
    border: 1px solid #f0b4b4;
}
.modal-caso {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
}
.modal-caso .card {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: auto;
    margin: 0;
}

.container { max-width: 860px; }
.card-compact { padding: 12px; }
.form-head { margin-bottom: 8px; }
.form-head h3 { border: none; padding: 0; }
.busca-fila {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: stretch;
    margin-top: 8px;
}
.busca-fila .btn-primario { width: auto; padding: 12px 18px; margin: 0; min-width: 108px; }
.chips-mini .chip { padding: 8px 12px; font-size: 13px; }
.chips-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.banner-ficha {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #eef5fb;
    border: 1px solid #c5d8ee;
}
.traza-linea {
    margin: 6px 0 4px;
    font-size: 13px;
    font-weight: 700;
    color: #0b4f8a;
    line-height: 1.35;
}
.dash-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.reporte {
    background: #fff;
    border: 1px solid #d7dee8;
    border-radius: 12px;
    padding: 14px 16px 12px;
    box-shadow: 0 8px 24px rgba(15, 40, 70, 0.06);
}
.reporte-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 2px solid #0b4f8a;
    padding-bottom: 10px;
    margin-bottom: 12px;
}
.reporte-kicker {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #5b6b7c;
    font-weight: 700;
}
.reporte-titulo { margin: 2px 0 0; font-size: 22px; color: #0b4f8a; }
.reporte-meta { text-align: right; font-size: 13px; color: #334155; }
.reporte-meta span { display: block; color: #64748b; font-size: 12px; }
.kpi-compact {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}
.kpi-compact .kpi {
    padding: 8px 6px;
    border-radius: 8px;
}
.kpi-compact .kpi-n { font-size: 20px; line-height: 1.1; }
.kpi-compact .kpi span:last-child { font-size: 11px; }
.kpi-accent { background: #0b4f8a; color: #dbeafe; border-color: #0b4f8a; }
.kpi-accent .kpi-n { color: #fff; }
.reporte-charts {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}
.chart-box {
    margin: 0;
    padding: 8px 10px 6px;
    border: 1px solid #e6edf5;
    border-radius: 8px;
    background: #fbfdff;
}
.chart-box figcaption {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 4px;
}
.chart-wrap { height: 150px; position: relative; }
.chart-wrap-lg { height: 150px; }
.chart-wrap-split {
    height: 150px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.modo-reporte .barra-estado,
.modo-reporte .cola-card { display: none !important; }
.modo-reporte .header-nav { padding: 10px 12px; margin-bottom: 8px; }

@media (max-width: 720px) {
    .kpi-compact { grid-template-columns: repeat(3, 1fr); }
    .reporte-charts { grid-template-columns: 1fr; }
    .chart-wrap-split { grid-template-columns: 1fr; height: 220px; }
    .busca-fila { grid-template-columns: 1fr; }
    .busca-fila .btn-primario { width: 100%; }
    .chips-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .grid-2 { grid-template-columns: 1fr; }
    .header-nav { flex-direction: column; }
    .nav-actions { width: 100%; }
    .kpi-compact { grid-template-columns: 1fr 1fr; }
    .checkbox-group { grid-template-columns: 1fr; }
    .chips-grid { grid-template-columns: 1fr; }
}

.panel-admin {
    background: #fff;
    border: 1px solid #d7dee8;
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
}
.panel-admin > summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #0b4f8a;
    color: #fff;
}
.panel-admin > summary::-webkit-details-marker { display: none; }
.panel-admin > summary span { font-weight: 800; font-size: 16px; }
.panel-admin > summary small { opacity: 0.85; font-size: 12px; }
.panel-admin[open] > summary { background: #083a66; }
.panel-admin-body { padding: 14px 16px 16px; }
.admin-intro { margin-bottom: 12px; }
.tabla-casos td button { width: auto; display: inline-block; margin: 2px 4px 2px 0; }

@media (min-width: 900px) {
    .kpi-compact { grid-template-columns: repeat(5, 1fr); }
}

@media print {
    body { background: #fff; padding: 0; }
    .header-nav, .dash-toolbar, .barra-estado, .cola-card { display: none !important; }
    .reporte { box-shadow: none; border: none; }
}
