:root {
    --blue: #1565c0;
    --blue-2: #1976d2;
    --teal: #00796b;
    --cyan: #00838f;
    --bg: #f3f6fb;
    --surface: #ffffff;
    --ink: #172033;
    --muted: #5d6b82;
    --line: #e4ebf5;
    --soft: #f7f9fc;
    --danger: #c62828;
    --warn: #ef6c00;
    --ok: #2e7d32;
    --shadow: 0 10px 30px rgba(23, 43, 77, 0.08);
    --radius: 18px;
    --sidebar: 248px;
    --top: 72px;
    color-scheme: light;
}

html.oscuro {
    --bg: #121722;
    --surface: #1c2433;
    --ink: #e8eef8;
    --muted: #a7b4c9;
    --line: #2c3850;
    --soft: #171e2c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: "Segoe UI", "Avenir Next", system-ui, sans-serif;
    background:
        radial-gradient(900px 420px at -10% -10%, rgba(25, 118, 210, 0.16), transparent 60%),
        radial-gradient(700px 380px at 110% 0%, rgba(0, 172, 193, 0.14), transparent 55%),
        var(--bg);
    color: var(--ink);
    line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: var(--blue-2); }

.ico {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.acceso {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    background:
        linear-gradient(160deg, rgba(21, 101, 192, 0.92), rgba(0, 131, 143, 0.88) 55%, rgba(0, 121, 107, 0.92)),
        var(--bg);
}
.opciones-acceso { display: grid; gap: 10px; margin: 8px 0 14px; }
.opcion-acceso {
    text-align: left;
    border: 1px solid #d5e2f2;
    background: #f7fafc;
    border-radius: 16px;
    padding: 14px 16px;
}
.opcion-acceso strong { display: block; font-size: 1.02rem; }
.opcion-acceso span { color: #5d6b82; font-size: .92rem; }
.instalar {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 16px;
    background: #e8f4fd;
    color: #172033;
}
.instalar p { margin: 6px 0 10px; color: #3d4d63; }
.layout > .main > .instalar { margin: 12px 16px 0; }

.acceso-card {
    width: min(440px, 100%);
    background: #fff;
    color: #172033;
    border-radius: 28px;
    padding: 36px 32px;
    box-shadow: 0 24px 60px rgba(10, 30, 60, 0.28);
}
.acceso-card.ancha { width: min(760px, 100%); }
.acceso.acceso-admin { justify-content: flex-start; align-items: center; overflow: auto; }
.acceso-admin .acceso-card { margin-inline: auto; }
.admin-quien { margin: 0 0 18px; color: #1565c0; font-weight: 600; }
.codigo-grande {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 1.7rem;
    letter-spacing: 0.14em;
    text-align: center;
    margin: 8px 0 12px;
}
.marca-grande {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, #1976d2, #00acc1 55%, #00796b);
    margin-bottom: 18px;
}
.marca-grande .ico { width: 32px; height: 32px; }
.acceso h1 { margin: 0 0 6px; font-size: 2rem; letter-spacing: -0.03em; }
.acceso p.lead { margin: 0 0 22px; color: #5d6b82; }
.lista-puntos { display: grid; gap: 8px; margin: 0 0 22px; padding: 0; list-style: none; color: #33425c; }
.lista-puntos li { display: flex; gap: 8px; align-items: center; }

.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: linear-gradient(180deg, #10233f 0%, #12324a 100%);
    color: #e7eef8;
}
.menu-scroll {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: none;
}
.menu-scroll::-webkit-scrollbar { display: none; }
.desplaza {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    padding: 0;
    display: grid;
    place-items: center;
    background: #10233f;
    color: white;
    box-shadow: var(--shadow);
}
.desplaza:disabled { opacity: 0.35; }
.desplaza[hidden] { display: none !important; }
.desplaza-menu { display: none; }
.flechas-pagina {
    position: fixed;
    right: 12px;
    bottom: 22px;
    z-index: 30;
    display: grid;
    gap: 8px;
}
.layout .flechas-pagina { bottom: 22px; }
.marca { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.marca strong { display: block; font-size: 1.15rem; letter-spacing: -0.02em; }
.marca span { display: block; color: #b7c6da; font-size: 0.82rem; }
.nav { display: grid; gap: 4px; }
.nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: #d5e2f2;
    border-radius: 12px;
    padding: 11px 12px;
}
.nav button.activa, .nav button:hover, .sidebar-pie button.activa { background: rgba(255, 255, 255, 0.1); color: white; }
.corto { display: none; }
.etiq { min-width: 0; }
.sidebar-pie { margin-top: auto; display: grid; gap: 8px; }
.sidebar-pie button {
    display: flex;
    gap: 8px;
    align-items: center;
    border: 0;
    background: rgba(255, 255, 255, 0.06);
    color: #d5e2f2;
    border-radius: 12px;
    padding: 10px 12px;
}

.main { min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    height: var(--top);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid transparent;
}
.titulo-top { min-width: 140px; }
.topbar h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.03em; }
.quien { margin: 0; line-height: 1.2; }
.grupo-lugar { margin: 0 0 18px; }
.grupo-lugar h3 { margin: 0 0 8px; font-size: 1rem; }
.lugar-final { background: #fff3bf; color: inherit; padding: 0 4px; border-radius: 4px; font-weight: 700; }
.sep-ruta { opacity: .55; }
.buscador {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 14px;
    height: 44px;
    box-shadow: var(--shadow);
}
.buscador input { border: 0; outline: 0; width: 100%; background: transparent; font-size: 16px; }
.buscador input::-webkit-search-cancel-button,
.buscador input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.contenido { padding: 8px 28px 48px; }

.rejilla { display: grid; gap: 16px; }
.rejilla-4 { grid-template-columns: repeat(4, 1fr); }
.rejilla-3 { grid-template-columns: repeat(3, 1fr); }
.rejilla-2 { grid-template-columns: repeat(2, 1fr); }

.tarjeta {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.pad { padding: 18px; }
.stat { display: flex; gap: 14px; align-items: center; }
.stat-ico {
    width: 46px; height: 46px; border-radius: 14px;
    display: grid; place-items: center; color: white;
    background: linear-gradient(135deg, var(--blue-2), var(--cyan));
}
.stat b { display: block; font-size: 1.45rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.88rem; }
.seccion-titulo { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0; }
.seccion-titulo h2 { margin: 0; font-size: 1.05rem; }

.btn, .btn-sec, .btn-ghost, .btn-peligro {
    border-radius: 12px;
    border: 0;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}
.btn { background: linear-gradient(135deg, var(--blue-2), #00897b); color: white; font-weight: 650; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-sec { background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-peligro { background: #fdecea; color: var(--danger); }
html.oscuro .btn-peligro { background: #3a2224; }
.btn-bloque { width: 100%; }
.fila-botones { display: flex; flex-wrap: wrap; gap: 8px; }
.fila-botones > input, .fila-botones > select { flex: 1 1 140px; width: auto; min-width: 0; }

.campo { display: grid; gap: 6px; margin-bottom: 12px; }
.campo span, .etiqueta-campo { font-size: 0.82rem; font-weight: 650; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], input[type="search"], select, textarea {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 12px;
    padding: 11px 12px;
    outline: none;
    font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #64b5f6; box-shadow: 0 0 0 4px rgba(25, 118, 210, 0.15); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .tag {
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.82rem;
    border: 1px solid var(--line);
    background: var(--soft);
    color: var(--ink);
}
.tag { color: white; border: 0; font-weight: 650; }
.chip.activa { background: #e3f2fd; color: var(--blue); border-color: transparent; }
html.oscuro .chip.activa { background: #1e3a5f; }

.lista-cosas, .lista-simple { display: grid; gap: 10px; }
.cosa, .fila-alerta, .lugar {
    display: grid;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--surface);
    text-align: left;
    width: 100%;
}
.cosa { grid-template-columns: 72px minmax(0, 1fr) auto; }
.cosa.con-check { grid-template-columns: 28px 72px minmax(0, 1fr) auto; }
.cosa > button, .lugar > span, .fila-alerta { min-width: 0; }
.cosa h3, .lugar h3, .meta, .miga, .dl dd, .ayuda, .stat b { overflow-wrap: anywhere; }
.cosa.seleccionada { border-color: #64b5f6; box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15); }
.mini {
    width: 72px; height: 72px; border-radius: 14px; object-fit: cover;
    background: var(--soft); display: grid; place-items: center; color: var(--muted);
}
.cosa h3, .lugar h3, .fila-alerta strong { margin: 0; font-size: 1rem; }
.meta { color: var(--muted); font-size: 0.86rem; }
.precio { font-weight: 700; font-variant-numeric: tabular-nums; }

.lugares { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.lugar { grid-template-columns: auto minmax(0, 1fr) auto; min-height: 92px; }
.lugar-ico {
    width: 48px; height: 48px; border-radius: 14px;
    display: grid; place-items: center; font-size: 1.4rem;
    background: color-mix(in srgb, var(--nivel, var(--blue)) 16%, var(--surface));
}
.n1 { --nivel: #1976d2; } .n2 { --nivel: #00796b; } .n3 { --nivel: #00838f; }
.n4 { --nivel: #6a1b9a; } .n5 { --nivel: #ef6c00; } .n6 { --nivel: #455a64; }
.n7 { --nivel: #3949ab; } .n8 { --nivel: #6d4c41; } .n9 { --nivel: #ad1457; }
.n10 { --nivel: #c62828; }
.nivel {
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
    text-transform: uppercase; color: var(--nivel, var(--blue));
}

.miga { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); margin-bottom: 14px; }
.miga button { border: 0; background: transparent; color: var(--blue-2); padding: 0; }

.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filtros select, .filtros input { width: auto; min-width: 150px; height: 42px; }

.vacio {
    padding: 42px 20px;
    text-align: center;
    color: var(--muted);
}
.vacio .marca-grande { margin: 0 auto 12px; }

.paginas { display: flex; gap: 8px; justify-content: center; margin-top: 16px; align-items: center; }

.drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(460px, 100%);
    background: var(--surface);
    z-index: 40;
    box-shadow: -16px 0 40px rgba(16, 32, 64, 0.16);
    transform: translateX(104%);
    transition: transform 0.22s ease;
    overflow: auto;
}
.drawer.abierto { transform: none; }
.drawer-cab { display: flex; justify-content: space-between; gap: 8px; padding: 16px 16px 0; position: sticky; top: 0; background: var(--surface); }
.carrusel { display: flex; gap: 8px; overflow: auto; padding: 8px 0 4px; }
.carrusel img { width: 180px; height: 140px; object-fit: cover; border-radius: 14px; }
.bloque { padding: 4px 18px 16px; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.modal-root[hidden] { display: none; }
.modal-root {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(15, 23, 38, 0.48);
    display: grid; place-items: center;
    padding: 18px;
}
.modal {
    width: min(760px, 100%);
    max-height: min(92vh, 900px);
    overflow: auto;
    background: var(--surface);
    border-radius: 24px;
    padding: 22px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
}
.modal h2 { margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.span-2 { grid-column: span 2; }
.iconos { display: flex; flex-wrap: wrap; gap: 6px; }
.iconos button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); font-size: 1.2rem; }
.iconos button.activa { border-color: var(--blue-2); background: #e3f2fd; }

.paso { display: flex; align-items: center; gap: 8px; }
.paso input { width: 88px; text-align: center; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews img, .foto-actual { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; }
.toast {
    background: #172033; color: white; padding: 12px 16px; border-radius: 12px;
    box-shadow: var(--shadow); max-width: min(520px, 92vw);
}
.toast.error { background: #8e2424; }
.toast.ok { background: #0f6b4c; }

.aviso {
    background: #fff6e8; color: #8a4b08; border-radius: 12px; padding: 10px 12px; font-size: 0.9rem;
}
html.oscuro .aviso { background: #3a2c18; color: #ffd59a; }
.error-box { background: #fdecea; color: #8e2424; border-radius: 12px; padding: 12px; }
html.oscuro .error-box { background: #3a2224; color: #ffcdd2; }

.video-scan { width: 100%; border-radius: 16px; background: #000; max-height: 280px; }
.tabla-scroll { overflow-x: auto; max-width: 100%; }
.tabla-muestra { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tabla-muestra th, .tabla-muestra td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.checkline { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.ayuda { color: var(--muted); font-size: 0.9rem; }
.ayuda-lista h3 { margin: 18px 0 4px; font-size: 1.02rem; }
.ayuda-lista h3:first-child { margin-top: 0; }
.ayuda-lista p { margin: 0; }

@media (max-width: 1100px) {
    .rejilla-4 { grid-template-columns: 1fr 1fr; }
    .rejilla-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .acceso { justify-content: flex-start; padding: 16px 14px; }
    .acceso-card { padding: 24px 18px; border-radius: 22px; }
    .acceso h1 { font-size: 1.65rem; }
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0; right: 0; bottom: 0; top: auto;
        height: auto;
        z-index: 20;
        flex-direction: row;
        align-items: stretch;
        gap: 0;
        padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
        background: #10233f;
        overflow: visible;
    }
    .marca { display: none; }
    .largo { display: none; }
    .corto { display: inline; }
    .menu-scroll {
        flex: 1;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
        flex-direction: row;
        align-items: stretch;
        gap: 0;
        -webkit-overflow-scrolling: touch;
    }
    .nav, .sidebar-pie {
        display: contents;
    }
    .nav button, .sidebar-pie button {
        flex: 1 1 0;
        width: auto;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2px;
        min-width: 48px;
        min-height: 52px;
        padding: 6px 2px;
        border-radius: 12px;
        font-size: 0.68rem;
        line-height: 1.1;
        text-align: center;
    }
    .desplaza-menu {
        display: grid;
        position: relative;
        flex: 0 0 36px;
        width: 36px;
        height: auto;
        min-height: 52px;
        align-self: stretch;
        border-radius: 0;
        background: #10233f;
        z-index: 21;
        box-shadow: none;
    }
    .desplaza-menu.izq { box-shadow: 8px 0 12px rgba(16, 35, 63, 0.55); }
    .desplaza-menu.der { box-shadow: -8px 0 12px rgba(16, 35, 63, 0.55); }
    .layout .flechas-pagina { bottom: calc(86px + env(safe-area-inset-bottom)); }
    .nav button .ico, .sidebar-pie button .ico { width: 1.2rem; height: 1.2rem; }
    .contenido, .topbar { padding-left: 14px; padding-right: 14px; }
    .main { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
    .topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 25;
        height: auto;
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px 10px;
        align-items: center;
        padding-top: calc(10px + env(safe-area-inset-top));
        padding-bottom: 10px;
        background: var(--bg);
        backdrop-filter: none;
    }
    .main { padding-top: var(--alto-top, calc(118px + env(safe-area-inset-top))); }
    .titulo-top { grid-column: 1; grid-row: 1; min-width: 0; }
    .topbar h1 { font-size: 1.25rem; }
    .btn-nueva { grid-column: 2; grid-row: 1; }
    .buscador { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
    .btn-nueva { width: 44px; height: 44px; padding: 0; }
    .btn-nueva .etiq { display: none; }
    .layout > .main > .instalar { margin: 8px 14px 0; }
    .rejilla-4 { grid-template-columns: 1fr 1fr; }
    .rejilla-2, .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .stat { gap: 10px; }
    .stat-ico { width: 38px; height: 38px; border-radius: 12px; }
    .stat b { font-size: 1.15rem; }
    .pad { padding: 14px; }
    .cosa, .cosa.con-check { grid-template-columns: 56px minmax(0, 1fr); align-items: center; }
    .cosa.con-check { grid-template-columns: 32px 56px minmax(0, 1fr); }
    .cosa .mini, .cosa button.mini { width: 56px; height: 56px; }
    .cosa .precio, .cosa.con-check .precio {
        display: block;
        grid-column: 2 / -1;
        justify-self: start;
        font-size: 0.92rem;
    }
    .cosa.con-check .precio { grid-column: 3 / -1; }
    .filtros { display: grid; grid-template-columns: 1fr 1fr; }
    .filtros select, .filtros input, .filtros button { width: 100%; min-width: 0; }
    .filtros > .btn, .filtros > .btn-sec, .filtros > .btn-ghost { grid-column: 1 / -1; }
    .fila-botones > .btn, .fila-botones > .btn-sec, .fila-botones > .btn-peligro, .fila-botones > a {
        flex: 1 1 calc(50% - 8px);
    }
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dt { margin-top: 8px; }
    .modal-root { align-items: end; padding: 0; }
    .modal {
        width: 100%;
        max-height: min(92dvh, 900px);
        border-radius: 22px 22px 0 0;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    }
    .drawer { width: 100%; padding-bottom: env(safe-area-inset-bottom); }
    .toasts { bottom: calc(74px + env(safe-area-inset-bottom)); width: min(520px, calc(100% - 24px)); }
    .paso { min-width: 0; }
    .paso input { flex: 1; width: auto; min-width: 0; }
}
@media (max-width: 380px) {
    .rejilla-4 { grid-template-columns: 1fr; }
    .nav button, .sidebar-pie button { min-width: 44px; font-size: 0.62rem; }
}
@media print {
    .sidebar, .topbar, .drawer, .modal-root, .toasts, .no-print { display: none !important; }
    .layout, .main, .contenido { display: block; padding: 0; }
    body { background: white; color: black; }
}
