:root {
    --obg-navy: #0b2a5b;
    --obg-navy-700: #123a75;
    --obg-blue: #1e88e5;
    --obg-cyan: #35b6f0;
    --obg-gradient: linear-gradient(135deg, #0b2a5b 0%, #1e88e5 70%, #35b6f0 100%);
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafd;
    --border: #e4eaf3;
    --text: #14243c;
    --muted: #6b7c93;
    --verde: #12915a;
    --verde-soft: #e6f7ef;
    --amarillo: #b97708;
    --amarillo-soft: #fff4e0;
    --rojo: #cc2b2b;
    --rojo-soft: #fdecec;
    --radius-lg: 18px;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 35, 61, .05), 0 2px 6px rgba(16, 35, 61, .04);
    --shadow-md: 0 12px 32px rgba(16, 35, 61, .08);
    --sidebar-width: 264px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--obg-blue);
    text-decoration: none;
}

a:hover {
    color: var(--obg-navy);
}

.svg-sprite {
    display: none;
}

.icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.icon-sm {
    width: 15px;
    height: 15px;
}

.icon-lg {
    width: 22px;
    height: 22px;
}

/* ---------- Shell ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: block;
    padding: 4px 10px 22px;
}

.brand-logo {
    width: 100%;
    max-width: 190px;
    height: auto;
    display: block;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-section {
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 16px 12px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    color: #3b4d66;
    font-weight: 500;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}

.nav-link:hover {
    background: var(--surface-soft);
    color: var(--obg-navy);
}

.nav-link.is-active {
    background: var(--obg-gradient);
    color: #fff;
    box-shadow: 0 8px 20px rgba(30, 136, 229, .28);
}

.nav-link .nav-count {
    margin-left: auto;
    background: var(--rojo-soft);
    color: var(--rojo);
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 8px;
}

.nav-link.is-active .nav-count {
    background: rgba(255, 255, 255, .22);
    color: #fff;
}

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 14px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.sidebar-foot strong {
    display: block;
    color: var(--text);
    font-size: 13px;
}

.app-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 32px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-context {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    min-width: 0;
}

.topbar-eyebrow {
    font-size: 11.5px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

.topbar-sep {
    color: #c3cede;
}

.topbar-current {
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-size: 13px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--verde-soft);
    color: var(--verde);
    font-weight: 600;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 999px;
}

.status-pill .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.app-main {
    padding: 28px 32px 56px;
    max-width: 1320px;
    width: 100%;
}

/* ---------- Page head ---------- */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.page-title {
    margin: 0 0 4px;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.page-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.page-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.page-actions form {
    display: flex;
    margin: 0;
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-pad {
    padding: 22px 24px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
}

.card-subtitle {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.section-grid {
    display: grid;
    gap: 20px;
}

/* ---------- KPI ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.kpi-card::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: var(--obg-gradient);
    opacity: .85;
}

.kpi-icon {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    color: #fff;
    flex: 0 0 auto;
}

.kpi-icon.bg-navy { background: linear-gradient(135deg, #0b2a5b, #174273); }
.kpi-icon.bg-blue { background: linear-gradient(135deg, #1e88e5, #35b6f0); }
.kpi-icon.bg-amber { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.kpi-icon.bg-red { background: linear-gradient(135deg, #dc2626, #f87171); }
.kpi-icon.bg-green { background: linear-gradient(135deg, #12915a, #34d399); }

.kpi-label {
    display: block;
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.kpi-value {
    display: block;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.15;
    margin-top: 2px;
}

.kpi-hint {
    display: block;
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 2px;
}

.kpi-hint.is-up { color: var(--verde); font-weight: 600; }
.kpi-hint.is-down { color: var(--rojo); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    padding: 9px 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-obg {
    background: var(--obg-gradient);
    color: #fff;
    box-shadow: 0 8px 18px rgba(30, 136, 229, .25);
}

.btn-obg:hover {
    color: #fff;
    box-shadow: 0 10px 24px rgba(30, 136, 229, .32);
}

.btn-soft {
    background: var(--surface);
    border-color: var(--border);
    color: #3b4d66;
}

.btn-soft:hover {
    background: var(--surface-soft);
    color: var(--obg-navy);
}

.btn-ghost-danger {
    background: transparent;
    border-color: #f2c9c9;
    color: var(--rojo);
}

.btn-ghost-danger:hover {
    background: var(--rojo-soft);
    color: var(--rojo);
}

.btn-wa {
    background: #1faa59;
    color: #fff;
}

.btn-wa:hover {
    background: #17924c;
    color: #fff;
}

.btn-sm {
    padding: 6px 11px;
    font-size: 13px;
}

.btn-icon {
    padding: 7px;
    border-radius: 9px;
    line-height: 1;
}

/* ---------- Forms ---------- */
.form-label {
    font-size: 13px;
    font-weight: 600;
    color: #3b4d66;
    margin-bottom: 6px;
}

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 10px 13px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--obg-blue);
    box-shadow: 0 0 0 4px rgba(30, 136, 229, .12);
}

.form-text {
    font-size: 12.5px;
    color: var(--muted);
}

.form-check-input:checked {
    background-color: var(--obg-blue);
    border-color: var(--obg-blue);
}

.field-error {
    color: var(--rojo);
    font-size: 12.5px;
    margin-top: 4px;
}

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

.form-grid .span-2 {
    grid-column: 1 / -1;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.filter-bar .form-group {
    min-width: 190px;
}

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
}

.obg-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

.obg-table thead th {
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 11.5px;
    letter-spacing: .09em;
    text-transform: uppercase;
    font-weight: 700;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    text-align: left;
}

.obg-table tbody td {
    padding: 13px 14px;
    border-bottom: 1px solid #eef2f8;
    vertical-align: middle;
}

.obg-table tbody tr:last-child td {
    border-bottom: none;
}

.obg-table tbody tr:hover {
    background: #fafcff;
}

.cell-strong {
    font-weight: 650;
    color: var(--text);
}

.cell-muted {
    color: var(--muted);
    font-size: 13px;
}

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* ---------- Badges / pills ---------- */
.badge-semaforo {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-semaforo .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.badge-verde { background: var(--verde-soft); color: var(--verde); }
.badge-amarillo { background: var(--amarillo-soft); color: var(--amarillo); }
.badge-rojo { background: var(--rojo-soft); color: var(--rojo); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 650;
    background: #eef3fb;
    color: #43597a;
}

.pill-activo { background: var(--verde-soft); color: var(--verde); }
.pill-prospecto { background: #eaf2ff; color: #1c68c9; }
.pill-inactivo { background: #eef1f5; color: #6b7c93; }

.pill-etapa {
    background: #f1edff;
    color: #5b46c9;
}

/* ---------- Wear bar ---------- */
.wear {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 150px;
}

.wear-bar {
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: #eaeff7;
    overflow: hidden;
}

.wear-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .4s ease;
}

.wear-fill.is-verde { background: linear-gradient(90deg, #34d399, #12915a); }
.wear-fill.is-amarillo { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.wear-fill.is-rojo { background: linear-gradient(90deg, #f87171, #dc2626); }

.wear-label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--muted);
    min-width: 44px;
    text-align: right;
}

/* ---------- Tabs ---------- */
.obg-tabs {
    display: flex;
    gap: 6px;
    border-bottom: 1px solid var(--border);
    padding: 0 8px;
    flex-wrap: wrap;
}

.obg-tabs .nav-link {
    border-radius: 10px 10px 0 0;
    color: var(--muted);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 2px solid transparent;
}

.obg-tabs .nav-link:hover {
    background: transparent;
    color: var(--obg-navy);
}

.obg-tabs .nav-link.active {
    color: var(--obg-navy);
    background: transparent;
    border-bottom-color: var(--obg-blue);
    box-shadow: none;
}

/* ---------- Detail header ---------- */
.entity-hero {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.entity-avatar {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: var(--obg-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    flex: 0 0 auto;
}

.entity-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.entity-meta {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13.5px;
    margin-top: 6px;
}

.entity-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 18px;
}

.info-item {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.info-label {
    display: block;
    font-size: 11.5px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 4px;
}

.info-value {
    font-size: 14.5px;
    font-weight: 600;
    word-break: break-word;
}

/* ---------- Cabinets ---------- */
.cabina-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.cabina-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 16px 20px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
}

.cabina-name {
    margin: 0;
    font-size: 15.5px;
    font-weight: 650;
}

.cabina-meta {
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 2px;
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 46px 24px;
    color: var(--muted);
}

.empty-state .icon {
    width: 40px;
    height: 40px;
    color: #b7c4d8;
    margin-bottom: 12px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 650;
    color: var(--text);
    margin: 0 0 6px;
}

/* ---------- Alerts ---------- */
.alert {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 13px 16px;
    font-size: 14px;
}

.alert-success {
    background: var(--verde-soft);
    border-color: #bfe9d4;
    color: #0d6b44;
}

.alert-danger {
    background: var(--rojo-soft);
    border-color: #f5c9c9;
    color: #a11f1f;
}

.alert-warning {
    background: var(--amarillo-soft);
    border-color: #f6dfae;
    color: #8a5a05;
}

.toast-stack {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast-obg {
    min-width: 260px;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--verde);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 14px 16px;
    font-size: 14px;
    display: flex;
    gap: 10px;
    animation: toast-in .25s ease;
}

.toast-obg.is-error {
    border-left-color: var(--rojo);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Certificado / print ---------- */
.print-sheet {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 40px 44px;
}

.print-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 3px solid var(--obg-navy);
    padding-bottom: 18px;
    margin-bottom: 26px;
}

.print-logo {
    width: 210px;
    height: auto;
}

.print-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--obg-navy);
    text-align: right;
}

.print-meta {
    font-size: 12.5px;
    color: var(--muted);
    text-align: right;
}

.print-section-title {
    font-size: 13px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--obg-navy);
    font-weight: 700;
    margin: 26px 0 12px;
}

.print-footer {
    margin-top: 34px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

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

.health-box {
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
}

.health-box strong {
    display: block;
    font-size: 22px;
    font-weight: 700;
    margin-top: 2px;
}

.health-box.is-rojo { background: var(--rojo-soft); border-color: #f5c9c9; color: var(--rojo); }
.health-box.is-amarillo { background: var(--amarillo-soft); border-color: #f6dfae; color: var(--amarillo); }
.health-box.is-verde { background: var(--verde-soft); border-color: #bfe9d4; color: var(--verde); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    /* El menú pasa a cajón lateral (off-canvas) con backdrop y cierre por teclado. */
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(304px, 88vw);
        height: 100dvh;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 20px 16px 26px;
        border-radius: 0 20px 20px 0;
        box-shadow: 0 26px 60px rgba(7, 23, 46, .3);
        transform: translateX(-104%);
        transition: transform .24s ease;
        visibility: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        z-index: 130;
    }

    .app-sidebar.is-open {
        transform: none;
        visibility: visible;
    }

    .brand {
        padding: 0 6px 18px;
    }

    .brand-logo {
        max-width: 160px;
    }

    .nav-menu {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        overflow: visible;
    }

    .nav-section {
        display: block;
    }

    .nav-close {
        display: inline-grid;
    }

    .sidebar-user {
        display: flex;
    }

    .sidebar-foot {
        display: flex;
    }

    .nav-toggle {
        display: inline-grid;
    }

    .app-main {
        padding: 22px 18px 48px;
    }

    .app-topbar {
        padding: 14px 18px;
    }
}

@media (max-width: 640px) {
    .page-title {
        font-size: 22px;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .print-sheet {
        padding: 24px 20px;
    }
}

@media print {
    body {
        background: #fff;
    }

    .app-sidebar,
    .app-topbar,
    .nav-backdrop,
    .nav-toggle,
    .pwa-offline,
    .pwa-install-hint,
    .no-print,
    .toast-stack {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .app-main {
        padding: 0;
        max-width: none;
    }

    .print-sheet {
        border: none;
        box-shadow: none;
        border-radius: 0;
        padding: 0;
    }

    .card,
    .cabina-card {
        break-inside: avoid;
        box-shadow: none;
    }

    a {
        color: inherit;
        text-decoration: none;
    }
}

/* ---------- Auth ---------- */
.auth-body {
    background: linear-gradient(135deg, #071c3d 0%, #0b2a5b 45%, #12507f 100%);
    min-height: 100vh;
}

.auth-shell {
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    min-height: 100vh;
}

.auth-aside {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    padding: 64px 72px;
    color: #eaf2ff;
}

.auth-logo {
    width: 240px;
    background: #fff;
    border-radius: 16px;
    padding: 14px 18px;
    margin-bottom: 12px;
}

.auth-headline {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.22;
    letter-spacing: -.02em;
    margin: 0;
    max-width: 15ch;
}

.auth-copy {
    font-size: 15px;
    line-height: 1.65;
    color: rgba(234, 242, 255, .8);
    max-width: 42ch;
    margin: 0;
}

.auth-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 14px;
    color: rgba(234, 242, 255, .88);
}

.auth-list li::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #35b6f0;
    margin-right: 10px;
    vertical-align: middle;
}

.auth-panel {
    display: grid;
    place-items: center;
    padding: 40px 32px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 22px;
    padding: 36px 34px;
    box-shadow: 0 30px 70px rgba(3, 15, 35, .35);
}

.auth-title {
    margin: 0 0 4px;
    font-size: 23px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.auth-subtitle {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 14px;
}

.auth-foot {
    margin: 22px 0 0;
    text-align: center;
    font-size: 11.5px;
    color: var(--muted);
    letter-spacing: .02em;
}

/* ---------- Sidebar user ---------- */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 10px;
    margin-top: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--obg-gradient);
    color: #fff;
    font-weight: 700;
    flex: 0 0 auto;
}

.sidebar-user-data {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.sidebar-user-data strong {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-data span {
    font-size: 11.5px;
    color: var(--muted);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: #3b4d66;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.sidebar-link:hover {
    background: var(--surface-soft);
    color: var(--obg-navy);
}

.sidebar-link-danger:hover {
    background: var(--rojo-soft);
    color: var(--rojo);
}

@media (max-width: 900px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-aside {
        padding: 38px 26px;
    }

    .auth-headline {
        font-size: 24px;
        max-width: none;
    }

    .auth-panel {
        padding: 24px 18px 48px;
    }

    .sidebar-user,
    .sidebar-foot {
        display: none;
    }
}

/* ---------- Consentimiento explícito en formularios ---------- */
.consent-required {
    margin-top: 22px;
    padding: 16px 18px;
    background: #f8fafd;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.consent-required .form-check-input {
    margin-top: .25em;
}

.consent-required .form-check-label {
    font-size: 13.5px;
    color: #3b4d66;
    line-height: 1.55;
}

/* Campo trampa antispam: fuera de pantalla, no oculto por display para que el bot lo complete */
.honeypot {
    position: absolute !important;
    left: -10000px !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.legal-links-inline {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 12px;
    margin-top: 14px;
}

.legal-links-inline a {
    color: var(--muted);
}

/* ---------- Footer legal interno ---------- */
.app-legal-foot {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}

.app-legal-foot nav {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
}

.app-legal-foot a {
    color: var(--muted);
}

.app-legal-foot a:hover {
    color: var(--obg-navy);
}

.legal-foot-btn {
    border: none;
    background: transparent;
    padding: 0;
    font-size: 12px;
    color: var(--muted);
    text-decoration: underline;
    cursor: pointer;
}

.legal-foot-btn:hover {
    color: var(--obg-navy);
}

/* ---------- Navegación móvil (cajón) ---------- */
.nav-toggle,
.nav-close {
    display: none;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--obg-navy);
    cursor: pointer;
    flex: 0 0 auto;
}

.nav-toggle:hover,
.nav-close:hover {
    background: var(--surface-soft);
}

.nav-close {
    position: absolute;
    top: 16px;
    right: 14px;
    width: 36px;
    height: 36px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(8, 21, 40, .48);
    backdrop-filter: blur(2px);
    z-index: 125;
}

body.nav-open {
    overflow: hidden;
}

body.nav-open .nav-backdrop {
    display: block;
}

.sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.topbar-install {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--obg-navy);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.topbar-install:hover {
    background: var(--surface-soft);
}

.topbar-install[hidden] {
    display: none;
}

/* ---------- PWA ---------- */
.pwa-offline {
    display: none;
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 28px);
    padding: 9px 16px;
    border-radius: 999px;
    background: #7a2222;
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    box-shadow: 0 12px 28px rgba(20, 36, 60, .28);
    z-index: 1090;
}

html.is-offline .pwa-offline {
    display: flex;
}

.pwa-install-hint {
    display: none;
    position: fixed;
    inset: 0;
    padding: 20px;
    background: rgba(8, 21, 40, .55);
    z-index: 1100;
    place-items: center;
}

.pwa-install-hint.is-visible {
    display: grid;
}

.pwa-install-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 24px;
}

.pwa-install-card h2 {
    margin: 0 0 8px;
    font-size: 18px;
    color: var(--obg-navy);
}

.pwa-install-card p {
    margin: 0 0 14px;
    font-size: 14px;
    color: var(--muted);
}

.pwa-install-card ol {
    margin: 0 0 18px;
    padding-left: 20px;
    font-size: 13.5px;
    line-height: 1.7;
    color: #3b4d66;
}

.pwa-install-card .btn {
    width: 100%;
}

/* Altura estable para los gráficos de Chart.js en cualquier ancho. */
.chart-box {
    position: relative;
    width: 100%;
    height: clamp(230px, 32vw, 300px);
    min-height: 230px;
    /* Evita que un canvas desactualizado desborde la tarjeta al girar el dispositivo. */
    overflow: hidden;
}

/* En modo aplicaciín instalada se respeta el área segura del dispositivo. */
html.is-standalone .app-main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

html.is-standalone .legal-main {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ---------- Ajustes de responsividad por ancho ---------- */
@media (max-width: 900px) {
    /* Reglas de visualización del cajón reafirmadas al final para ganar a los
       bloques anteriores que ocultaban estos elementos. */
    .nav-toggle,
    .nav-close {
        display: inline-grid;
    }

    .nav-section,
    .sidebar-user,
    .sidebar-foot {
        display: flex;
    }

    .nav-section {
        display: block;
    }

    .topbar-date {
        display: none;
    }
}

@media (max-width: 860px) {
    .app-topbar {
        gap: 10px;
    }

    .topbar-eyebrow,
    .topbar-sep {
        display: none;
    }

    .topbar-meta {
        gap: 8px;
        font-size: 12px;
    }

    .page-head {
        gap: 14px;
        margin-bottom: 18px;
    }
}

@media (max-width: 720px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-group {
        min-width: 0;
        width: 100%;
    }

    .filter-bar .btn {
        width: 100%;
        justify-content: center;
    }

    .obg-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 4px;
        scrollbar-width: none;
    }

    .obg-tabs::-webkit-scrollbar {
        display: none;
    }

    .obg-tabs .nav-link {
        white-space: nowrap;
    }

    .table-wrap {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .table-wrap .obg-table {
        min-width: 560px;
    }

    .obg-table {
        font-size: 13px;
    }

    .obg-table thead th {
        padding: 10px 12px;
    }

    .obg-table tbody td {
        padding: 11px 12px;
    }

    .row-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14.5px;
    }

    .app-main {
        padding: 18px 14px 40px;
    }

    .app-topbar {
        padding: 10px 14px;
    }

    .page-title {
        font-size: 21px;
    }

    .page-subtitle {
        font-size: 13px;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions > * {
        flex: 1 1 auto;
        justify-content: center;
    }

    .page-actions form .btn {
        width: 100%;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .kpi-card {
        padding: 16px 18px;
    }

    .card-pad {
        padding: 16px;
    }

    .card-head {
        padding: 15px 16px;
    }

    .entity-hero {
        padding: 18px;
        gap: 14px;
    }

    .entity-title {
        font-size: 19px;
        overflow-wrap: anywhere;
    }

    .section-grid {
        gap: 14px;
    }

    .print-sheet {
        padding: 22px 16px;
    }

    .toast-stack {
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        align-items: stretch;
    }

    .toast-obg {
        justify-content: flex-start;
    }

    .topbar-install span {
        display: none;
    }

    .topbar-install {
        padding: 7px 9px;
    }

    .chart-box {
        height: 240px;
    }

    .legal-table {
        font-size: 13px;
    }

    .legal-table th,
    .legal-table td {
        padding: 8px 9px;
    }
}

@media (max-width: 420px) {
    .info-grid {
        grid-template-columns: 1fr;
    }

    .cabina-head {
        padding: 14px 16px;
    }

    .status-pill {
        padding: 5px 10px;
        font-size: 11.5px;
    }
}

/* ---------- Tour de onboarding ---------- */
.topbar-help {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--obg-navy);
    cursor: pointer;
}

.topbar-help:hover {
    background: var(--surface-soft);
    color: var(--obg-blue);
}

.obg-tour {
    position: fixed;
    inset: 0;
    z-index: 1500;
}

.obg-tour-velo {
    position: fixed;
    inset: 0;
    background: transparent;
}

.obg-tour-foco {
    position: fixed;
    border-radius: 14px;
    box-shadow: 0 0 0 9999px rgba(6, 20, 40, .74), 0 0 0 2px rgba(53, 182, 240, .95);
    pointer-events: none;
    transition: top .18s ease, left .18s ease, width .18s ease, height .18s ease;
}

.obg-tour-card {
    position: fixed;
    width: min(370px, calc(100vw - 28px));
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 26px 60px rgba(6, 20, 40, .38);
    padding: 20px 22px;
    z-index: 1501;
}

.obg-tour-card:focus {
    outline: none;
}

.obg-tour-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.obg-tour-paso {
    font-size: 11.5px;
    letter-spacing: .12em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--obg-blue);
}

.obg-tour-cerrar {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--muted);
    cursor: pointer;
}

.obg-tour-cerrar:hover {
    background: #eef3fa;
    color: var(--obg-navy);
}

.obg-tour-titulo {
    margin: 10px 0 6px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--text);
}

.obg-tour-texto {
    margin: 0 0 16px;
    font-size: 13.8px;
    line-height: 1.62;
    color: #3b4d66;
}

.obg-tour-puntos {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.obg-tour-punto {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d7e2ef;
}

.obg-tour-punto.is-activo {
    width: 16px;
    border-radius: 999px;
    background: var(--obg-blue);
}

.obg-tour-acciones {
    display: flex;
    align-items: center;
    gap: 8px;
}

.obg-tour-acciones .obg-tour-omitir {
    margin-right: auto;
    border: none;
    background: transparent;
    padding: 0;
    font-size: 12.5px;
    color: var(--muted);
    text-decoration: underline;
    cursor: pointer;
}

.obg-tour-acciones .obg-tour-omitir:hover {
    color: var(--obg-navy);
}

/* En móvil la tarjeta se comporta como hoja inferior. */
.obg-tour-card.is-hoja {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 70dvh;
    overflow-y: auto;
}

.obg-tour-card.is-centrada {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@media (prefers-reduced-motion: reduce) {
    .obg-tour-foco {
        transition: none;
    }
}

@media print {
    .obg-tour,
    .topbar-help {
        display: none !important;
    }
}
