/* ============================================================================
   CUPHST cloud - hoja de estilos unica del panel.
   No se fragmenta en modulos: todo el lenguaje visual vive aca.

   Dos zonas cromaticas, sin mezcla:
     1. Chrome pintado en el ambar institucional --primary: SOLO la topbar y la
        barra de titulo de los modales. Sus hijos usan #fff y opacidades de
        blanco, NUNCA --text / --muted / --border: el contraste se calcula
        contra el ambar, no contra el gris.
     2. Todo lo demas -- sidebar, area de contenido (cards, tablas, inputs,
        cuerpos de modal) -- en grises oscuros. Ahi el ambar vuelve solo como
        ACENTO: boton primario, focus ring, chip activo, item de menu activo,
        valores destacados.

   Tema unico oscuro. No hay data-theme, no hay toggle, no hay modo claro.
   ========================================================================== */

/* ---- 1. Tokens ---------------------------------------------------------- */

:root {
    /* superficies */
    --bg:        #1a1a1a;   /* fondo del area de contenido */
    --surface:   #242526;   /* cards, modales, inputs, dropdowns */
    --border:    #383838;   /* bordes sutiles en zona gris */
    --row-hover: #2d2e2f;   /* hover de filas y tarjetas */
    --sidebar:   #202021;   /* fondo del menu vertical */
    --sidebar-2: #191919;   /* sub-items desplegados del menu */

    /* marca: ambar institucional del Colegio.
       Es el naranja del sitio publico (#f7b035) bajado hasta que el blanco
       sobre el llega a 4.6:1 -- el chrome lleva texto blanco, asi que el hex
       del sitio no se puede usar tal cual. */
    --primary:   #b87414;
    --primary-h: #8f590f;

    /* semanticos */
    --danger:    #e62a2a;
    --success:   #22c55e;
    --warn:      #f59e0b;
    --info:      #3b82f6;

    /* texto */
    --text:      #f0f0f0;
    --muted:     #9ca0a4;

    /* formas */
    --radius:    10px;
    --shadow:    0 1px 4px rgba(0,0,0,.45);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.65);
}

/* ---- 2. Reset y base ---------------------------------------------------- */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    color-scheme: dark;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: rgba(184,116,20,.45); }

/* Scrollbars acordes al tema (sin esto Chrome en Windows las pinta claras). */
* { scrollbar-color: #4a4a4a transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #4a4a4a; border-radius: 99px;
                             border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #5c5c5c; background-clip: content-box; }

/* ---- 3. Layout principal ------------------------------------------------ */

.layout  { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar);
           border-right: 1px solid var(--border);
           display: flex; flex-direction: column; flex-shrink: 0; }
.main    { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar  { background: var(--primary); border-bottom: 1px solid rgba(0,0,0,.25);
           padding: 0 24px; height: 60px; flex-shrink: 0;
           display: flex; align-items: center; justify-content: space-between;
           box-shadow: var(--shadow); }
.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ---- 4. Sidebar --------------------------------------------------------- */

/* La franja del logo es la continuacion de la topbar, no del menu: va en
   ambar y a la misma altura, asi la cabecera corta la pantalla de lado a
   lado. De ahi para abajo el sidebar ya es gris. */
.sidebar-logo      { height: 60px; padding: 0 16px; flex-shrink: 0;
                     background: var(--primary);
                     border-bottom: 1px solid rgba(0,0,0,.25);
                     display: flex; align-items: center; justify-content: center; }
.sidebar-logo-mark { display: block; width: auto; height: 34px;
                     max-width: 100%; object-fit: contain; }

.sidebar-nav { padding: 8px 0 12px; flex: 1; overflow-y: auto; }

.nav-item { display: flex; align-items: center; gap: 10px;
            padding: 10px 20px; font-size: .9rem; color: var(--muted);
            cursor: pointer; border-left: 3px solid transparent;
            transition: background .15s, color .15s; text-decoration: none; }
.nav-item:hover  { background: var(--row-hover); color: var(--text); }
.nav-item.active { background: rgba(184,116,20,.16); color: var(--primary);
                   border-left-color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; flex-shrink: 0; }

.nav-group-wrap                       { display: block; }
.nav-group-toggle                     { width: 100%; background: none; border: none;
                                        text-align: left; cursor: pointer;
                                        color: var(--muted); }
.nav-group-label                      { flex: 1; }
.nav-group-arrow                      { margin-left: auto; font-size: 1rem; font-weight: 700;
                                        line-height: 1; color: var(--muted);
                                        transition: transform .2s; }
.nav-group-wrap.open .nav-group-arrow { transform: rotate(45deg); }   /* + -> x */
.nav-sub                              { display: none; background: var(--sidebar-2);
                                        border-top: 1px solid var(--border);
                                        border-bottom: 1px solid var(--border); }
.nav-group-wrap.open .nav-sub         { display: block; }
.nav-sub-item                         { padding-left: 44px; font-size: .85rem; }

/* ---- 5. Topbar ---------------------------------------------------------- */

.topbar-title    { font-size: 1rem; font-weight: 600; flex: 1; color: #fff;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user     { display: flex; align-items: center; gap: 10px;
                   flex-shrink: 0; position: relative; }
.topbar-username { background: none; border: none; cursor: pointer;
                   font-size: .85rem; color: rgba(255,255,255,.85);
                   display: flex; align-items: center; gap: 6px;
                   padding: 6px 10px; border-radius: 8px;
                   transition: background .15s, color .15s; }
.topbar-username:hover { background: rgba(0,0,0,.18); color: #fff; }
.topbar-entorno  { font-size: .68rem; font-weight: 700; letter-spacing: .06em;
                   text-transform: uppercase; color: #fff;
                   background: rgba(0,0,0,.28); border-radius: 99px; padding: 3px 9px; }
.topbar .hamburger { color: #fff; }

/* El dropdown cae sobre el area gris: ahi si valen los tokens normales. */
.user-dropdown       { display: none; position: absolute; right: 0; top: calc(100% + 6px);
                       background: var(--surface); border: 1px solid var(--border);
                       border-radius: 10px; box-shadow: var(--shadow-lg);
                       min-width: 190px; overflow: hidden; z-index: 200; }
.user-dropdown.open  { display: block; }
.user-dropdown-datos { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.user-dropdown-datos strong { display: block; font-size: .85rem; }
.user-dropdown-datos span   { font-size: .75rem; color: var(--muted); }
.user-dropdown a     { display: flex; align-items: center; gap: 10px;
                       padding: 10px 14px; color: var(--text); font-size: .85rem;
                       cursor: pointer; transition: background .15s, color .15s; }
.user-dropdown a:hover { background: var(--bg); color: var(--primary); }
.user-dropdown a i   { width: 14px; text-align: center; color: var(--muted); }
.user-dropdown a:hover i { color: inherit; }

/* ---- 6. Botones --------------------------------------------------------- */

.btn { padding: 8px 16px; border-radius: var(--radius); border: none;
       font-size: .88rem; font-weight: 600; cursor: pointer;
       display: inline-flex; align-items: center; justify-content: center; gap: 6px;
       transition: background .15s, transform .1s, border-color .15s, color .15s; }
.btn:active          { transform: scale(.97); }
.btn:disabled        { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary         { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)   { background: var(--primary-h); }
.btn-danger          { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)    { background: #c91515; }
.btn-secondary       { background: var(--surface); color: var(--text);
                       border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-ghost           { background: transparent; color: var(--muted);
                       border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)     { background: var(--bg); color: var(--text); }
.btn-sm              { padding: 5px 12px; font-size: .8rem; }
.btn-icon-sm         { background: none; border: none; cursor: pointer;
                       padding: 4px 8px; border-radius: 6px; font-size: .85rem;
                       color: var(--muted); transition: background .15s, color .15s; }
.btn-icon-sm:hover   { background: var(--bg); color: var(--text); }

/* Botones solo-icono de la toolbar (Filtros / Refrescar). */
.btn.btn-icon        { position: relative; width: 36px; height: 36px;
                       padding: 0; flex-shrink: 0; }
.btn.btn-icon i      { font-size: .95rem; }
.btn.btn-icon.active { background: transparent;
                       border-color: var(--primary); color: var(--primary); }
.btn-icon-badge      { position: absolute; top: -4px; right: -4px;
                       min-width: 18px; height: 18px; padding: 0 5px;
                       border-radius: 99px; background: var(--warn); color: #1a1a1a;
                       font-size: .65rem; font-weight: 700; line-height: 1;
                       display: inline-flex; align-items: center; justify-content: center; }

/* ---- 7. Inputs ---------------------------------------------------------- */

input[type=text], input[type=number], input[type=url], input[type=tel],
input[type=email], input[type=date], input[type=time], input[type=datetime-local],
input[type=password], input[type=search], select, textarea {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px 12px; font-size: .88rem; background: var(--surface);
    color: var(--text); outline: none; font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(184,116,20,.25);
}
input:disabled, select:disabled, textarea:disabled,
input[readonly], textarea[readonly] {
    color: var(--muted); background: var(--bg); cursor: not-allowed; opacity: .75;
}
textarea { resize: vertical; min-height: 60px; line-height: 1.5; }
select   { cursor: pointer; }
/* el icono nativo del date picker es negro sobre fondo oscuro */
input[type=date]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(.8); cursor: pointer; }

.field-error   { margin-top: 4px; font-size: .78rem; color: var(--danger); }
.input-invalid { border-color: var(--danger) !important;
                 box-shadow: 0 0 0 2px rgba(230,42,42,.18) !important; }

/* ---- 8. Formularios ----------------------------------------------------- */

.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3  { grid-template-columns: repeat(3, 1fr); }
.form-row-4  { grid-template-columns: repeat(4, 1fr); }
.form-group  { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea { width: 100%; }
.form-nota   { font-size: .78rem; color: var(--muted); line-height: 1.5; }

/* 8-bis. Ayuda de un campo: question-circle a la DERECHA del rotulo. */
.field-help {
    position: relative;
    display: inline-flex; align-items: center; vertical-align: middle;
    margin-left: 5px;
    color: var(--muted); cursor: help;
    transition: color .15s;
}
/* El :has() acota el flex a los labels que REALMENTE tienen ayuda: los de los
   toggles y los campos sin globito no deben volverse flex. El gap reemplaza al
   margin-left de arriba, que sumado daria 10px. */
.form-group label:has(.field-help) { display: flex; align-items: center; gap: 5px; }
.form-group label .field-help      { margin-left: 0; }
.field-help:hover, .field-help:focus-visible { color: var(--text); outline: none; }
.field-help i { font-size: .85rem; }

.field-help-tip {
    position: absolute; top: calc(100% + 8px); left: 0; z-index: 20;
    width: max-content; max-width: 280px;
    padding: 9px 11px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    /* el globito hereda del <label>, que va en 600 y en --muted */
    font-size: .78rem; font-weight: 400; line-height: 1.5;
    text-transform: none; letter-spacing: normal; white-space: normal;
    opacity: 0; visibility: hidden;
    transition: opacity .12s ease, visibility .12s;
    /* sin esto el globito se come los clicks del campo de abajo */
    pointer-events: none;
}
.field-help:hover .field-help-tip,
.field-help:focus-visible .field-help-tip { opacity: 1; visibility: visible; }
/* En la ultima columna de la grilla se ancla al borde derecho: anclado a la
   izquierda mide hasta 280px, se sale del modal y le aparece scroll
   horizontal. Mira la posicion en la grilla, no una clase del llamador. */
.form-row > *:last-child .field-help-tip { left: auto; right: 0; }

/* ---- 9. Encabezado de pantalla y toolbar -------------------------------- */

.page-header  { display: flex; align-items: flex-start; justify-content: space-between;
                gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title   { font-size: 1.15rem; font-weight: 700; }
.page-sub     { font-size: .82rem; color: var(--muted); margin-top: 2px; }

.module-help  { background: var(--surface); border: 1px solid var(--border);
                border-radius: var(--radius); padding: 14px 18px;
                margin-bottom: 16px; box-shadow: var(--shadow);
                display: flex; gap: 14px; align-items: center; }
.module-help-icon { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.module-help-text { font-size: .88rem; color: var(--muted); line-height: 1.45; }

.toolbar       { display: flex; align-items: center; gap: 12px;
                 flex-wrap: wrap; margin-bottom: 20px; }
.toolbar-left  { display: flex; align-items: center; gap: 8px;
                 flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; flex-wrap: wrap; }

.search-wrap               { position: relative; display: inline-flex; align-items: center; }
.search-wrap .search-input { width: 280px; max-width: 100%; padding-right: 28px; }
.search-clear       { position: absolute; right: 6px; background: none; border: none;
                      cursor: pointer; color: var(--muted); font-size: 1.1rem;
                      padding: 2px 4px; border-radius: 50%; transition: color .15s; }
.search-clear:hover { color: var(--text); }

.filter-chip        { padding: 6px 12px; border-radius: 20px;
                      border: 1.5px solid var(--border);
                      font-size: .8rem; font-weight: 600; cursor: pointer;
                      white-space: nowrap; background: var(--surface);
                      color: var(--muted); transition: all .15s; }
.filter-chip:hover  { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- 10. Tablas --------------------------------------------------------- */

.table-card { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow);
              overflow-x: auto; overflow-y: hidden; }

table    { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead tr { background: var(--bg); }
th       { padding: 10px 14px; text-align: left;
           font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
           color: var(--muted); font-weight: 600;
           border-bottom: 1px solid var(--border); white-space: nowrap; }
td       { padding: 10px 14px; border-bottom: 1px solid var(--border);
           vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.row-clickable { cursor: pointer; }

tfoot td { background: var(--bg); color: var(--muted); font-size: .8rem;
           border-top: 1px solid var(--border); border-bottom: none; }

.actions     { display: flex; gap: 4px; }
.table-empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.td-img      { width: 40px; height: 40px; object-fit: cover;
               border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.td-nombre   { font-weight: 600; }
.td-id       { color: var(--muted); font-size: .8rem; }
.td-mono     { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
               font-size: .82rem; }
.td-num      { text-align: right; font-variant-numeric: tabular-nums; }
.td-corta    { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 11. Badges --------------------------------------------------------- */

.badge         { display: inline-block; padding: 2px 10px; white-space: nowrap;
                 border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-info    { background: rgba(59,130,246,.18); color: #93c5fd; }
.badge-success { background: rgba(34,197,94,.18);  color: #86efac; }
.badge-danger  { background: rgba(230,42,42,.2);   color: #f5a8a8; }
.badge-warn    { background: rgba(245,158,11,.18); color: #fcd34d; }
.badge-muted   { background: rgba(255,255,255,.08); color: var(--muted); }

/* ---- 12. Alerts --------------------------------------------------------- */

.alert         { border-radius: var(--radius); padding: 10px 12px;
                 font-size: .85rem; line-height: 1.5; margin-bottom: 14px;
                 border: 1px solid transparent; }
.alert-error   { background: rgba(230,42,42,.12);  color: #f5a8a8; border-color: rgba(230,42,42,.3); }
.alert-warn    { background: rgba(245,158,11,.12); color: #fcd34d; border-color: rgba(245,158,11,.3); }
.alert-info    { background: rgba(59,130,246,.12); color: #93c5fd; border-color: rgba(59,130,246,.3); }
.alert-success { background: rgba(34,197,94,.12);  color: #86efac; border-color: rgba(34,197,94,.3); }

/* ---- 13. Stat cards y grilla del dashboard ------------------------------ */

.stats-bar  { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 14px 20px;
              display: flex; flex-direction: column; gap: 2px;
              flex: 1; min-width: 140px; }
.stat-label { font-size: .75rem; color: var(--muted);
              text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.amber { color: var(--primary); }
.stat-value.green { color: var(--success); }
.stat-value.red   { color: var(--danger); }
.stat-value.warn  { color: var(--warn); }
.stat-value.info  { color: var(--info); }
.stat-hint  { font-size: .72rem; color: var(--muted); }

.dash-link  { cursor: pointer; transition: background .15s, border-color .15s; }
.stat-card.dash-link:hover { background: var(--row-hover); border-color: var(--primary); }

.dash-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 4px; }
.dash-table-header { padding: 14px 20px 10px; font-weight: 600; font-size: .95rem;
                     border-bottom: 1px solid var(--border);
                     display: flex; align-items: center; justify-content: space-between; }
.dash-ver-mas      { font-size: .78rem; font-weight: 500; color: var(--primary); cursor: pointer; }

/* ---- 14. Modales -------------------------------------------------------- */

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55);
                  display: flex; align-items: center; justify-content: center;
                  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s;
                  padding: 16px; }
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal { background: var(--surface); border-radius: 14px;
         width: 100%; max-width: 560px; max-height: 100%;
         box-shadow: var(--shadow-lg);
         transform: scale(.96) translateY(12px); transition: transform .2s;
         /* El scroll es del CUERPO, no del modal entero: asi la barra de
            titulo y la de acciones quedan fijas. Con el modal scrolleable, la
            salida se va de la vista justo cuando mas contenido hay. */
         overflow: hidden; display: flex; flex-direction: column; }
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-wide  { max-width: 820px; }
.modal-ancho { max-width: 1100px; }
.modal-alto  { height: 88vh; }

.modal-header, .modal-menubar { flex: 0 0 auto; }
.modal-body {
    flex: 1 1 auto;
    /* min-height:0 NO es opcional: un hijo flex no baja de su alto de
       contenido, asi que sin esto el overflow-y nunca se activa, el modal
       crece hasta el tope y la cabecera se va igual. */
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px; display: flex; flex-direction: column; gap: 16px;
}

.modal-header   { padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
                  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-title    { font-size: 1rem; font-weight: 700;
                  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.modal-subtitle { font-size: .8rem; font-weight: 500; color: var(--muted); }

/* 14-bis. Barra de titulo pintada en primary. Va JUNTO a .modal-header. */
.modal-header-primary {
    background: var(--primary); color: #fff;
    border-bottom: none;                  /* con el fondo pintado, la divisoria sobra */
    border-radius: 14px 14px 0 0;         /* mismo radio que el .modal */
    padding: 10px 24px;                   /* mas baja: arriba solo hay texto */
}
.modal-header-primary .modal-title       { color: #fff; }
.modal-header-primary .modal-subtitle    { color: rgba(255,255,255,.75); }
.modal-header-primary .btn-icon-sm,
.modal-header-primary .btn-ghost         { color: #fff; }
.modal-header-primary .btn-icon-sm:hover { background: rgba(255,255,255,.18); color: #fff; }

/* Barra de acciones, pegada debajo del titulo. TODOS los botones van aca:
   ningun modal del panel lleva footer. */
.modal-menubar {
    /* 14px, NO los 10 del titulo: aca hay botones de ~30px y con 10 quedan
       tocando el primary de arriba y la divisoria de abajo. */
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    /* Un escalon MAS OSCURO que el cuerpo. Es lo unico que separa la barra del
       contenido: debajo del border-bottom empieza el gris del cuerpo. La
       mezcla va entre tokens, no contra #000, asi el tono sigue al tema. */
    background: color-mix(in srgb, var(--surface) 40%, var(--bg));
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
/* La barra normaliza el tamano sola: ningun llamador se olvida el btn-sm. */
.modal-menubar .btn { white-space: nowrap; padding: 5px 12px; font-size: .8rem; }
/* La salida va RELLENA con el gris del cuerpo: sobre la franja mas oscura un
   ghost transparente se lee como un hueco al lado de los primary. Y su hover
   SUBE, en vez de bajar al color de la franja y desaparecer. */
.modal-menubar .btn-ghost       { background: var(--surface); color: var(--text); }
.modal-menubar .btn-ghost:hover { background: var(--row-hover); color: var(--text); }
.modal-menubar-end { margin-left: auto; }
.menubar-caret     { font-size: .7em; opacity: .65; margin-left: 2px; }

/* Cuando el cuerpo tiene una tabla larga, el scroll baja un nivel mas: el
   cuerpo deja de scrollear y scrollea solo el bloque .modal-scroll, asi las
   tarjetas de arriba quedan quietas. min-height:0 en cada eslabon. */
.modal-alto > .modal-body { overflow-y: hidden; }
.modal-scroll        { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.modal-scroll thead tr { position: sticky; top: 0; z-index: 1; background: var(--bg); }

/* Tarjetas de la vista de Consulta: sin borde, 10% mas oscuras que el modal.
   Son del modo CONSULTA; el de edicion usa .form-group sobre el fondo del
   modal -- un input dentro de una de estas se lee como un dato de solo lectura. */
.view-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.view-card  { background: color-mix(in srgb, var(--surface) 90%, #000);
              border: none; border-radius: var(--radius); padding: 10px 14px;
              display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.view-card.ancha { grid-column: 1 / -1; }
.view-label { font-size: .72rem; font-weight: 600; color: var(--muted);
              text-transform: uppercase; letter-spacing: .04em; }
.view-value { font-size: .9rem; color: var(--text); word-break: break-word; }
.view-value.vacia { color: var(--muted); font-style: italic; }
.view-value code  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
                    font-size: .82rem; background: var(--bg);
                    border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.view-html  { font-size: .88rem; line-height: 1.6; }
.view-html img { max-width: 100%; height: auto; border-radius: 8px; }
.view-foto  { width: 100%; max-width: 180px; border-radius: var(--radius);
              border: 1px solid var(--border); background: var(--bg); }

.modal-seccion { font-size: .78rem; font-weight: 700; color: var(--muted);
                 text-transform: uppercase; letter-spacing: .06em;
                 padding-top: 4px; }

/* ---- 15. Confirm dialog ------------------------------------------------- */
/* Es una pregunta, no una pantalla: conserva el formato clasico (sin barra de
   titulo pintada, sin menubar, botones abajo). Unica excepcion al estandar. */

.confirm-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6);
                    display: flex; align-items: center; justify-content: center;
                    z-index: 400; opacity: 0; pointer-events: none; transition: opacity .15s; }
.confirm-backdrop.open { opacity: 1; pointer-events: all; }
.confirm-box     { background: var(--surface); border-radius: 14px;
                   padding: 26px 26px 20px; max-width: 400px;
                   width: calc(100% - 32px); box-shadow: var(--shadow-lg);
                   transform: scale(.95); transition: transform .15s; }
.confirm-backdrop.open .confirm-box { transform: scale(1); }
.confirm-title   { font-weight: 700; margin-bottom: 8px; }
.confirm-msg     { font-size: .88rem; color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- 16. Toasts --------------------------------------------------------- */

.toast { position: fixed; bottom: 24px; left: 50%;
         transform: translateX(-50%) translateY(16px);
         background: #0d0d0d; color: var(--text);
         border: 1px solid var(--border);
         padding: 10px 20px; border-radius: 99px;
         font-size: .88rem; opacity: 0; pointer-events: none;
         transition: opacity .2s, transform .2s;
         z-index: 500; max-width: calc(100vw - 48px); text-align: center;
         box-shadow: var(--shadow-lg); }
.toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); border-color: var(--danger); color: #fff; }
.toast.ok    { border-color: rgba(34,197,94,.5); }

/* ---- 17. Toggle switches ------------------------------------------------ */

.toggle-switch { display: flex; align-items: center; gap: 12px;
                 cursor: pointer; user-select: none; }
.toggle-switch input { display: none; }
.toggle-track  { width: 44px; height: 24px; border-radius: 12px; flex-shrink: 0;
                 background: var(--border); position: relative; transition: background .2s; }
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-thumb  { position: absolute; top: 3px; left: 3px;
                 width: 18px; height: 18px; border-radius: 50%;
                 background: #fff; transition: transform .2s;
                 box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }
.toggle-label  { font-size: .9rem; color: var(--text); }

/* ---- 18. Spinner -------------------------------------------------------- */

.spin { display: inline-block; width: 28px; height: 28px;
        border: 3px solid var(--border); border-top-color: var(--primary);
        border-radius: 50%; animation: spin .7s linear infinite; }
.spin-sm { width: 15px; height: 15px; border-width: 2px; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 19. Tile grid (modulo Herramientas) -------------------------------- */

.tile-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
              gap: 16px; }
.tile-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 20px;
              display: flex; flex-direction: column; gap: 6px;
              text-align: left; cursor: pointer; color: var(--text);
              transition: border-color .15s, background .15s, transform .1s; }
.tile-card:hover  { border-color: var(--primary); background: var(--row-hover); }
.tile-card:active { transform: scale(.98); }
.tile-icon  { font-size: 1.6rem; line-height: 1; margin-bottom: 4px; }
.tile-title { font-weight: 600; font-size: .95rem; }
.tile-desc  { font-size: .8rem; color: var(--muted); line-height: 1.45; }

/* ---- 20. Menu contextual (filas del listado y barra de los modales) ----- */

.ctx-menu        { position: fixed; z-index: 300; display: none; min-width: 200px;
                   background: var(--surface); border: 1px solid var(--border);
                   border-radius: 10px; box-shadow: var(--shadow-lg);
                   overflow: hidden; padding: 4px 0; }
.ctx-menu.open   { display: block; }
.ctx-menu button { display: flex; align-items: center; gap: 10px; width: 100%;
                   padding: 8px 14px; background: none; border: none; cursor: pointer;
                   font-size: .85rem; color: var(--text); text-align: left; }
.ctx-menu button:hover:not(:disabled)   { background: var(--bg); color: var(--primary); }
.ctx-menu button:disabled               { opacity: .5; cursor: not-allowed; }
.ctx-menu button i                      { width: 14px; text-align: center; color: var(--muted); }
.ctx-menu button:hover:not(:disabled) i { color: inherit; }
.ctx-menu-sep    { height: 1px; background: var(--border); margin: 4px 0; }
.ctx-menu-group  { padding: 8px 14px 4px; font-size: .68rem; font-weight: 700;
                   text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ctx-menu-danger { color: var(--danger); }
.ctx-menu-danger:hover:not(:disabled),
.ctx-menu-danger:hover:not(:disabled) i { background: var(--danger) !important; color: #fff !important; }

/* ---- 21. Selector de items con switch (roles de un usuario, permisos de
           un rol) ------------------------------------------------------- */

.sel-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.sel-lista   { display: flex; flex-direction: column; gap: 6px;
               max-height: 320px; overflow-y: auto; padding-right: 4px; }
.sel-fila    { display: flex; align-items: center; gap: 12px;
               background: color-mix(in srgb, var(--surface) 90%, #000);
               border-radius: var(--radius); padding: 8px 12px; }
.sel-fila-texto  { flex: 1; min-width: 0; }
.sel-fila-nombre { font-size: .88rem; font-weight: 600; }
.sel-fila-detalle{ font-size: .76rem; color: var(--muted);
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-fila-codigo { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
                   font-size: .74rem; color: var(--muted); }
.sel-vacio   { font-size: .85rem; color: var(--muted); padding: 10px 2px; }

/* ---- 22. Editor de texto enriquecido ----------------------------------- */
/* contenteditable + document.execCommand. Sin librerias ni build step: es lo
   que reemplaza al Summernote del legacy, que llegaba por CDN. */

.editor        { border: 1px solid var(--border); border-radius: var(--radius);
                 overflow: hidden; background: var(--surface); }
.editor-barra  { display: flex; gap: 2px; flex-wrap: wrap; padding: 6px;
                 background: var(--bg); border-bottom: 1px solid var(--border); }
.editor-barra button { background: none; border: none; cursor: pointer;
                       color: var(--muted); padding: 5px 8px; border-radius: 6px;
                       font-size: .82rem; min-width: 30px;
                       transition: background .15s, color .15s; }
.editor-barra button:hover { background: var(--surface); color: var(--text); }
.editor-barra .editor-sep  { width: 1px; background: var(--border); margin: 3px 4px; }
.editor-area   { min-height: 220px; max-height: 420px; overflow-y: auto;
                 padding: 12px 14px; font-size: .9rem; line-height: 1.6;
                 outline: none; }
.editor-area:focus { box-shadow: inset 0 0 0 2px rgba(184,116,20,.25); }
.editor-area p         { margin-bottom: .7em; }
.editor-area h2        { font-size: 1.1rem; margin: .6em 0 .4em; }
.editor-area h3        { font-size: 1rem; margin: .6em 0 .4em; }
.editor-area ul,
.editor-area ol        { margin: 0 0 .7em 1.3em; }
.editor-area a         { color: var(--primary); text-decoration: underline; }
.editor-area img       { max-width: 100%; height: auto; border-radius: 8px; }
.editor-area:empty::before { content: attr(data-placeholder); color: var(--muted); }

/* ---- 22-bis. Selector con buscador (elegir un matriculado) ------------- */
/* El id del matriculado va en un hidden y lo que se ve es el nombre: un campo
   que muestra el numero y explica debajo "es el id del matriculado" es un dato
   escondido donde no se puede mirar. */

.picker        { position: relative; }
.picker-elegido{ display: flex; align-items: center; gap: 8px;
                 background: color-mix(in srgb, var(--surface) 90%, #000);
                 border: 1px solid var(--border); border-radius: var(--radius);
                 padding: 8px 12px; font-size: .88rem; }
.picker-elegido .crece { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-lista  { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
                 background: var(--surface); border: 1px solid var(--border);
                 border-radius: var(--radius); box-shadow: var(--shadow-lg);
                 max-height: 260px; overflow-y: auto; display: none; }
.picker-lista.open { display: block; }
.picker-item   { display: flex; align-items: baseline; gap: 10px; width: 100%;
                 padding: 8px 12px; background: none; border: none; cursor: pointer;
                 font-size: .85rem; color: var(--text); text-align: left; }
.picker-item:hover { background: var(--bg); color: var(--primary); }
.picker-item small { color: var(--muted); font-size: .75rem; }
.picker-vacio  { padding: 10px 12px; font-size: .82rem; color: var(--muted); }

/* ---- 23. Subida de archivos -------------------------------------------- */

.drop        { border: 1.5px dashed var(--border); border-radius: var(--radius);
               padding: 26px 18px; text-align: center; cursor: pointer;
               transition: border-color .15s, background .15s; }
.drop:hover,
.drop.sobre  { border-color: var(--primary); background: var(--row-hover); }
.drop-icono  { font-size: 1.8rem; color: var(--muted); margin-bottom: 8px; }
.drop-texto  { font-size: .88rem; }
.drop-ayuda  { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.drop-previa { max-width: 100%; max-height: 220px; border-radius: var(--radius);
               margin: 0 auto 10px; display: block; }

/* ---- 24. Consola de salida (herramientas) ------------------------------ */

.consola { background: #0d0d0d; border: 1px solid var(--border); border-radius: var(--radius);
           padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
           font-size: .78rem; line-height: 1.6; white-space: pre-wrap;
           max-height: 50vh; overflow-y: auto; color: var(--text); }
.consola .ok   { color: #86efac; }
.consola .mal  { color: #f5a8a8; }
.consola .avi  { color: #fcd34d; }
.consola .dim  { color: var(--muted); }

/* ---- 25. Pantallas de acceso (login / recuperar) ----------------------- */
/* Viven fuera del layout .layout: no tienen chrome. */

.acceso-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center;
                padding: 24px;
                background: radial-gradient(circle at 20% 0%, #2a2114 0%, var(--bg) 55%); }
.acceso-caja  { width: 100%; max-width: 400px; background: var(--surface);
                border: 1px solid var(--border); border-radius: 14px;
                box-shadow: var(--shadow-lg); overflow: hidden; }
.acceso-cabeza{ background: var(--primary); padding: 22px 26px; text-align: center; }
.acceso-cabeza img { height: 42px; width: auto; }
.acceso-cuerpo{ padding: 24px 26px 26px; display: flex; flex-direction: column; gap: 14px; }
.acceso-titulo{ font-size: 1.05rem; font-weight: 700; }
.acceso-bajada{ font-size: .84rem; color: var(--muted); line-height: 1.5; }
.acceso-pie   { display: flex; align-items: center; justify-content: space-between;
                gap: 10px; flex-wrap: wrap; }
.acceso-link  { font-size: .82rem; color: var(--primary); cursor: pointer; }
.acceso-link:hover { text-decoration: underline; }
.acceso-nota  { font-size: .72rem; color: var(--muted); text-align: center;
                margin-top: 14px; line-height: 1.5; }

/* ---- 26. Utilidades ---------------------------------------------------- */

.centro     { text-align: center; }
.derecha    { text-align: right; }
.fila       { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fila-fin   { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.crece      { flex: 1; }
.atenuado   { color: var(--muted); }
.mono       { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap     { white-space: nowrap; }
.oculto     { display: none !important; }
.cargando   { padding: 48px 24px; text-align: center; }

/* ---- 27. Responsive ---------------------------------------------------- */

.hamburger        { display: none; background: none; border: none; cursor: pointer;
                    font-size: 1.4rem; color: var(--text);
                    padding: 4px 8px; margin-right: 8px; line-height: 1; }
.sidebar-overlay  { display: none; position: fixed; inset: 0;
                    background: rgba(0,0,0,.45); z-index: 199; }
.sidebar-overlay.active { display: block; }

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

@media (max-width: 768px) {
    .hamburger { display: inline-flex; align-items: center; }
    .sidebar   { position: fixed; top: 0; left: 0; height: 100vh; z-index: 200;
                 transform: translateX(-100%); transition: transform .25s; }
    .sidebar.open { transform: translateX(0); }
    .content   { padding: 16px; }
    .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
    .view-grid { grid-template-columns: 1fr; }
    .search-wrap .search-input { width: 100%; }
    .search-wrap { flex: 1; }
    .topbar-entorno { display: none; }
    .modal-body, .modal-header, .modal-menubar { padding-left: 16px; padding-right: 16px; }
}
