:root {
    --bg: #0f1729;
    --panel: #ffffff;
    --ink: #16233c;
    --muted: #6b7a99;
    --line: #e2e8f4;
    --brand: #2f6bff;
    --brand-dark: #1f4ed1;
    --ok: #12946a;
    --warn: #b54708;
    --bad: #c62828;
    --radius: 12px;
    --alto-barra: 52px;
    --ancho-menu: 226px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink);
    background: #f5f7fc;
    font-size: 15px;
}

a { color: var(--brand); }

.wrap { max-width: 1180px; margin: 0 0 0 var(--ancho-menu); padding: 22px clamp(14px, 2.6vw, 30px) 40px; }

/* ---- login ---- */
.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(1100px 600px at 50% -10%, #1c2f5c, var(--bg));
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 24px 60px rgba(8, 16, 38, .45);
}
.login-card h1 { margin: 0 0 4px; font-size: 21px; }
.login-card p.lead { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

/* ---- shared form ----
   Las reglas van limitadas a .field para no pisar los widgets de EasyUI
   (un selector con atributo, input[type=text], pesa más que .textbox-text). */
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=url], .field input[type=number], .field select, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    font: inherit;
    background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid rgba(47, 107, 255, .25);
    border-color: var(--brand);
}
.field { margin-bottom: 16px; }

.btn {
    display: inline-block;
    padding: 10px 16px;
    border: 0;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: var(--bad); }

.alert {
    padding: 11px 14px;
    border-radius: 9px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert.error { background: #fdecec; color: var(--bad); border: 1px solid #f7c9c9; }
.alert.ok { background: #e7f7ef; color: var(--ok); border: 1px solid #b9e5cf; }

/* ---- shell: barra + menú lateral ---- */
.barra {
    position: sticky;
    top: 0;
    z-index: 900;
    height: var(--alto-barra);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--bg);
    color: #fff;
    box-shadow: 0 6px 18px rgba(8, 16, 38, .18);
}
.barra-marca { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.barra-usuario { margin-left: auto; font-size: 13px; color: #cdd9f5; }

.btn-menu { display: none; }

.menu {
    position: fixed;
    top: var(--alto-barra);
    left: 0;
    bottom: 0;
    width: var(--ancho-menu);
    display: flex;
    flex-direction: column;
    padding: 14px 10px 10px;
    background: var(--panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    z-index: 800;
}
.menu-nav { flex: 1; }
.menu-bloque { margin-bottom: 14px; }
.menu-bloque h3 {
    margin: 0 0 4px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
}
.menu-bloque ul { margin: 0; padding: 0; list-style: none; }
.menu-bloque a {
    display: block;
    padding: 9px 10px;
    border-radius: 9px;
    color: var(--ink);
    font-size: 14px;
    text-decoration: none;
}
.menu-bloque a:hover { background: #eef3ff; color: var(--brand-dark); }
.menu-bloque a.activa { background: var(--brand); color: #fff; font-weight: 600; }
.menu-pie {
    display: grid;
    gap: 2px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}
.menu-pie a { padding: 8px 10px; border-radius: 8px; color: var(--muted); font-size: 13px; text-decoration: none; }
.menu-pie a:hover { background: #eef3ff; color: var(--brand-dark); }

.salto { position: absolute; left: -9999px; top: 0; }
.salto:focus {
    left: 8px;
    top: 8px;
    z-index: 1200;
    padding: 8px 12px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(8, 16, 38, .25);
}

.barra a:focus-visible, .barra button:focus-visible, .menu a:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

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

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
}
.card .k { font-size: 13px; color: var(--muted); }
.card .v { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* ---- tables ---- */
table.data { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: middle; }
table.data th { background: #f2f5fc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.data tr:last-child td { border-bottom: 0; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.on { background: #e7f7ef; color: var(--ok); }
.pill.off { background: #eef1f7; color: var(--muted); }
.pill.nueva { background: #e8f0ff; color: var(--brand-dark); }
.pill.contactado { background: #fff4e0; color: var(--warn); }
.pill.activado { background: #e7f7ef; color: var(--ok); }
.pill.rechazada { background: #fdecec; color: var(--bad); }

section.title { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
section.title h2 { margin: 0; font-size: 20px; }
section.title .spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- páginas CRUD con layout EasyUI ----
   El alto disponible ya no es 100vh menos la barra de antaño: la barra mide --alto-barra. */
main.lleno { max-width: none; margin-left: var(--ancho-menu); padding: 8px 10px 12px; }
main.lleno .easyui-layout { height: calc(100vh - var(--alto-barra) - 20px); }
.crud-acciones { display: flex; flex-direction: column; gap: 10px; }
.crud-acciones .easyui-linkbutton { margin: 0 !important; }

/* ---- celular / tablet: el menú se vuelve cajón y el contenido ocupa todo el ancho ---- */
@media (max-width: 999px) {
    .btn-menu {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        height: 38px;
        padding: 0 12px;
        border: 1px solid rgba(255, 255, 255, .28);
        border-radius: 9px;
        background: rgba(255, 255, 255, .10);
        color: #fff;
        font: inherit;
        font-size: 14px;
        cursor: pointer;
    }
    .btn-menu-icono {
        display: inline-block;
        width: 16px;
        height: 2px;
        background: currentColor;
        position: relative;
    }
    .btn-menu-icono::before, .btn-menu-icono::after {
        content: '';
        position: absolute;
        left: 0;
        width: 16px;
        height: 2px;
        background: currentColor;
    }
    .btn-menu-icono::before { top: -5px; }
    .btn-menu-icono::after { top: 5px; }

    .barra-marca { font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

    .menu {
        width: min(84vw, 300px);
        transform: translateX(-100%);
        transition: transform .18s ease;
        box-shadow: 0 18px 40px rgba(8, 16, 38, .35);
    }
    body.menu-abierto .menu { transform: none; }

    .menu-capa {
        position: fixed;
        inset: var(--alto-barra) 0 0 0;
        z-index: 790;
        background: rgba(8, 16, 38, .45);
    }

    .wrap, main.lleno { margin-left: 0; padding: 16px 14px 30px; }
    /* En el celular cada píxel del layout EasyUI cuenta: el relleno se aprieta al mínimo. */
    main.lleno { padding: 6px; }
    /*
     * El layout necesita un alto REAL en el celular: con `height:auto` EasyUI no puede repartir
     * las regiones y la north se infla (138 px para una barra de 45), dejando al datagrid con
     * ~150 px. `dvh` porque en el navegador del teléfono la barra de direcciones no cabe en `vh`.
     */
    main.lleno .easyui-layout { height: calc(100vh - var(--alto-barra) - 14px); }
    main.lleno .easyui-layout { height: calc(100dvh - var(--alto-barra) - 14px); }
}

/* ---- rail de botones de los CRUD, ya fuera del layout en pantallas angostas ---- */
@media (max-width: 759px) {
    .rail-apilado {
        margin: 0 0 8px;
        padding: 8px;
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 10px;
    }
    .rail-apilado .crud-acciones {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }
    .rail-apilado .sidebar-button {
        flex: 0 0 auto;
        width: auto;
        min-width: 112px;
        height: 36px;
        font-size: 13px;
        white-space: nowrap;
    }
    /* La nota de reglas del rail se muda abajo de la tabla, plegada (ver base.php). */
    .nota-regla {
        margin: 8px 0 0;
        padding: 8px 10px;
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 10px;
    }
    .nota-regla summary { font-size: 13px; font-weight: 600; cursor: pointer; }
    .nota-regla p { margin: 8px 0 0; font-size: 12px; line-height: 1.45; }

    /* Barra de búsqueda: el renglón deslizable ya es global (ver .barra-north más abajo);
       en el celular además se quita el título, que no cabe y no aporta. */
    .barra-north .search-bar > strong { display: none; }
    .barra-north .search-bar .contadores { margin-left: 0; }
}

/*
 * La barra de búsqueda de los CRUD vive en la región `north` del layout. Pasan dos cosas:
 * 1) las vistas le ponen `flex-wrap:wrap`, y si revienta a dos renglones el panel la recorta;
 * 2) el alto de la región se quita del markup para que EasyUI lo mida del contenido.
 * Para que la medida sea la buena el selector usa `.barra-north` (clase del div EN EL MARKUP):
 * `.layout-panel-north` no existe todavía cuando el layout calcula las regiones, así que con
 * esa clase la barra se medía ya partida en tres renglones y la north salía de 138 px.
 */
.barra-north .search-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.barra-north .search-bar > * { flex: 0 0 auto; }
.barra-north .search-bar .contadores { flex-wrap: nowrap; }

/* ---- montos del módulo de pagos ---- */
.saldo-negro { color: #b3261e; font-weight: bold; }
.saldo-cero  { color: #2e7d32; }
.previo { margin-top: 8px; }
.previo img { max-width: 180px; max-height: 110px; border: 1px solid var(--line); border-radius: 8px; }
