:root {
    --brand-navy: #091f48;
    --brand-blue: #1f3c73;
    --brand-accent: #00b8ff;
    --header-h: 52px;
    --main-offset: calc(var(--header-h) + 16px);
    --sidebar-w: 250px;
    --footer-h: 36px;
    --transition: 0.22s ease;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f4f6fb;
    color: #0f172a;
}

.header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: var(--header-h);
    padding: 6px max(14px, env(safe-area-inset-right, 0px)) 6px max(10px, env(safe-area-inset-left, 0px));
    padding-top: max(6px, env(safe-area-inset-top, 0px));
    background: #091f48;
    color: #fff;
    width: 100%;
    box-sizing: border-box;
}

.menu-toggle {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 40px;
    min-height: 40px;
    margin: 0;
    padding: 6px 10px;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.menu-toggle:active {
    background: rgba(255, 255, 255, 0.12);
}

.brand {
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
}

.brand i { margin-right: 10px; }

.sidebar-backdrop {
    position: fixed;
    top: var(--header-h);
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    z-index: 1002;
    width: min(var(--sidebar-w), 88vw);
    max-width: 100%;
    height: calc(100dvh - var(--header-h));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #1f3c73;
    color: #fff;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform var(--transition);
}

.sidebar.is-open { transform: translateX(0); }

.sidebar__nav {
    list-style: none;
    margin: 0;
    padding: 10px 10px 16px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

.sidebar__nav > li {
    max-width: 100%;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 42px;
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
}

.sidebar__link:hover,
.sidebar__link.is-active {
    background: #2a4a8b;
}

.sidebar__link i { width: 20px; text-align: center; }

.sidebar__group {
    list-style: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar__nav > li:first-child + .sidebar__group {
    border-top: 0;
}

.sidebar__group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 42px;
    padding: 10px 12px;
    margin: 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: left;
    cursor: pointer;
}

.sidebar__group-toggle:hover,
.sidebar__group-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

.sidebar__group.is-open .sidebar__group-toggle {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar__group-caret {
    flex-shrink: 0;
    font-size: 0.72rem;
    opacity: 0.75;
    transition: transform var(--transition);
}

.sidebar__group.is-open .sidebar__group-caret {
    transform: rotate(180deg);
}

.sidebar__subnav {
    list-style: none;
    margin: 0;
    padding: 0 0 6px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.sidebar__group.is-open .sidebar__subnav {
    max-height: 480px;
}

.sidebar__subnav .sidebar__link {
    padding-left: 24px;
    font-size: 0.92rem;
    min-height: 40px;
    margin: 2px 0;
}

.sidebar__subnav .sidebar__link.is-active {
    background: #2a4a8b;
    box-shadow: inset 3px 0 0 #6ea8ff;
}

.sidebar__link--disabled {
    opacity: 0.55;
    cursor: default;
}

.sidebar__link small {
    margin-left: 4px;
    font-size: 0.72rem;
    font-weight: normal;
}

.main {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding-top: calc(var(--header-h) + 16px);
    padding-right: clamp(16px, 2vw, 32px);
    padding-bottom: 24px;
    padding-left: clamp(16px, 2vw, 32px);
    min-height: calc(100dvh - var(--header-h));
    box-sizing: border-box;
    overflow-x: clip;
    min-width: 0;
}

.footer {
    position: relative;
    width: 100%;
    min-height: var(--footer-h);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    box-sizing: border-box;
}

@media (min-width: 1024px) {
    .sidebar-backdrop { display: none; }
    .sidebar { transform: none; left: 0; }
    body.sidebar-collapsed .sidebar { left: calc(-1 * var(--sidebar-w)); }
    .main {
        margin-left: var(--sidebar-w);
        width: calc(100% - var(--sidebar-w));
        transition: margin-left 0.3s, width 0.3s;
    }
    body.sidebar-collapsed .main {
        margin-left: 0;
        width: 100%;
    }
}

/* Páginas módulo */
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.page-head h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-head__subtitle {
    flex: 1 1 100%;
    margin: -4px 0 0;
    color: var(--text-muted, #64748b);
    font-size: 0.9rem;
}

.form__intro {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    background: #f0f7ff;
    border-left: 3px solid var(--accent, #2563eb);
    border-radius: 4px;
    font-size: 0.92rem;
    color: #334155;
}

.form__section {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem 1.25rem 0.5rem;
    margin-bottom: 1.25rem;
}

.form__section legend {
    font-weight: 600;
    padding: 0 0.5rem;
    color: #1e293b;
}

.card__title {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: #1e293b;
}

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

.search-form {
    display: flex;
    gap: 8px;
}

.search-form input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    min-width: 220px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background: #f4f4f4;
    color: #222;
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn:hover { background: #e8e8e8; }

.btn--primary {
    background: #00b8ff;
    border-color: #00a8e8;
    color: #fff;
}

.btn--primary:hover { background: #0099d6; }

.btn--ghost {
    background: transparent;
    border-color: #ccc;
}

.btn--sm {
    padding: 5px 10px;
    font-size: 0.82rem;
}

.btn--danger {
    color: #b91c1c;
    border-color: #fecaca;
}

.btn--danger:hover {
    background: #fef2f2;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.alert--success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.alert--error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert--warning {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
}

.table-card {
    width: 100%;
    padding: 16px clamp(12px, 1.5vw, 20px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

/* DataTables (jQuery) */
.table-card .dataTables_wrapper {
    width: 100%;
    font-size: 0.9rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-card .dt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.table-card .dataTables_filter {
    margin: 0;
}

.table-card .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #333;
}

.table-card .dataTables_filter input {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font: inherit;
    min-width: 260px;
    margin-left: 8px;
}

.table-card .dataTables_length label {
    font-weight: 600;
    color: #333;
}

.table-card .dataTables_length select {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font: inherit;
    margin: 0 6px;
}

.table-card .dt-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

.table-card table.dataTable thead th {
    background: #f4f4f4;
    border-bottom: 2px solid #ddd;
}

.table-card table.dataTable tbody tr:nth-child(odd) {
    background: #f9f9f9;
}

.table-card table.dataTable tbody tr:hover {
    background: #f1f1f1;
}

.table-card .dataTables_paginate .paginate_button {
    padding: 4px 10px !important;
    border-radius: 4px !important;
}

.col-actions {
    min-width: 130px;
}

.table {
    width: 100% !important;
    border-collapse: collapse;
}

.table-card table.dataTable {
    width: 100% !important;
}

.table th,
.table td {
    border: 1px solid #ddd;
    padding: 0.75rem;
    text-align: left;
}

.table th {
    background: #f4f4f4;
    font-weight: bold;
}

.table tbody tr:nth-child(odd) { background: #f9f9f9; }
.table tbody tr:hover { background: #f1f1f1; }

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge--activo { background: #dcfce7; color: #166534; }
.badge--inactivo { background: #f3f4f6; color: #374151; }
.badge--ok { background: #dcfce7; color: #166534; }
.badge--muted { background: #f3f4f6; color: #374151; }
.badge--suspendido { background: #fef3c7; color: #92400e; }
.badge--moroso { background: #fee2e2; color: #991b1b; }
.badge--instalacion { background: #e0f2fe; color: #0369a1; }

.form__hint {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    color: #64748b;
}

.detail-muted {
    color: #64748b;
    font-size: 0.9rem;
}

.card__subtitle {
    margin: 0 0 14px;
    font-size: 1.1rem;
}

.table tbody tr.row--highlight {
    background: #e0f2fe !important;
}

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

.actions .inline-form {
    display: inline;
    margin: 0;
}

.form--inline-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.form__radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
}

.radio-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

.radio-label input {
    margin-top: 3px;
}

.form__label-block {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    color: #334155;
}

.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.06);
}

/* One column: each .detail-row is a full-width row (label + value inside the row). */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0;
}

.detail-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px 0;
    border-bottom: 1px solid #eee;
}

@media (min-width: 640px) {
    .detail-row {
        grid-template-columns: minmax(140px, 200px) 1fr;
        gap: 12px 16px;
        align-items: start;
    }
}

.detail-row:last-child { border-bottom: 0; }

.detail-row dt {
    margin: 0;
    font-weight: bold;
    color: #555;
    font-size: 0.85rem;
    min-width: 0;
}

.detail-row dd {
    margin: 0;
    min-width: 0;
    word-break: break-word;
}

.detail-row--full dd.detail-pre {
    white-space: pre-wrap;
    line-height: 1.45;
    color: #334155;
}

.form__grid {
    display: grid;
    gap: 16px;
}

@media (min-width: 769px) {
    .form__grid {
        grid-template-columns: 1fr 1fr;
    }
    .form__field--full { grid-column: 1 / -1; }
}

.form__field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.req { color: #dc2626; }

.form__field input,
.form__field select,
.form__field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font: inherit;
}

.form__field textarea {
    resize: vertical;
    min-height: 100px;
}

.form__field--error input,
.form__field--error select {
    border-color: #dc2626;
}

.form__error {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    color: #dc2626;
}

.form__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.banner {
    background: #00b8ff;
    color: #fff;
    padding: 20px;
    text-align: center;
    border-radius: 8px;
    margin-top: 16px;
}

.media-grid {
    display: grid;
    gap: 16px;
    margin-top: 12px;
}

@media (min-width: 769px) {
    .media-grid { grid-template-columns: 1fr 1fr; }
    .media-grid--view { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

.media-card {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    background: #fafafa;
}

.media-card__title {
    margin: 0 0 8px;
    font-size: 0.95rem;
}

.media-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.media-preview {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    border: 1px solid #ddd;
    margin-bottom: 8px;
    object-fit: contain;
}

.media-preview--firma {
    background: #fff;
}

.media-preview--cam[hidden] {
    display: none !important;
}

.input-file-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.firma-block {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}

.firma-pad-wrap {
    border: 1px dashed #ccc;
    border-radius: 8px;
    background: #fff;
    touch-action: none;
}

.firma-canvas {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
}

.firma-tools {
    margin-top: 8px;
}

.camara-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.camara-modal[hidden] {
    display: none !important;
}

.camara-modal__panel {
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    max-width: 520px;
    width: 100%;
}

.camara-video {
    width: 100%;
    max-height: 360px;
    background: #000;
    border-radius: 6px;
}

.camara-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.form__scan-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.form__scan-row input {
    flex: 1;
    min-width: 0;
}

.form__scan-row .btn {
    flex-shrink: 0;
    align-self: stretch;
    min-width: 44px;
    padding-left: 12px;
    padding-right: 12px;
}

.inventario-escaner__panel {
    max-width: min(520px, 96vw);
}

.inventario-escaner__titulo {
    margin: 0 0 8px;
    font-size: 1.125rem;
}

.inventario-escaner__reader {
    width: 100%;
    min-height: 240px;
    border-radius: 6px;
    overflow: hidden;
    background: #000;
}

.inventario-escaner__reader video {
    border-radius: 6px;
}

.inventario-escaner__status {
    margin: 10px 0 0;
    font-size: 0.875rem;
    color: var(--text-muted, #64748b);
}

.inventario-escaner__status--ok {
    color: #15803d;
}

.inventario-escaner__status--warn,
.inventario-escaner__status--error {
    color: #b91c1c;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.inventario-escaner__modos {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.inventario-escaner__modos .btn.is-active {
    background: var(--primary-soft, #eff6ff);
    border-color: var(--primary, #2563eb);
    color: var(--primary, #2563eb);
}

.inventario-escaner__acciones-principales {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inventario-escaner__acciones-principales .form__hint {
    flex: 1 1 100%;
}

.inventario-escaner__ocr .inventario-escaner__video,
.inventario-escaner__video {
    width: 100%;
    max-height: min(50vh, 360px);
    background: #000;
    border-radius: 6px;
}

.inventario-escaner__status--pending {
    color: #1d4ed8;
}

.recorte-modal__panel {
    max-width: min(920px, 96vw);
}

.recorte-modal__hint {
    margin: 0 0 10px;
}

.recorte-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: min(65vh, 520px);
    overflow: hidden;
    background: #1a1a1a;
    border-radius: 6px;
    touch-action: none;
    user-select: none;
}

.recorte-stage__img {
    display: block;
    max-width: 100%;
    max-height: min(65vh, 520px);
    width: auto;
    height: auto;
}

.recorte-stage__sombra {
    position: absolute;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.recorte-marco {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
    cursor: move;
    box-sizing: border-box;
}

.recorte-marco::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px dashed rgba(255, 255, 255, 0.7);
}

.recorte-modal__actions {
    justify-content: flex-end;
}

.form__geo-actions .btn--geo {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
}

.geo-status {
    margin: 8px 0 0;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
}

.geo-status--ok {
    background: #e8f5e9;
    color: #1b5e20;
}

.geo-status--warn {
    background: #fff8e1;
    color: #6d4c00;
}

.geo-status--error {
    background: #ffebee;
    color: #b71c1c;
}

.geo-status--pending {
    background: #e3f2fd;
    color: #0d47a1;
}

.geo-map-link {
    display: inline-block;
    margin-top: 8px;
    font-weight: 600;
}

@media (min-width: 640px) {
    .form__geo-actions .btn--geo {
        width: auto;
        min-width: 280px;
    }
}

.input-readonly {
    background: #f4f6fa;
    color: #333;
    cursor: not-allowed;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 600;
    cursor: pointer;
}

.checkbox-label input {
    margin-top: 4px;
    min-width: 18px;
    min-height: 18px;
}

.legal-hint {
    margin: 8px 0 0 28px;
}

.legal-preview {
    margin: 8px 0 0 28px;
    padding: 12px 14px;
    max-height: 360px;
    overflow-y: auto;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-muted, #505050);
    background: var(--surface-muted, #f4f6fa);
    border: 1px solid var(--border, #d2d6dc);
    border-radius: 8px;
}

.legal-preview .legal--titulo {
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-navy, #091f48);
    text-align: center;
    margin: 8px 0;
}

.legal-preview .legal--seccion {
    font-size: 11px;
    font-weight: 700;
    color: #1f3c73;
    margin: 10px 0 4px;
}

.legal-preview .legal {
    margin: 0 0 6px;
}

.legal-preview .legal--footer {
    margin-top: 10px;
    font-weight: 600;
}

.legal-preview .legal--url a {
    color: var(--link, #003399);
    word-break: break-all;
}

.card__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 1rem;
}

.card__toolbar .card__title {
    margin: 0;
}

.form__fieldset {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}
.form__fieldset legend {
    font-weight: 600;
    padding: 0 0.5rem;
}
.form__fieldset .checkbox {
    display: block;
    margin: 0.65rem 0;
}

.table--compact th,
.table--compact td {
    padding: 6px 8px;
    font-size: 0.88rem;
}

.mensaje-notificacion {
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 100%;
}

/* Inicio — accesos rápidos */
.home-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
}

.home-actions .btn {
    flex: 1 1 calc(50% - 6px);
    justify-content: center;
    min-width: min(100%, 140px);
}

/* ——— Móvil y pantallas táctiles ——— */
@media (max-width: 768px) {
    :root {
        --header-h: 50px;
        --main-offset: calc(var(--header-h) + 16px);
    }

    .brand {
        font-size: 1rem;
        max-width: 55vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .main {
        padding-top: calc(var(--header-h) + 16px);
        padding-right: max(12px, env(safe-area-inset-right, 0px));
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    .sidebar.is-open {
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .page-head h1 {
        font-size: 1.25rem;
    }

    .page-head .toolbar,
    .page-head > .btn {
        width: 100%;
    }

    .page-head .toolbar .btn--primary,
    .page-head > .btn--primary {
        width: 100%;
        justify-content: center;
    }

    .toolbar {
        width: 100%;
    }

    .search-form {
        flex-direction: column;
        width: 100%;
    }

    .search-form input {
        width: 100%;
        min-width: 0;
    }

    .form__actions {
        flex-direction: column;
    }

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

    .card {
        padding: 14px;
    }

    .table-card {
        padding: 12px 8px;
    }

    .table-card .dataTables_wrapper {
        font-size: 0.82rem;
        min-width: 0;
    }

    .table-card .dt-toolbar,
    .table-card .dt-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .table-card .dataTables_filter label,
    .table-card .dataTables_length label {
        flex-wrap: wrap;
    }

    .table-card .dataTables_filter input {
        width: 100%;
        min-width: 0;
        margin-left: 0;
        margin-top: 6px;
    }

    .table-card .dataTables_length select {
        margin: 6px 0 0;
    }

    .table th,
    .table td {
        padding: 0.5rem 0.45rem;
        font-size: 0.85rem;
    }

    .col-actions {
        min-width: 100px;
    }

    .actions .btn {
        min-height: 36px;
    }

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

    .media-card__actions {
        flex-direction: column;
    }

    .media-card__actions .btn,
    .media-card__actions [data-camara] {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .firma-pad-wrap,
    .firma-canvas {
        width: 100%;
        max-width: 100%;
    }

    .camara-modal {
        padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
        align-items: flex-end;
    }

    .camara-modal__panel {
        max-width: none;
        width: 100%;
        border-radius: 12px 12px 0 0;
    }

    .camara-modal__actions {
        flex-direction: column;
    }

    .camara-modal__actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .camara-video {
        max-height: min(50vh, 360px);
    }

    .home-actions .btn {
        flex: 1 1 100%;
    }

    .alert {
        padding: 12px 14px;
        font-size: 0.92rem;
    }

    .badge {
        font-size: 0.8rem;
    }

    .form__field input,
    .form__field select,
    .form__field textarea,
    .search-form input,
    .table-card .dataTables_filter input,
    .table-card .dataTables_length select {
        font-size: 16px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .btn,
    .search-form input,
    .table-card .dataTables_filter input,
    .table-card .dataTables_length select,
    .table-card .dataTables_paginate .paginate_button,
    .form__field input:not([type="checkbox"]):not([type="radio"]),
    .form__field select,
    .form__field textarea,
    .sidebar__link,
    .menu-toggle {
        min-height: 44px;
    }

    .btn--sm {
        min-height: 40px;
        padding: 8px 12px;
    }

    .media-card__actions .btn--sm,
    .media-card__actions [data-camara] {
        min-height: 44px;
        font-size: 0.9rem;
    }

    .checkbox-label input {
        min-width: 22px;
        min-height: 22px;
    }
}

.header-user-menu {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
}

.header-user-menu__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: min(220px, 42vw);
    padding: 6px 10px 6px 6px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.header-user-menu__toggle:hover,
.header-user-menu__toggle:focus-visible {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.45);
    outline: none;
}

.header-user-menu__toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.5);
}

.header-user-menu__toggle[aria-expanded="true"] .header-user-menu__caret {
    transform: rotate(180deg);
}

.header-user-menu__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(0, 184, 255, 0.25);
    color: #fff;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.header-user-menu__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.header-user-menu__caret {
    font-size: 0.65rem;
    opacity: 0.85;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.header-user-menu__panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1200;
    min-width: 240px;
    max-width: min(320px, 92vw);
    padding: 10px 0;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #0f172a;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.header-user-menu__panel[hidden] {
    display: none;
}

.header-user-menu__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 14px 10px;
    border-bottom: 1px solid #e8edf3;
    margin-bottom: 6px;
}

.header-user-menu__meta strong {
    font-size: 0.9rem;
    color: var(--brand-navy);
}

.header-user-menu__email,
.header-user-menu__rol {
    font-size: 0.78rem;
    color: #64748b;
    word-break: break-word;
}

.header-user-menu__rol {
    text-transform: capitalize;
}

.header-user-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.header-user-menu__list a,
.header-user-menu__logout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: 0;
    background: transparent;
    color: #0f172a;
    text-decoration: none;
    font-size: 0.88rem;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.header-user-menu__list a:hover,
.header-user-menu__list a:focus-visible,
.header-user-menu__logout:hover,
.header-user-menu__logout:focus-visible {
    background: #f1f5f9;
    outline: none;
}

.header-user-menu__list a i,
.header-user-menu__logout i {
    width: 16px;
    color: #64748b;
    text-align: center;
}

.header-user-menu__logout-form {
    margin: 0;
}

.header-user-menu__divider {
    height: 1px;
    margin: 6px 0;
    background: #e8edf3;
}

.header-user-menu__logout {
    color: #b91c1c !important;
}

.header-user-menu__logout i {
    color: #b91c1c !important;
}

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-shell {
    width: 100%;
    max-width: 420px;
}

.btn--block {
    width: 100%;
    min-height: 48px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 12px;
    margin-top: 1rem;
    width: 100%;
}

.stat-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card__label {
    display: block;
    font-size: 0.8rem;
    color: #555;
}

.stat-card__value {
    display: block;
    font-size: 1.5rem;
    color: var(--brand-navy);
    margin: 6px 0;
}

.stat-card__link {
    font-size: 0.8rem;
    font-weight: 600;
}

.reporte-texto {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    background: #f8fafc;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
}

.toolbar-form {
    display: inline;
}

/* Tom Select — selector de cliente con búsqueda */
.form__field .ts-wrapper {
    width: 100%;
}

.form__field .ts-wrapper.single .ts-control,
.form__field .ts-control {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 42px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    padding: 6px 10px;
    box-shadow: none;
    background: #fff;
}

.form__field .ts-control input {
    flex: 1 1 140px;
    width: 100% !important;
    min-width: 120px;
    border: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 4px 0 !important;
    margin: 0 !important;
    font-size: 0.95rem;
    background: transparent;
}

.form__field .ts-wrapper.focus .ts-control {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 2px rgba(0, 184, 255, 0.2);
}

.form__field .ts-dropdown {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    z-index: 1200;
    margin-top: 4px;
}

.form__field .ts-dropdown .dropdown-input {
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.form__field .ts-dropdown .dropdown-input input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.95rem;
}

.form__field .ts-dropdown .active {
    background: var(--brand-navy);
    color: #fff;
}

.form__field .ts-dropdown .no-results {
    padding: 10px 12px;
    color: #64748b;
}

.code-block {
    display: block;
    padding: 12px 14px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.45;
}

.dashboard-nodos {
    margin-top: 1.75rem;
}

.dashboard-nodos__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 12px;
}

.dashboard-nodos__head h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--brand-navy);
}

.dashboard-nodos__status {
    margin: 0;
    font-size: 0.85rem;
    color: #64748b;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #64748b;
    padding: 4px 10px;
    border-radius: 999px;
    background: #f1f5f9;
}

.live-badge i {
    font-size: 0.45rem;
}

.live-badge--on {
    color: #15803d;
    background: #dcfce7;
}

.live-badge--on i {
    animation: live-pulse 1.2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.node-card--live {
    animation: card-flash 0.35s ease;
}

@keyframes card-flash {
    from { box-shadow: 0 0 0 0 rgba(0, 184, 255, 0.35); }
    to { box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06); }
}

.node-card--loading {
    border-left-color: #94a3b8;
}

.node-status--pending {
    color: #64748b;
    font-size: 0.78rem;
}

.node-traffic__value,
.node-metric strong,
.node-system__item strong {
    transition: color 0.2s ease;
}

.dashboard-nodos__body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
}

.nodes-dashboard {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.node-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.35fr);
    gap: 14px;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 14px 16px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.node-row--online {
    border-left: 4px solid #16a34a;
}

.node-row--offline {
    border-left: 4px solid #dc2626;
}

.node-row--loading {
    border-left-color: #94a3b8;
}

.node-row__header {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px 16px;
    padding-bottom: 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid #f1f5f9;
}

.node-row__title-wrap {
    min-width: 0;
}

.node-col {
    min-width: 0;
    overflow: visible;
    padding: 12px 14px;
    border: 1px solid #e8edf3;
    border-radius: 8px;
    background: #fafbfc;
}

.node-col--chart {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    min-height: 220px;
    overflow: hidden;
}

.node-col__title {
    margin: 0 0 10px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--brand-navy);
    display: flex;
    align-items: center;
    gap: 8px;
}

.node-spec-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.node-spec-table th,
.node-spec-table td {
    padding: 9px 10px;
    border: 1px solid #e8edf3;
    text-align: left;
    vertical-align: middle;
}

.node-spec-table th {
    width: 42%;
    font-weight: 600;
    color: #475569;
    background: #fff;
}

.node-spec-table td {
    color: #0f172a;
    font-weight: 500;
    background: #fafbfc;
}

.node-spec-table tr:first-child th,
.node-spec-table tr:first-child td {
    border-top: 1px solid #e8edf3;
}

.node-spec-bars {
    margin-top: 12px;
}

.node-uptime {
    margin: 0 0 10px;
    font-size: 0.8rem;
    color: #475569;
}

.node-uptime strong {
    color: var(--brand-navy);
}

.node-chart__canvas {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 200px;
}

.node-chart__legend {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-size: 0.78rem;
    color: #64748b;
}

.node-chart__legend span::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 3px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

.node-chart__legend--rx::before {
    background: #2563eb;
}

.node-chart__legend--tx::before {
    background: #16a34a;
}

@media (max-width: 1200px) {
    .node-row {
        grid-template-columns: 1fr 1fr;
    }

    .node-col--chart {
        grid-column: 1 / -1;
        min-height: 240px;
    }
}

@media (max-width: 720px) {
    .node-row {
        grid-template-columns: 1fr;
    }

    .node-col--chart {
        grid-column: auto;
    }
}

.node-card__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.node-card__title {
    margin: 0;
    font-size: 1.05rem;
}

.node-card__meta {
    margin: 4px 0 0;
    font-size: 0.82rem;
    color: #64748b;
}

.node-card__error {
    margin: 0 0 8px;
    font-size: 0.82rem;
    color: #b45309;
}

.node-card__app {
    margin: 10px 0 0;
    font-size: 0.8rem;
    color: #475569;
    border-top: 1px solid #f1f5f9;
    padding-top: 8px;
}

.node-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.node-status--online {
    color: #16a34a;
}

.node-status--offline {
    color: #dc2626;
}

.node-status i {
    font-size: 0.5rem;
}

.node-traffic {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 10px;
}

.node-traffic__label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
}

.node-traffic__value {
    font-size: 1.1rem;
    color: var(--brand-navy);
}

.node-metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 12px;
}

.node-metric span {
    display: block;
    font-size: 0.72rem;
    color: #64748b;
}

.node-metric strong {
    font-size: 1.15rem;
}

.text-ok {
    color: #16a34a;
}

.text-warn {
    color: #d97706;
}

.node-system {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.node-system__title {
    margin: 0 0 6px;
    font-size: 0.88rem;
    color: var(--brand-navy);
    display: flex;
    align-items: center;
    gap: 8px;
}

.node-system__meta {
    margin: 0 0 8px;
    font-size: 0.78rem;
    color: #64748b;
    line-height: 1.35;
}

.node-system__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    margin-bottom: 10px;
}

.node-system__item span {
    display: block;
    font-size: 0.72rem;
    color: #64748b;
}

.node-system__item strong {
    font-size: 0.92rem;
}

.node-bar {
    margin-bottom: 8px;
}

.node-bar__head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.72rem;
    color: #475569;
    margin-bottom: 4px;
}

.node-bar__track {
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.node-bar__fill {
    height: 100%;
    background: #3b82f6;
    border-radius: 999px;
    transition: width 0.35s ease;
}

.node-bar__fill--warn {
    background: #f59e0b;
}

.node-bar__fill--danger {
    background: #ef4444;
}

.node-bar__hint {
    display: block;
    margin-top: 2px;
    font-size: 0.68rem;
    color: #94a3b8;
}

.ubicacion-ac {
    position: relative;
}

.ubicacion-ac__list {
    position: absolute;
    z-index: 40;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    margin: 0;
    padding: 6px 0;
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface-elevated, #fff);
    border: 1px solid var(--border, #dbe3ef);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.ubicacion-ac__item {
    padding: 8px 12px;
    font-size: 0.92rem;
    cursor: pointer;
    color: var(--text, #0f172a);
}

.ubicacion-ac__item:hover,
.ubicacion-ac__item--active {
    background: var(--primary-soft, #eff6ff);
    color: var(--primary, #2563eb);
}
