/* =========================================================
   Consola de datos · YT Grupo
   Paleta de ytgrupo.pe: noche, índigo y magenta; modo oscuro automático
   ========================================================= */

:root {
    /* Paleta YT Grupo (ytgrupo.pe) */
    --noche: #0b0824;
    --noche-2: #161633;
    --indigo: #5c55e1;
    --magenta: #cc299f;
    --lavanda: #838cf8;
    --lila: #cb80ec;
    --degradado: linear-gradient(100deg, var(--indigo) 0%, var(--magenta) 100%);
    --degradado-texto: linear-gradient(95deg, var(--lavanda) 0%, #a987fb 50%, var(--lila) 100%);

    --fondo: #f7f5fd;
    --superficie: #ffffff;
    --superficie-2: #f8f6fe;
    --tarjeta: linear-gradient(135deg, #eff5ff 0%, #fce8f6 100%);
    --linea: #ebe5f6;
    --linea-fuerte: #dcd2f0;
    --texto: #0d0d2b;
    --tenue: #6d6890;
    --acento: #5c55e1;
    --acento-hover: #4a42cf;
    --acento-suave: #efedfd;
    --acento-texto: #ffffff;
    --ok: #12a37a;
    --error: #d62a6b;
    --error-suave: #fdeaf2;
    --editor: #fdfcff;
    --pestana-activa: var(--noche);
    --pestana-activa-texto: #ffffff;
    --sombra: 0 1px 2px rgba(13, 13, 43, 0.06), 0 10px 30px rgba(92, 85, 225, 0.10);
    --sans: "Outfit", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
    --radio: 14px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fondo: #0b0824;
        --superficie: #100c2e;
        --superficie-2: #171238;
        --tarjeta: linear-gradient(135deg, #1d1648 0%, #241450 100%);
        --linea: #251f52;
        --linea-fuerte: #352c6b;
        --texto: #f0eeff;
        --tenue: #9f99c8;
        --acento: #8b8bf9;
        --acento-hover: #a3a3fb;
        --acento-suave: rgba(131, 140, 248, 0.14);
        --acento-texto: #0b0824;
        --ok: #3fd1a0;
        --error: #ff6fa8;
        --error-suave: rgba(255, 111, 168, 0.12);
        --editor: #0d0a28;
        --pestana-activa: var(--degradado);
        --pestana-activa-texto: #ffffff;
        --sombra: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--fondo);
    color: var(--texto);
    font: 14px/1.5 var(--sans);
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- controles ---------- */
.boton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    background: var(--superficie);
    border: 1px solid var(--linea-fuerte);
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.boton:hover:not(:disabled) { border-color: var(--acento); color: var(--acento); }
.boton:disabled { opacity: 0.4; cursor: default; }
.boton.primario { background: var(--degradado); border: 0; color: #fff; padding: 0 18px; box-shadow: 0 6px 18px rgba(204, 41, 159, 0.22); }
.boton.primario:hover:not(:disabled) { color: #fff; filter: brightness(1.08); box-shadow: 0 8px 22px rgba(204, 41, 159, 0.32); }
.boton.peligro { color: var(--error); border-color: transparent; background: var(--error-suave); }
.boton.peligro:hover:not(:disabled) { color: var(--error); border-color: var(--error); }
.boton.grande { height: 50px; font-size: 16px; }

input[type="text"], input[type="password"], input[type="search"], select {
    height: 34px;
    background: var(--superficie);
    border: 1px solid var(--linea-fuerte);
    border-radius: 10px;
    padding: 0 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
input::placeholder { color: var(--tenue); }
select { padding-right: 8px; }

.logo-yt { display: block; height: 26px; width: auto; flex-shrink: 0; }
.marca-sep { width: 1px; height: 20px; background: currentColor; opacity: 0.22; flex-shrink: 0; }

/* =========================================================
   Login
   ========================================================= */
.pagina-login { background: var(--superficie); }
.login-escena {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
    min-height: 100%;
}
.login-arte {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(60% 55% at 12% 100%, rgba(92, 85, 225, 0.45) 0%, transparent 70%),
        radial-gradient(45% 45% at 95% 8%, rgba(204, 41, 159, 0.28) 0%, transparent 70%),
        var(--noche);
    color: #fff;
    padding: 36px 0 36px 48px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
}
.login-arte::before {
    /* retícula tenue, como en ytgrupo.pe */
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 56px 56px;
    pointer-events: none;
}
.login-arte > * { position: relative; }
.login-marca { display: inline-flex; align-items: center; gap: 14px; font-weight: 600; font-size: 16px; }
.login-marca .logo-yt { height: 32px; }
.login-query {
    margin: 0;
    display: grid;
    font-family: var(--sans);
    font-weight: 800;
    font-size: clamp(56px, 9.6vw, 164px);
    line-height: 0.9;
    letter-spacing: -0.045em;
    text-transform: uppercase;
    white-space: nowrap;
}
.login-query span:nth-child(2), .login-query span:nth-child(3) {
    background: var(--degradado-texto);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.login-query span:nth-child(3) { margin-right: -0.4em; }
.cursor {
    display: inline-block;
    width: 0.07em;
    height: 0.74em;
    margin-left: 0.05em;
    background: var(--magenta);
    vertical-align: -0.02em;
    animation: parpadeo 1.1s steps(1) infinite;
}
@keyframes parpadeo { 50% { opacity: 0; } }
.login-estado {
    margin: 0;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(33, 21, 78, 0.6);
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}
.punto { width: 8px; height: 8px; border-radius: 50%; background: #3fd1a0; box-shadow: 0 0 0 4px rgba(63, 209, 160, 0.2); }
.login-estado.mal .punto { background: #ffb347; box-shadow: 0 0 0 4px rgba(255, 179, 71, 0.2); }

.login {
    align-self: center;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    padding: 48px 32px;
}
.login h1 { font-size: 34px; line-height: 1.1; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 10px; }
.login-texto { color: var(--tenue); margin: 0 0 36px; font-size: 16px; }
.login-form { display: grid; }
.login-form label { font-size: 14px; font-weight: 600; margin: 18px 0 8px; }
.login-form label:first-of-type { margin-top: 0; }
.login-form input { height: 48px; font-size: 15px; border-radius: 12px; }
.login-form .boton { margin-top: 30px; }
.login-error {
    margin: 0 0 22px;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--error-suave);
    color: var(--error);
    font-weight: 600;
}

/* =========================================================
   Estructura de la app
   ========================================================= */
.barra {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 0 18px;
    background: var(--superficie);
    border-bottom: 1px solid var(--linea);
}
.marca { display: inline-flex; align-items: center; gap: 12px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.sesion { display: flex; align-items: center; gap: 10px; }
.sesion form { margin: 0; }
.sesion-usuario { font-weight: 600; }
.rol { white-space: nowrap; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; }
.rol-admin { background: var(--degradado); color: #fff; }
.rol-lectura { background: var(--superficie-2); color: var(--tenue); border: 1px solid var(--linea); }

.app {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    height: calc(100% - 56px);
}

/* ---------- panel lateral ---------- */
.lateral {
    background: var(--fondo);
    border-right: 1px solid var(--linea);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.filtro { margin: 14px 14px 8px; }
.arbol { overflow-y: auto; padding: 4px 8px 20px; }
.arbol > .aviso { padding: 12px 8px; }
.base summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.base summary:hover { background: var(--superficie-2); }
.base summary::-webkit-details-marker { display: none; }
.base summary::before {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--tenue);
    border-bottom: 1.5px solid var(--tenue);
    transform: rotate(-45deg);
    transition: transform 0.15s;
    flex-shrink: 0;
}
.base[open] summary::before { transform: rotate(45deg) translate(-2px, -1px); }
.base-nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.base-alias { color: var(--tenue); font-size: 12px; }
.tablas { list-style: none; margin: 2px 0 4px; padding: 0 0 0 14px; }
.tabla {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: none;
    border: 0;
    border-radius: 7px;
    padding: 5px 10px;
    text-align: left;
    cursor: pointer;
    font: 400 13px/1.5 var(--mono);
    color: var(--texto);
}
.tabla:hover { background: var(--superficie-2); }
.tabla.activa { background: var(--degradado); color: #fff; }
.tabla.activa .filas, .tabla.activa .etiqueta { color: inherit; opacity: 0.75; }
.tabla-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filas, .etiqueta { color: var(--tenue); font-size: 11px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.etiqueta { font-family: var(--sans); font-style: italic; }
.tablas .cargando, .tablas .vacio { color: var(--tenue); padding: 5px 10px; font-size: 13px; }

/* ---------- zona principal ---------- */
.principal { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--superficie); }
.pestanas {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--linea);
}
.pestanas button {
    height: 32px;
    padding: 0 14px;
    background: none;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    color: var(--tenue);
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}
.pestanas button:hover { color: var(--texto); background: var(--superficie-2); }
.pestanas button[aria-selected="true"] { background: var(--pestana-activa); color: var(--pestana-activa-texto); }
.ubicacion {
    margin-left: auto;
    font: 400 12px/1.6 var(--mono);
    color: var(--tenue);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 12px;
}

.vista { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.herramientas { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.herramientas label { color: var(--tenue); font-size: 13px; }
.buscar { width: min(320px, 100%); }
.espacio { flex: 1; }
.info { color: var(--tenue); font-size: 13px; font-variant-numeric: tabular-nums; }
.aviso { margin: 0; padding: 0 16px 10px; color: var(--tenue); font-size: 13px; }
.estado { margin: 0; padding: 10px 16px; font-size: 13px; color: var(--tenue); min-height: 1.5em; }
.estado.error { color: var(--error); }
.estado.ok { color: var(--ok); }

/* ---------- rejilla ---------- */
.rejilla-caja { flex: 1; overflow: auto; min-height: 0; border-top: 1px solid var(--linea); }
.rejilla {
    border-collapse: separate;
    border-spacing: 0;
    min-width: 100%;
    font: 400 13px/1.45 var(--mono);
    font-variant-numeric: tabular-nums;
}
.rejilla th, .rejilla td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--linea);
    text-align: left;
    white-space: nowrap;
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rejilla td + td, .rejilla th + th { border-left: 1px solid var(--linea); }
.rejilla th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0;
    background: var(--superficie-2);
    color: var(--tenue);
    font: 600 12px/1.4 var(--sans);
}
.rejilla th .orden, .rejilla th.fijo {
    display: flex;
    gap: 6px;
    align-items: center;
    width: 100%;
    padding: 9px 14px;
    background: none;
    border: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}
.rejilla th .orden:hover { color: var(--texto); }
.rejilla th.fijo { display: table-cell; cursor: default; }
.rejilla th.pk .orden { color: var(--acento); }
.rejilla th.pk .orden::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--degradado); }
.rejilla th[aria-sort="ascending"] .orden, .rejilla th[aria-sort="descending"] .orden { color: var(--texto); }
.flecha { color: var(--acento); font-size: 9px; }
.rejilla tbody tr:hover td { background: var(--superficie-2); }
.rejilla td.num { text-align: right; }
.rejilla td.nulo { color: var(--tenue); opacity: 0.55; }
.rejilla td.vacio { color: var(--tenue); font-family: var(--sans); padding: 28px 16px; white-space: normal; }
.rejilla td[tabindex] { cursor: cell; }
.rejilla td[tabindex]:focus-visible { outline: 2px solid var(--acento); outline-offset: -2px; }
.rejilla td.editando { padding: 0; overflow: visible; }
.rejilla td.guardada { background: color-mix(in srgb, var(--ok) 16%, transparent); transition: background 1.2s; }
.edicion {
    width: 100%;
    min-width: 160px;
    height: 34px;
    border: 2px solid var(--acento) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    font: inherit;
    padding: 0 12px;
}
.mensaje-vacio { padding: 56px 24px; color: var(--tenue); max-width: 52ch; font-size: 14px; }
.mensaje-vacio strong { display: block; margin-bottom: 6px; font-size: 24px; font-weight: 800; background: var(--degradado-texto); -webkit-background-clip: text; background-clip: text; color: transparent; width: fit-content; letter-spacing: -0.02em; }

/* ---------- editor SQL ---------- */
.editor {
    display: flex;
    flex-shrink: 0;
    height: 38%;
    min-height: 160px;
    max-height: 75vh;
    margin: 0 16px;
    border: 1px solid var(--linea-fuerte);
    border-radius: var(--radio);
    background: var(--editor);
    overflow: hidden;
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.editor:focus-within { border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
.numeros {
    width: 48px;
    padding: 16px 12px 16px 0;
    text-align: right;
    color: var(--linea-fuerte);
    font: 400 14px/1.7 var(--mono);
    overflow: hidden;
    user-select: none;
    white-space: pre;
    background: var(--superficie-2);
    border-right: 1px solid var(--linea);
}
.editor textarea {
    flex: 1;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    padding: 16px 18px;
    font: 400 14px/1.7 var(--mono);
    font-variant-ligatures: none;
    caret-color: var(--magenta);
    tab-size: 2;
    white-space: pre;
    overflow: auto;
}
.editor textarea::placeholder { color: var(--tenue); }
.vista-sql .rejilla-caja { margin-top: 2px; }
.selector { min-width: 170px; }

/* Barra de símbolos y palabras clave */
.teclas {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
}
.tecla {
    flex-shrink: 0;
    min-width: 34px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--linea-fuerte);
    border-radius: 8px;
    background: var(--superficie);
    color: var(--texto);
    font: 500 14px/1 var(--mono);
    font-variant-ligatures: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.tecla:hover { border-color: var(--acento); color: var(--acento); }
.tecla:active { background: var(--acento-suave); border-color: var(--acento); }
.tecla-palabra { font-size: 12px; color: var(--acento); }
.tecla-ejecutar { display: none; }
.tecla-ejecutar {
    font-family: var(--sans);
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 0 18px;
    background: var(--degradado);
}

/* Botón y velo del panel de tablas en el celular */
.barra-izq { display: flex; align-items: center; gap: 10px; min-width: 0; }
.boton-lateral, .velo { display: none; }

/* ---------- aviso flotante ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    max-width: min(480px, calc(100% - 32px));
    padding: 11px 18px 11px 16px;
    border-radius: 999px;
    background: var(--noche-2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--sombra);
    opacity: 0;
    transform: translate(-50%, 12px);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tenue); flex-shrink: 0; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.ok::before { background: #3fd1a0; }
.toast.error::before { background: var(--error); }

/* =========================================================
   Usuarios
   ========================================================= */
.ubicacion[hidden] { display: none; }
.rejilla td.resumen { font-family: var(--sans); font-size: 13px; max-width: 460px; }
.rejilla td.inactivo { color: var(--error); }
.rejilla td.acciones { padding: 5px 14px; text-align: right; font-family: var(--sans); }
.rejilla td.acciones .boton { height: 28px; font-size: 13px; }
.etiqueta-tu {
    margin-left: 8px;
    font: 500 11px/1 var(--sans);
    color: #fff;
    background: var(--degradado);
    padding: 2px 8px;
    border-radius: 999px;
}

.formulario { flex: 1; overflow-y: auto; padding: 24px 28px 40px; max-width: 900px; }
.form-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 26px; }
.formulario h2 { font-size: 28px; font-weight: 800; letter-spacing: -0.025em; margin: 0; }
.formulario h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.campos label, .dialogo label { display: grid; align-content: start; gap: 8px; font-size: 13px; font-weight: 500; }
.campos input, .campos select, .dialogo input { height: 40px; font-size: 14px; font-weight: 400; }
.campos input[readonly] { background: var(--superficie-2); color: var(--tenue); }
.campos .check { display: flex; align-items: center; gap: 10px; font-size: 14px; align-self: end; height: 40px; }
.check input { accent-color: var(--acento); width: 17px; height: 17px; }
.ayuda { color: var(--tenue); font-size: 12px; font-weight: 400; }

.permisos { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--linea); }
.permisos-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.permisos > .ayuda { margin: 6px 0 16px; }
.permiso-base { border: 1px solid var(--linea); border-radius: var(--radio); margin-bottom: 10px; background: var(--superficie); overflow: hidden; }
.permiso-cabecera-base { display: flex; align-items: center; gap: 10px; padding: 12px 16px; flex-wrap: wrap; background: var(--tarjeta); }
.permiso-cabecera-base .base-nombre { flex: 1; min-width: 140px; }
.permiso-cabecera-base .nivel { border-color: var(--acento); color: var(--acento); font-weight: 500; }
.permiso-tablas { border-top: 1px solid var(--linea); padding: 6px 0; max-height: 380px; overflow-y: auto; }
.permiso-tablas .aviso { padding: 10px 14px; }
.permiso-fila { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 14px; }
.permiso-fila:hover { background: var(--superficie-2); }
.permiso-fila[hidden] { display: none; }
.mono { font: 400 12px/1.5 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nivel { min-width: 150px; height: 32px; font-size: 13px; }

.form-acciones { display: flex; align-items: center; gap: 10px; margin-top: 28px; flex-wrap: wrap; }
.form-error { color: var(--error); font-size: 13px; font-weight: 500; margin: 0; }

.dialogo {
    width: min(420px, calc(100% - 32px));
    background: var(--superficie);
    color: var(--texto);
    border: 0;
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 24px 64px rgba(17, 28, 46, 0.25);
}
.dialogo::backdrop { background: rgba(17, 28, 46, 0.45); backdrop-filter: blur(3px); }
.dialogo h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 6px; }
.dialogo form { display: grid; gap: 16px; }
.dialogo .form-acciones { margin-top: 4px; }

/* =========================================================
   Pantallas pequeñas y accesibilidad
   ========================================================= */
@media (max-width: 900px) {
    .login-escena { grid-template-columns: 1fr; }
    .login-arte { padding: 24px 0 26px 24px; min-height: 280px; gap: 24px; }
    .login-query { font-size: clamp(48px, 17vw, 96px); }
    .login { padding: 36px 24px 48px; }
}
@media (max-width: 820px) {
    .solo-escritorio, .marca-texto, .marca .marca-sep, .sesion-usuario, .rol, .ubicacion { display: none !important; }
    .barra { padding: 0 12px; padding-top: env(safe-area-inset-top, 0); }
    .sesion { gap: 6px; }
    .barra .boton { height: 34px; padding: 0 12px; font-size: 14px; }

    .app { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 56px); }

    /* Panel de tablas como cajón lateral */
    .lateral {
        position: fixed;
        z-index: 30;
        top: 56px;
        bottom: 0;
        left: 0;
        width: min(86vw, 340px);
        border-right: 1px solid var(--linea);
        box-shadow: var(--sombra);
        transform: translateX(-102%);
        transition: transform 0.22s ease;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .lateral-abierto .lateral { transform: none; }
    .velo { display: block; position: fixed; inset: 56px 0 0; z-index: 25; background: rgba(11, 8, 36, 0.45); }
    .velo[hidden] { display: none; }
    .tabla { padding: 10px 12px; font-size: 14px; }
    .base summary { padding: 11px 10px; }

    .pestanas { overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
    .pestanas::-webkit-scrollbar { display: none; }
    .pestanas button { flex-shrink: 0; height: 36px; }
    .boton-lateral { display: inline-flex; gap: 8px; }
    .boton-lateral::before {
        content: "";
        width: 14px;
        height: 10px;
        border-top: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
    }
    .lateral-abierto .boton-lateral { border-color: var(--acento); color: var(--acento); }

    /* Evita el zoom automático del iPhone: los campos deben tener 16px o más */
    input[type="text"], input[type="password"], input[type="search"], select, .editor textarea { font-size: 16px; }
    input[type="text"], input[type="password"], input[type="search"], select { height: 42px; }
    .herramientas { padding: 10px 12px; }
    .buscar { width: 100%; }
    .herramientas .boton { height: 40px; }

    /* Editor SQL cómodo en el celular */
    .vista-sql { overflow-y: auto; }
    .vista-sql > * { flex-shrink: 0; }
    .vista-sql .herramientas { flex-wrap: nowrap; }
    .vista-sql #ejecutar { display: none; }
    .tecla { min-width: 42px; height: 40px; padding: 0 12px; border-radius: 10px; font-size: 16px; }
    .tecla-palabra { font-size: 13px; }
    .tecla-ejecutar { display: inline-flex; align-items: center; }
    .vista-sql .selector { flex: 1; min-width: 0; }
    .vista-sql .herramientas label { display: none; }
    .teclas {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 0 12px 10px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .teclas::-webkit-scrollbar { display: none; }
    .editor { margin: 0 12px; height: 40dvh; min-height: 200px; resize: none; }
    .numeros { display: none; }
    .editor textarea { padding: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
    .vista-sql .rejilla-caja { flex: none; min-height: 45dvh; }
    .rejilla { font-size: 13px; }
    .rejilla th, .rejilla td { max-width: 220px; }

    .formulario { padding: 18px 16px 32px; }
    .form-cabecera { flex-wrap: wrap; }
    .toast { bottom: calc(16px + env(safe-area-inset-bottom, 0)); }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* =========================================================
   Bitácora
   ========================================================= */
.selector-corto { max-width: 190px; }
.rejilla-bitacora td { vertical-align: top; }
.rejilla-bitacora .b-fecha { color: var(--tenue); font-variant-numeric: tabular-nums; }
.rejilla-bitacora .b-usuario { font-family: var(--sans); font-weight: 600; font-size: 13px; }
.rejilla-bitacora .b-base { color: var(--tenue); }
.rejilla-bitacora .b-detalle { min-width: 360px; max-width: 620px; white-space: normal; }
.rejilla-bitacora .b-fecha, .rejilla-bitacora .b-usuario, .rejilla-bitacora .b-evento, .rejilla-bitacora .b-base, .rejilla-bitacora .b-origen { width: 1%; }
.b-texto {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.b-extra { display: block; margin-top: 2px; font: 400 12px/1.4 var(--sans); color: var(--tenue); }
.rejilla-bitacora .b-origen { font-size: 12px; }
.evento {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font: 600 12px/1.3 var(--sans);
    white-space: nowrap;
}
.evento-sesion { background: var(--superficie-2); color: var(--tenue); border: 1px solid var(--linea); }
.evento-consulta { background: var(--acento-suave); color: var(--acento); }
.evento-cambio { background: color-mix(in srgb, var(--magenta) 14%, transparent); color: var(--magenta); }
.evento-usuarios { background: color-mix(in srgb, var(--lila) 22%, transparent); color: #8a3fc0; }
.evento-fallo { background: var(--error-suave); color: var(--error); }
@media (prefers-color-scheme: dark) {
    .evento-cambio { color: #f07ccb; }
    .evento-usuarios { color: var(--lila); }
}
@media (max-width: 820px) {
    #vista-bitacora .herramientas select, #vista-bitacora .buscar { flex: 1 1 45%; max-width: none; }
}
