/* ==========================================================================
   el proyecto Admin Panel — Component Styles
   ==========================================================================
   Design tokens are defined in _theme.css (loaded before this file).
   This file contains ONLY component/layout styles.
   ========================================================================== */

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body.admin-body {
    margin: 0;
    padding: 0;
    background: var(--page-glow, none) no-repeat fixed, var(--color-dark-bg);
    color: var(--color-text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.admin-layout {
    min-height: 100vh;
}

.admin-main {
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar-collapsed .admin-main {
    margin-left: var(--sidebar-collapsed-width);
}

.admin-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* Pantallas con resumen fijo a un lado (skill admin-ux): con
   overflow auto, .admin-content es el contenedor del sticky pero no hace
   scroll (lo hace el documento), y el resumen se va con la página. `clip`
   no crea contenedor de scroll y sigue sin dejar desbordar a lo ancho. */
.admin-content:has([data-sticky-aside]),
.admin-content:has([data-action-bar]) {
    overflow: visible;
    overflow-x: clip;
}

/* Barra de acciones de toda pantalla (_partials/_action_bar.html.twig, skill
   admin-ux patrón 10): fija al pie de la ventana mientras se hace
   scroll. Volver/deshacer/borrar a la izquierda, construir/guardar a la derecha.
   Requiere que .admin-content no sea contenedor de scroll (regla de arriba). */
.action-bar {
    position: sticky;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin: 24px -8px 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border: 1px solid var(--color-border);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    /* Plana y opaca: sin desenfoque ni sombra;
       la separa del contenido la línea fina de arriba. */
    background: var(--color-surface);
}

.action-bar-start,
.action-bar-end {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.action-bar-end {
    margin-left: auto;
}

/* Una barra dentro de un formulario: sin el borde/margen del pie clásico. */
form .action-bar { margin-top: 24px; }


/* Móvil: una sola fila. Todo botón con icono que no es la acción
   principal se queda en el icono (font-size 0: el texto sigue siendo su nombre
   accesible) y la principal ocupa el resto. */
@media (max-width: 640px) {
    .action-bar {
        flex-wrap: nowrap;
        gap: 8px;
        margin-left: 0;
        margin-right: 0;
        padding-left: 12px;
        padding-right: 12px;
    }
    .action-bar-start,
    .action-bar-end {
        flex-wrap: nowrap;
        gap: 8px;
    }
    .action-bar-end {
        flex: 1 1 auto;
        justify-content: flex-end;
        min-width: 0;
    }
    .action-bar .btn { padding-left: 12px; padding-right: 12px; }
    .action-bar .btn:has(> svg):not(.action-bar-main) {
        flex: 0 0 44px;
        width: 44px;
        padding: 0;
        gap: 0;
        justify-content: center;
        font-size: 0;
    }
    .action-bar .btn:has(> svg):not(.action-bar-main) > span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
    .action-bar .action-bar-main {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
    }
    .action-bar .action-bar-main > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* «Saltar al contenido»: fuera de la vista hasta que recibe el foco. */
.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 10002;
    padding: 10px 16px;
    border-radius: var(--radius-control);
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-200%);
}
.skip-link:focus {
    transform: none;
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.35);
}
.admin-content:focus { outline: none; }

/* ==========================================================================
   Sidebar
   ========================================================================== */

.admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: width var(--transition-speed) ease;
    overflow: hidden;
}

.sidebar-collapsed .admin-sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    display: flex;
    align-items: center;
    /* Misma altura que .admin-header: las dos líneas de abajo quedan alineadas. */
    height: var(--header-height);
    padding: 0 16px;
    border-bottom: 1px solid var(--color-border);
    gap: 12px;
    color: inherit;
    text-decoration: none;
    overflow: hidden;
}

/* Logotipo del kit: el horizontal con el lema; plegado, el símbolo.
   Claro en oscuro y verde noche en claro, como en el login (.login-lockup). */
.sidebar-lockup {
    display: block;
    height: 44px;
    width: auto;
}

.sidebar-symbol {
    display: none;
    width: 36px;
    height: 36px;
}

.sidebar-lockup--ink,
[data-theme="light"] .sidebar-lockup--white {
    display: none;
}

[data-theme="light"] .sidebar-lockup--ink {
    display: block;
}

.sidebar-collapsed .sidebar-lockup {
    display: none !important;
}

.sidebar-collapsed .sidebar-symbol--white {
    display: block;
}

[data-theme="light"] .sidebar-collapsed .sidebar-symbol--white {
    display: none;
}

[data-theme="light"] .sidebar-collapsed .sidebar-symbol--ink {
    display: block;
}

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

.sidebar-section-label {
    padding: 16px 20px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-collapsed .sidebar-section-label {
    opacity: 0;
}

.sidebar-divider {
    height: 1px;
    background: var(--color-border);
    margin: 8px 16px;
}

/* Grupos del menú por tareas: cabecera con la etiqueta de sección de la
   guía de estilo (§3: Inter 700, 0,68 rem, mayúsculas, gris) que pliega el grupo. */
.sidebar-section {
    border-top: 1px solid var(--color-separator);
    padding: 4px 0;
}

.sidebar-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 20px 6px;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-secondary);
    font-family: var(--font-family-base);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

.sidebar-section-toggle:hover {
    color: var(--color-text-primary);
}

.sidebar-section-toggle:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
    border-radius: var(--radius-tile);
}

.sidebar-section-chevron {
    display: inline-flex;
    transition: transform var(--transition-fast) ease;
}

.sidebar-section-chevron svg {
    width: 14px;
    height: 14px;
}

/* Plegado a iconos (solo escritorio; en el cajón del móvil el menú sale entero): sin
   cabeceras y con todos los grupos a la vista. */
@media (min-width: 1025px) {
    .sidebar-collapsed .sidebar-section-toggle {
        visibility: hidden;
        height: 8px;
        padding: 0;
    }

    .sidebar-collapsed .sidebar-section-items {
        display: block !important;
    }
}

/* Sobre la fila activa (ya teñida) el tinte de la insignia se suma y baja el contraste
   del texto de AA: la insignia va sobre la superficie. */
.sidebar-link.active .sidebar-badge-new,
.sidebar-link.active .badge-primary {
    background: var(--color-card-bg);
}

.sidebar-badge-new {
    padding: 1px 8px;
    border-radius: var(--radius-full);
    background: rgba(var(--color-primary-rgb), 0.14);
    color: var(--color-primary-text);
    font-size: 10px;
    font-weight: 700;
}

.sidebar-collapsed .sidebar-badge-new {
    display: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    gap: 12px;
    white-space: nowrap;
}

.sidebar-link:hover {
    background: rgba(var(--tint-rgb), 0.04);
    color: var(--color-text-primary);
    border-left-color: var(--color-secondary);
}

/* Entrada activa: fondo de la acción al 14 % y barra del acento;
   nunca un bloque entero del color de acción. */
.sidebar-link.active {
    background: rgba(var(--color-primary-rgb), 0.14);
    color: var(--color-primary-text);
    border-left-color: var(--color-primary-text);
}

.sidebar-link:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.sidebar-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link:hover svg,
.sidebar-link.active svg {
    opacity: 1;
}

.sidebar-link-text {
    overflow: hidden;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-collapsed .sidebar-link-text {
    opacity: 0;
    width: 0;
}

.sidebar-link.danger {
    color: var(--color-text-muted);
}

.sidebar-link.danger:hover {
    color: var(--color-tertiary);
    border-left-color: var(--color-tertiary);
}

/* Live Fleet special link */
.sidebar-link-live {
    position: relative;
}

.sidebar-link-live svg {
    color: var(--color-secondary);
    opacity: 1;
}

.sidebar-link-live:hover svg,
.sidebar-link-live.active svg {
    color: var(--color-secondary);
    opacity: 1;
}

.sidebar-link-live.active {
    background: rgba(var(--color-primary-rgb), 0.1);
    color: var(--color-secondary);
    border-left-color: var(--color-secondary);
}

/* Sidebar Submenu & Sublinks */
.sidebar-submenu {
    padding-left: 14px;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    margin-left: 20px;
    margin-top: 2px;
    margin-bottom: 6px;
}

.sidebar-sublink {
    padding: 7px 12px;
    font-size: 12.5px;
    border-left: none;
    border-radius: 6px;
    gap: 10px;
}

.sidebar-sublink svg {
    width: 15px;
    height: 15px;
}

.sidebar-sublink.active {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-primary);
    font-weight: 600;
}

.sidebar-footer {
    border-top: 1px solid var(--color-border);
    padding: 12px;
}

/* Sidebar toggle button */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.sidebar-toggle:hover {
    background: rgba(var(--tint-rgb), 0.04);
    color: var(--color-text-primary);
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-speed) ease;
}

.sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* ==========================================================================
   Header
   ========================================================================== */

.admin-header {
    position: sticky;
    top: 0;
    z-index: 9999;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--header-bg, var(--color-dark-bg));
    -webkit-backdrop-filter: var(--glass-blur, none);
    backdrop-filter: var(--glass-blur, none);
    border-bottom: 1px solid var(--color-border);
}

/* Título de la página en Poppins y, encima, las migas. */
.admin-header-heading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.admin-breadcrumb ol {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    margin: 0 0 2px;
    padding: 0;
    list-style: none;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Pages without a parent (Home, the lists) show only the title. */
.admin-breadcrumb:not(:has(li)) {
    display: none;
}

.admin-breadcrumb li + li::before {
    content: "›";
    margin-right: 6px;
    color: var(--color-text-muted);
}

.admin-breadcrumb a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.admin-breadcrumb a:hover {
    color: var(--color-primary-text);
}

.admin-breadcrumb a:focus-visible {
    outline: none;
    border-radius: 4px;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.admin-breadcrumb-back {
    display: none;
}

.admin-header-title {
    font-family: var(--font-family-heading);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text-primary);
    margin: 0;
    /* Titles may lead with an icon from the registry, so keep the SVG on the
       same baseline as the text instead of letting it sit inline. */
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-header-title svg {
    flex-shrink: 0;
}

.admin-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.admin-header-user {
    font-size: 13px;
    color: var(--color-text-secondary);
}

.admin-header-logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.15s ease;
}

.admin-header-logout:hover {
    color: var(--color-tertiary);
    border-color: var(--color-tertiary);
}

/* Mobile sidebar toggle */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 35;
}

/* ==========================================================================
   Cards & Containers
   ========================================================================== */

.admin-card {
    /* La tarjeta de Inicio de la app. */
    background: var(--color-card-translucent);
    -webkit-backdrop-filter: var(--glass-blur, none);
    backdrop-filter: var(--glass-blur, none);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    overflow: visible;
    /* Prevent clipping of dropdowns */
}

.admin-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.admin-card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.admin-card-body {
    padding: 20px;
}

/* Antigua tarjeta «de cristal» de las cifras: ahora es la misma tarjeta que
   .admin-card, con su relleno. */
.glass-card {
    background: var(--color-card-translucent);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 20px;
    transition: border-color 0.2s ease;
}

.glass-card:hover {
    border-color: var(--color-border-light);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.admin-table-wrap,
.admin-table-container {
    overflow-x: auto;
}

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

.admin-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    background: var(--color-thead-bg);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.admin-table thead th.text-right {
    text-align: right;
}

.admin-table tbody td {
    /* Una sola densidad: filas de 48 px como mínimo, texto 14 px. */
    height: 48px;
    padding: 8px 16px;
    font-size: 14px;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.admin-table tbody tr {
    transition: background 0.12s ease;
}

.admin-table tbody tr:hover {
    background: var(--color-pressed);
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-table .font-medium {
    color: var(--color-text-primary);
    font-weight: 500;
}

.admin-table .text-mono {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
}

/* Empty state */
.admin-empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--color-text-muted);
}

.admin-empty-state svg {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.4;
}

/* A list that failed to load must not read as a list that is legitimately empty. */
.admin-empty-state-error {
    color: var(--color-danger-text);
    font-weight: 500;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 9999px;
    white-space: nowrap;
}

.badge-primary {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-primary-text);
}

.badge-secondary {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-secondary-text);
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success-text);
}

.badge-danger {
    background: rgba(230, 57, 70, 0.15);
    color: var(--color-danger-text);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--color-warning-text);
}

.badge-muted {
    background: rgba(100, 116, 139, 0.2);
    color: var(--color-text-secondary);
}

.badge-info {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-secondary-text);
}

.badge-count {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-primary-text);
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 6px;
    margin-left: 8px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    /* Una sola forma de botón: radio 14, 44 px de
       alto, peso 600, sin mayúsculas ni sombra ni saltos. Variantes: principal
       (acción del tema), secundario (neutro con borde fino), discreto, peligro con
       borde, y solo icono (cuadrado). */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 18px;
    font-family: var(--font-family-base);
    font-size: 14px;
    font-weight: 600;
    text-transform: none;
    border-radius: var(--radius-control);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--transition-fast) ease, border-color var(--transition-fast) ease, color var(--transition-fast) ease;
    white-space: nowrap;
    line-height: 1.3;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
    border-radius: var(--radius-tile);
}

.btn-compact {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12px;
    height: 30px;
    border-radius: 10px;
}

/* Solo icono: cuadrado del mismo alto (lleva aria-label). */
.btn-icon {
    width: 44px;
    padding: 0;
}

.btn-sm.btn-icon {
    width: 36px;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: rgba(var(--tint-rgb), 0.08);
    border-color: rgba(var(--tint-rgb), 0.14);
    color: var(--color-text-primary);
}

.btn-secondary:hover {
    background: rgba(var(--tint-rgb), 0.12);
    border-color: rgba(var(--tint-rgb), 0.22);
}

/* Borrar de verdad tras confirmar (diálogos): el único botón rojo relleno. */
.btn-danger {
    background: var(--color-danger-dark);
    color: #ffffff;
}

.btn-danger:hover {
    background: var(--color-tertiary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}

.btn-ghost:hover {
    background: var(--color-pressed);
    color: var(--color-text-primary);
    border-color: var(--color-border-light);
}

.btn-danger-ghost {
    background: transparent;
    color: var(--color-danger-text);
    border-color: var(--color-danger);
}

.btn-danger-ghost:hover {
    background: var(--color-danger-light);
}

/* Aprobar / confirmar algo bueno (8 plantillas lo usaban sin que existiera). */
.btn-success {
    background: var(--color-success);
    color: var(--color-on-primary);
}

.btn-success:hover {
    background: var(--color-success-dark);
}

/* Action links (in tables) */
.action-link {
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.12s ease;
}

.action-link-show {
    color: var(--color-primary-text);
}

.action-link-show:hover {
    color: var(--color-primary-text-hover);
}

.action-link-edit {
    color: var(--color-purple-text);
}

.action-link-edit:hover {
    color: var(--color-purple-text-hover);
}

.action-link-delete {
    color: var(--color-danger-text);
}

.action-link-delete:hover {
    color: var(--color-danger-text-soft);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.admin-form label,
.admin-form .form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.admin-form input[type="text"],
.admin-form input[type="email"],
.admin-form input[type="password"],
.admin-form input[type="number"],
.admin-form input[type="tel"],
.admin-form input[type="url"],
.admin-form input[type="date"],
.admin-form input[type="datetime-local"],
.admin-form input[type="search"],
.admin-form input[type="time"],
.admin-form input[type="month"],
.admin-form input[type="week"],
.admin-form select,
.admin-form textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-control);
    color: var(--color-text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}

.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
    border-color: var(--color-primary-text);
    background: var(--color-input-bg-focus);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

/* El buscador nativo trae su aspa y su redondeo: se quitan para que sea un campo más. */
.admin-form input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
}
.admin-form input[type="search"]::-webkit-search-cancel-button,
.admin-form input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    display: none;
}

.admin-form input::placeholder,
.admin-form textarea::placeholder {
    color: var(--color-text-muted);
}

.admin-form select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 38px;
}

.admin-form select option {
    background: var(--color-card-bg);
    color: var(--color-text-primary);
}

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

/* Checkboxes */
.admin-form input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    border-radius: 4px;
    cursor: pointer;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check label {
    margin-bottom: 0;
    cursor: pointer;
    color: var(--color-text-primary);
    font-size: 14px;
}

/* Form errors */
.admin-form .form-error,
.admin-form .form-errors ul li {
    color: var(--color-danger-text);
    font-size: 12px;
    font-weight: 500;
    margin-top: 4px;
}

/* Campo con error del servidor (lo marca el form_theme) o de validations.js. */
.admin-form select.invalid,
.admin-form textarea.invalid {
    border-color: var(--color-danger) !important;
}

.validation-error {
    display: block;
    color: var(--color-danger-text-soft);
    /* Softer red (accordant to #f87171 but lighter on dark) */
    font-size: 10px;
    font-weight: 600;
    margin-top: 2px;
    min-height: 12px;
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

.validation-error.show {
    opacity: 1;
}

.admin-form input.invalid {
    border-color: var(--color-danger) !important;
}

.admin-form input.invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}

/* Password Toggle */
.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper input {
    padding-right: 40px !important;
}

.password-visibility-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease;
    z-index: 10;
}

.password-visibility-toggle:hover {
    color: var(--color-text-primary);
}

.password-visibility-toggle svg {
    width: 20px;
    height: 20px;
}

/* Input Suffix Pattern */
.input-with-suffix {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.input-with-suffix input {
    padding-right: 32px !important;
}

.input-suffix {
    position: absolute;
    right: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    pointer-events: none;
    user-select: none;
}

/* Password Strength Meter */
.password-strength-container {
    width: 100%;
}

.password-strength-bar {
    height: 6px;
    background: var(--color-dark-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
    border: 1px solid var(--color-border);
}

.strength-meter {
    height: 100%;
    width: 0;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.strength-text {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.strength-very-weak {
    background-color: var(--color-danger);
    width: 20%;
}

.strength-weak {
    background-color: #f97316;
    width: 40%;
}

.strength-medium {
    background-color: #eab308;
    width: 60%;
}

.strength-strong {
    background-color: #22c55e;
    width: 80%;
}

.strength-very-strong {
    background-color: #10b981;
    width: 100%;
}


.form-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
    margin-top: 24px;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.admin-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
}

.admin-pagination-info {
    font-size: 13px;
    color: var(--color-text-muted);
}

.admin-pagination-links {
    display: flex;
    gap: 4px;
}

.admin-pagination-links a,
.admin-pagination-links span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.12s ease;
}

.admin-pagination-links a {
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.admin-pagination-links a:hover {
    background: rgba(var(--tint-rgb), 0.04);
    color: var(--color-text-primary);
    border-color: var(--color-border-light);
}

.admin-pagination-links .active {
    background: var(--color-primary);
    color: var(--color-on-primary);
    border: 1px solid var(--color-primary);
}

/* ==========================================================================
   Flash Messages
   ========================================================================== */

.flash-message {
    /* Doc 49 §4.2 (T19): superficie de la tarjeta con el borde izquierdo del color de
       estado; el icono lleva ese color y el texto, el principal (contraste en los dos
       temas). Correcto e info se cierran solos; aviso y error, con su ×. */
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 12px 12px 16px;
    border: 1px solid var(--color-card-border);
    border-left-width: 4px;
    border-radius: var(--radius-control);
    background: var(--color-card-translucent);
    color: var(--color-text-primary);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.45;
    animation: flashSlideIn 0.3s ease-out;
    position: relative;
}

.flash-message svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.flash-icon {
    display: inline-flex;
    margin-top: 1px;
}

.flash-text {
    flex: 1;
    min-width: 0;
    white-space: pre-line;
}

.flash-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin: -6px -4px -6px 0;
    border: 0;
    border-radius: var(--radius-tile);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.flash-close:hover {
    background: var(--color-pressed);
    color: var(--color-text-primary);
}

.flash-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.flash-message.auto-dismiss {
    animation: flashSlideIn 0.3s ease-out, flashFadeOut 0.4s ease-in 4.6s forwards;
}

.flash-success { border-left-color: var(--color-success); }
.flash-success .flash-icon { color: var(--color-success-text); }
.flash-info { border-left-color: var(--color-info); }
.flash-info .flash-icon { color: var(--color-info-text); }
.flash-warning { border-left-color: var(--color-warning); }
.flash-warning .flash-icon { color: var(--color-warning-text); }
.flash-error { border-left-color: var(--color-danger); }
.flash-error .flash-icon { color: var(--color-danger-text); }

@keyframes flashSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes flashFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ==========================================================================
   Detail / Show Views
   ========================================================================== */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-item.full-width {
    grid-column: span 2;
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.detail-value {
    font-size: 14px;
    color: var(--color-text-primary);
}

.detail-value.mono {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 13px;
}

.detail-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}

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

.detail-row-label {
    font-size: 13px;
    color: var(--color-text-muted);
}

.detail-row-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-primary);
}

/* ==========================================================================
   Dashboard Stats
   ========================================================================== */

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon-blue {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-primary-text);
}

.stat-icon-green {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-secondary-text);
}

.stat-icon-purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--color-purple-text);
}

.stat-icon-red {
    background: rgba(230, 57, 70, 0.15);
    color: var(--color-danger-text);
}

.stat-icon-amber {
    background: rgba(245, 158, 11, 0.15);
    color: var(--color-warning-text);
}

.stat-icon-cyan {
    background: var(--color-info-light);
    color: var(--color-info-text);
}


/* ==========================================================================
   Estado del servidor: una baldosa por herramienta
   ========================================================================== */

/* Fila de la guía de estilo (§4): loseta de icono 40×40, título y subtítulo,
   flecha apagada; al pulsar, el fondo «pulsado». La tarjeta es .admin-card. */
.maintenance-tile {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    color: inherit;
    text-decoration: none;
    transition: background-color var(--transition-fast) ease, border-color var(--transition-fast) ease;
}

.maintenance-tile:hover {
    background: var(--color-card-translucent-hover);
    border-color: var(--color-border-light);
}

.maintenance-tile:active {
    background: var(--color-pressed);
}

.maintenance-tile:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.maintenance-tile-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-tile);
    background: var(--color-tile-bg);
    color: var(--color-tile-icon);
}

.maintenance-tile-title {
    display: block;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.maintenance-tile-desc {
    display: block;
    margin-top: 2px;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--color-text-secondary);
}

.maintenance-tile-arrow {
    flex-shrink: 0;
    margin-top: 11px;
    color: var(--color-text-muted);
}

/* Estado: píldora con el color de estado de fondo suave y texto del mismo tono
  , nunca solo el color del texto. */
.maintenance-tile-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(var(--tint-rgb), 0.06);
    color: var(--color-text-secondary);
}

.maintenance-tile-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: currentColor;
}

.maintenance-tile-status.is-ok {
    background: var(--color-success-light);
    color: var(--color-success-text);
}

.maintenance-tile-status.is-warning {
    background: var(--color-warning-light);
    color: var(--color-warning-text);
}

.maintenance-tile-status.is-error {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
}

/* ==========================================================================
   Login Page
   ========================================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--color-dark-bg);
    padding: 20px;
    gap: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-card-translucent);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 40px 36px;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.login-logo .login-lockup {
    width: 280px;
    height: auto;
}

.login-logo .login-lockup--ink,
[data-theme="light"] .login-logo .login-lockup--white {
    display: none;
}

[data-theme="light"] .login-logo .login-lockup--ink {
    display: block;
}

.login-alert {
    /* Misma receta que los avisos del panel: superficie de tarjeta
       con el borde izquierdo del color de estado. */
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border: 1px solid var(--color-card-border);
    border-left-width: 4px;
    border-radius: var(--radius-control);
    background: var(--color-card-translucent);
    color: var(--color-text-primary);
    font-size: 14px;
    line-height: 1.5;
    width: 100%;
    max-width: 420px;
    box-sizing: border-box;
    word-break: break-word;
}

.login-alert-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-alert-icon svg {
    width: 22px !important;
    height: 22px !important;
    display: block;
}

.login-alert-body {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.login-alert-body .btn {
    text-decoration: none;
}

.login-alert-success { border-left-color: var(--color-success); }
.login-alert-success .login-alert-icon { color: var(--color-success-text); }
.login-alert-error { border-left-color: var(--color-danger); }
.login-alert-error .login-alert-icon { color: var(--color-danger-text); }
.login-alert-warning { border-left-color: var(--color-warning); margin-bottom: 2rem; }
.login-alert-warning .login-alert-icon { color: var(--color-warning-text); }

.login-copyright {
    margin-top: 24px;
    text-align: center;
    font-size: 12px;
    color: var(--color-text-secondary);
}

.auth-remember {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.auth-submit {
    width: 100%;
    padding: 12px;
}

/* Authentication Layout */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    margin-top: 4px;
}

.auth-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-link:hover {
    text-decoration: underline;
}

.auth-divider {
    text-align: center;
    margin: 10px 0;
    color: var(--color-text-muted);
    font-size: 14px;
}

.auth-btn-google {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    background: #ffffff;
    color: var(--color-primary-text);
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.auth-btn-google:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.auth-btn-linkedin {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    background: #0077B5;
    color: #ffffff;
    border: 1px solid #0077B5;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.auth-btn-linkedin:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: var(--color-on-primary);
}

.auth-btn-facebook {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    background: #1877F2;
    color: #ffffff;
    border: 1px solid #1877F2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.auth-btn-facebook:hover {
    background: #0d65d9;
    border-color: #0d65d9;
    color: #ffffff;
}

/* Bulletproof Password Toggle */
.password-input-wrapper {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
}

.password-input-wrapper input {
    width: 100% !important;
    padding-right: 44px !important;
}

.password-visibility-toggle {
    position: absolute !important;
    right: 4px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 36px !important;
    height: 36px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--color-text-secondary) !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10 !important;
    outline: none !important;
    padding: 0 !important;
    margin: 0 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    transition: color 0.2s ease;
}

.password-visibility-toggle:hover {
    color: var(--color-text-primary) !important;
}

.password-visibility-toggle svg {
    width: 20px !important;
    height: 20px !important;
    stroke: currentColor !important;
    fill: none !important;
    pointer-events: none !important;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-speed) ease;
    }

    /* El cajón y su velo van por encima de la cabecera (z-index 9999): si no, la
       cabecera tapa el logotipo y las primeras entradas. */
    .sidebar-open .admin-sidebar {
        transform: translateX(0);
        width: var(--sidebar-width);
        z-index: 10001;
    }

    .sidebar-open .sidebar-overlay {
        display: block;
        z-index: 10000;
    }

    /* El plegado a iconos es de escritorio: en el cajón el menú sale siempre entero,
       aunque se dejara plegado en el ordenador. */
    .sidebar-collapsed .sidebar-link-text {
        opacity: 1;
        width: auto;
    }

    .sidebar-collapsed .sidebar-lockup--white {
        display: block !important;
    }

    [data-theme="light"] .sidebar-collapsed .sidebar-lockup--white,
    .sidebar-collapsed .sidebar-symbol {
        display: none !important;
    }

    [data-theme="light"] .sidebar-collapsed .sidebar-lockup--ink {
        display: block !important;
    }

    .sidebar-collapsed .sidebar-badge-new {
        display: inline;
    }

    .sidebar-toggle {
        display: none;
    }

    .admin-main {
        margin-left: 0 !important;
    }

    .mobile-menu-btn {
        display: flex;
    }

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

    .detail-item.full-width {
        grid-column: span 1;
    }
}

@media (max-width: 640px) {
    .admin-content {
        padding: 16px;
    }

    /* Un título largo (ficha de un grupo, de un gasto) no empuja el grupo de
       la derecha fuera de la pantalla: se corta con puntos suspensivos. */
    .admin-header-left { min-width: 0; flex: 1; }
    .admin-header-title {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
        font-size: 16px;
    }

    /* En el móvil, de las migas solo queda «‹ nivel anterior» (D17); el título,
       sin icono, para que quepa más texto. */
    .admin-header-title svg { display: none; }
    .admin-breadcrumb li { display: none; }
    .admin-breadcrumb li.is-back { display: list-item; }
    .admin-breadcrumb li.is-back::before { content: none; }
    .admin-breadcrumb-back { display: inline-block; }

    /* Para que el título quepa: en el móvil la cabecera solo enseña el avatar (el
       nombre sigue en el menú de usuario) y junta un poco los botones. */
    .admin-header { padding: 0 12px; }
    .admin-header-right { gap: 8px; }
    .user-profile-btn .user-name,
    .user-profile-btn .user-chevron { display: none; }

    .admin-card-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .admin-table thead th,
    .admin-table tbody td {
        padding-left: 12px;
        padding-right: 12px;
    }

    .form-footer {
        flex-direction: column;
    }

    .form-footer .btn {
        width: 100%;
    }

    .admin-pagination {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-primary {
    color: var(--color-primary);
}

.text-secondary {
    color: var(--color-secondary);
}

.text-danger {
    color: var(--color-tertiary);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-xs {
    font-size: 12px;
}

.text-sm {
    font-size: 14px;
}

.font-mono {
    font-family: 'SF Mono', 'Consolas', monospace;
}

.font-medium {
    font-weight: 500;
}

.font-bold {
    font-weight: 700;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ==========================================================================
   DataTable - Async Paginated/Sortable/Searchable Tables
   ========================================================================== */

.dt-container {
    position: relative;
}

.dt-toolbar {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    gap: 8px;
}

/* Baldosas de estado con contador que filtran. */
.dt-tiles {
    display: flex;
    gap: 8px;
    padding: 16px 20px 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.dt-tiles::-webkit-scrollbar { display: none; }

.dt-tile {
    display: inline-flex;
    flex-direction: row;
    align-items: baseline;
    flex-shrink: 0;
    gap: 8px;
    padding: 7px 14px;
    white-space: nowrap;
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-tile);
    background: rgba(var(--tint-rgb), 0.03);
    color: var(--color-text-secondary);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition-fast) ease, background-color var(--transition-fast) ease;
}
.dt-tile:hover { background: var(--color-pressed); }
.dt-tile:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25); }
.dt-tile-count {
    font-family: var(--font-family-heading);
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text-primary);
}
.dt-tile-label { font-size: 0.78rem; font-weight: 600; }
.dt-tile.is-active {
    border-color: var(--color-primary-text);
    background: rgba(var(--color-primary-rgb), 0.14);
    color: var(--color-primary-text);
}
.dt-tile--success .dt-tile-count { color: var(--color-success-text); }
.dt-tile--warning .dt-tile-count { color: var(--color-warning-text); }
.dt-tile--danger .dt-tile-count { color: var(--color-danger-text); }
.dt-tile--info .dt-tile-count { color: var(--color-info-text); }

/* «Limpiar filtros (N)»: solo con algún filtro puesto. */
.dt-clear-filters[hidden] { display: none; }

/* Barra fija «N seleccionados» con las acciones en lote, por encima de la barra de acciones. */
.dt-selection-bar {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 32px);
    padding: 8px 8px 8px 18px;
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
    transform: translateX(-50%);
}
.dt-selection-bar[hidden] { display: none; }
.dt-selection-count {
    font-weight: 700;
    white-space: nowrap;
    color: var(--color-text-primary);
}
.dt-selection-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
@media (max-width: 640px) {
    .dt-selection-bar { left: 16px; right: 16px; flex-wrap: wrap; transform: none; }
}

/* Toolbar: one row with the search first, the filters right next to it and
   «Clear filters» at the end. «Show N rows» is in the footer. */
.dt-toolbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

@media (min-width: 768px) {
    .dt-search { flex: 0 1 300px; }
    .dt-search-input { width: 100%; }
    .dt-filters { flex-wrap: wrap; }
    .dt-filters:empty { display: none; }
    .dt-clear-filters { margin-left: auto; }
    .dt-filters .panel-select-control.dt-filter-select,
    .dt-filters .searchable-select-control { min-height: 36px; height: 36px; }
}

.dt-per-page {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.dt-per-page-select {
    padding: 6px 32px 6px 10px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    color: var(--color-text-primary);
    font-size: 13px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
    cursor: pointer;
    outline: none;
}

.dt-per-page-select:focus {
    border-color: var(--color-primary);
}

.dt-per-page-select option {
    background: var(--color-card-bg);
    color: var(--color-text-primary);
}

.dt-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    transition: border-color 0.15s ease;
}

.dt-search:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

.dt-search svg {
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.dt-search-input {
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 13px;
    outline: none;
    width: 180px;
    font-family: inherit;
}

.dt-search-input::placeholder {
    color: var(--color-text-muted);
}

.dt-filters {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dt-filter-select {
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    color: var(--color-text-primary);
    font-size: 12px;
    padding: 6px 32px 6px 10px;
    outline: none;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
}

.dt-filter-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

/* ── SearchableSelect: desplegable con buscador para catálogos largos ────────
   Se usa en los filtros de las tablas (AdminDataTable) y en cualquier vista que
   necesite elegir entre cientos o miles de valores. */
.searchable-select {
    position: relative;
    display: inline-block;
}

.searchable-select-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 150px;
    max-width: 240px;
    height: 34px;
    padding: 6px 10px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease;
}

.searchable-select.has-value .searchable-select-control {
    color: var(--color-text-primary);
    border-color: var(--color-primary);
}

.searchable-select-control:hover {
    border-color: var(--color-primary);
}

.searchable-select-control:focus-visible {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

.searchable-select-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.searchable-select-arrow {
    display: flex;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    color: var(--color-text-muted);
    transition: transform 0.15s ease;
}

.searchable-select-arrow svg {
    width: 100%;
    height: 100%;
}

.searchable-select.open .searchable-select-arrow {
    transform: rotate(180deg);
}

.searchable-select-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    min-width: 100%;
    width: max-content;
    max-width: 320px;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

/* `display: flex` gana a la regla `[hidden] { display: none }` del navegador,
   así que el panel necesita apagarse explícitamente o nace abierto. */
.searchable-select-panel[hidden],
.searchable-select-footer[hidden] {
    display: none;
}

.searchable-select-search-wrap {
    padding: 8px;
    border-bottom: 1px solid var(--color-border-light);
}

.searchable-select-search {
    width: 100%;
    padding: 6px 10px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    color: var(--color-text-primary);
    font-family: inherit;
    font-size: 12px;
    outline: none;
}

.searchable-select-search:focus {
    border-color: var(--color-primary);
}

.searchable-select-options {
    max-height: 260px;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    list-style: none;
}

.searchable-select-option {
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--color-text-primary);
    font-size: 12px;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.searchable-select-option.is-clear {
    color: var(--color-text-muted);
    font-style: italic;
}

.searchable-select-option.active {
    background: var(--color-input-bg-focus);
}

.searchable-select-option.selected {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.searchable-select-empty {
    padding: 12px 10px;
    color: var(--color-text-muted);
    font-size: 12px;
    text-align: center;
    list-style: none;
}

.searchable-select-footer {
    padding: 7px 10px;
    border-top: 1px solid var(--color-border-light);
    background: var(--color-input-bg-focus);
    color: var(--color-text-muted);
    font-size: 11px;
    text-align: center;
}

.searchable-select-options::-webkit-scrollbar {
    width: 6px;
}

.searchable-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.searchable-select-options::-webkit-scrollbar-thumb {
    background: var(--color-border-light);
    border-radius: 3px;
}

.dt-filter-date-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    padding: 0 10px;
    height: 34px;
}

.dt-filter-date-wrap label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.dt-filter-date {
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 12px;
    outline: none;
    font-family: inherit;
    cursor: pointer;
    width: 115px;
}

.dt-filter-date::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.5;
    cursor: pointer;
}

/* Sort indicators */
.dt-sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 24px !important;
}

.dt-sortable::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--color-text-muted);
    opacity: 0.3;
}

.dt-sortable:hover::after {
    opacity: 0.6;
}

.dt-sortable.dt-sort-asc::after {
    border-top: none;
    border-bottom: 4px solid var(--color-primary);
    opacity: 1;
}

.dt-sortable.dt-sort-desc::after {
    border-top: 4px solid var(--color-primary);
    opacity: 1;
}

.dt-sortable:hover {
    color: var(--color-text-secondary);
}

/* Footer */
.dt-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
}

.dt-footer { gap: 12px; flex-wrap: wrap; }

.dt-footer-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 20px;
}

.dt-info {
    font-size: 13px;
    color: var(--color-text-muted);
}

.dt-pagination {
    display: flex;
    gap: 4px;
}

.dt-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    text-decoration: none;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    transition: all 0.12s ease;
}

.dt-page-btn:hover {
    background: rgba(var(--tint-rgb), 0.04);
    color: var(--color-text-primary);
    border-color: var(--color-border-light);
}

.dt-page-btn.active {
    background: var(--color-primary);
    color: var(--color-on-primary);
    border-color: var(--color-primary);
}

.dt-page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* Loading overlay */
.dt-loading {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--color-loading-overlay);
    z-index: 10;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.dt-loading.active {
    display: flex;
}

.dt-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: dtSpin 0.7s linear infinite;
}

@keyframes dtSpin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   DataTable Action Buttons (Icon-based)
   ========================================================================== */

.dt-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

/* ── Avatar en la primera columna de una tabla ──────────────────────────────
   La foto identifica una fila antes que cualquier texto. Quien no tiene sale
   con sus iniciales sobre un color derivado de su id (estable: la misma
   persona siempre es del mismo color), nunca con un hueco ni una imagen rota. */
.dt-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    /* El preflight de Tailwind da a img max-width:100%: en una celda eso anula
       el ancho mínimo y, si todas las filas visibles tienen foto, la columna
       se estrecha y aplasta el círculo. */
    min-width: 36px;
    max-width: none;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--color-border);
    background: var(--color-surface-2, rgba(148, 163, 184, 0.15));
    vertical-align: middle;
    flex-shrink: 0;
}

.dt-avatar-initials {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.4px;
    color: #ffffff;
    border-color: transparent;
    user-select: none;
}

.dt-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--color-text-muted);
    text-decoration: none;
    padding: 0;
    font-size: 0;
}

.dt-action-btn:hover {
    background: rgba(var(--tint-rgb), 0.06);
    border-color: var(--color-border-light);
}

.dt-action-show:hover {
    color: var(--color-primary-text);
    border-color: rgba(var(--color-primary-rgb), 0.3);
}

.dt-action-edit:hover {
    color: var(--color-purple-text);
    border-color: rgba(167, 139, 250, 0.3);
}

.dt-action-delete:hover {
    color: var(--color-danger-text);
    border-color: rgba(248, 113, 113, 0.3);
    background: rgba(230, 57, 70, 0.08);
}

.dt-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Force logout button */
.dt-action-logout:hover {
    color: var(--color-warning-text);
    border-color: rgba(251, 191, 36, 0.3);
    background: rgba(245, 158, 11, 0.08);
}


/* ==========================================================================
   Force Logout Status
   ========================================================================== */

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot-online {
    background: var(--color-success-text);
    box-shadow: none;
}

.status-dot-offline {
    background: var(--color-text-muted);
}

.force-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 4px;
    border: 1px solid rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.08);
    color: var(--color-warning-text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.force-logout-btn:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.5);
}

.force-logout-all-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.08);
    color: var(--color-warning-text);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.force-logout-all-btn:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.5);
}

/* ==========================================================================
   Responsive DataTable: por debajo de 768 px cada fila es una
   tarjeta (título, dos datos con su etiqueta, estado arriba a la derecha y las
   acciones abajo) que abre la ficha al tocarla; los filtros van en un panel que
   se despliega con «Filtros (N)». Los papeles los pone AdminDataTable en cada
   celda (dt-cell--title|meta|status|hidden|select|actions).
   ========================================================================== */

.dt-filters-toggle { display: none; }

@media (max-width: 767px) {
    /* La tarjeta de la página ya da el margen: la tabla no añade el suyo a los lados. */
    .dt-toolbar {
        padding: 4px 0 12px;
        gap: 10px;
    }
    .dt-per-page { display: none; }
    .dt-search {
        order: 1;
        flex: 1 1 100%;
    }
    .dt-search-input { width: 100%; }
    .dt-filters-toggle:not([hidden]) { display: inline-flex; order: 2; }
    .dt-clear-filters { order: 3; }
    .dt-filters {
        order: 4;
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .dt-filters.is-open { display: flex; }
    .dt-filters > *,
    .dt-filters .dt-filter-select { width: 100%; }
    .dt-tiles { padding: 0 0 4px; }

    .dt-container .admin-table-wrap { overflow: visible; }
    .dt-container .admin-table thead { display: none; }
    .dt-container .admin-table,
    .dt-container .admin-table tbody { display: block; }
    .dt-container .admin-table tbody tr {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        gap: 4px 0;
        padding: 14px 0;
        border-bottom: 1px solid var(--color-border);
        cursor: pointer;
    }
    .dt-container .admin-table tbody tr:last-child { border-bottom: none; }
    .dt-container .admin-table tbody tr.dt-empty-row {
        display: block;
        cursor: default;
    }
    .dt-container .admin-table tbody td {
        display: block;
        height: auto;
        padding: 0;
        border: 0;
        text-align: left;
        min-width: 0;
    }
    .dt-container .admin-table tbody tr.dt-empty-row td { padding: 0; }
    .dt-container .admin-table td.dt-cell--hidden { display: none; }
    .dt-container .admin-table td.dt-cell--select {
        grid-column: 1;
        grid-row: 1;
        margin-right: 12px;
    }
    .dt-container .admin-table td.dt-cell--title {
        grid-column: 2;
        grid-row: 1;
        font-size: 15px;
        font-weight: 600;
        color: var(--color-text-primary);
    }
    .dt-container .admin-table td.dt-cell--status {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        margin-left: 12px;
    }
    .dt-container .admin-table td.dt-cell--meta {
        grid-column: 2 / -1;
        font-size: 13px;
    }
    .dt-container .admin-table td.dt-cell--meta::before {
        content: attr(data-label) " · ";
        color: var(--color-text-muted);
    }
    .dt-container .admin-table td.dt-cell--meta[data-label=""]::before { content: none; }
    .dt-container .admin-table td.dt-cell--actions {
        grid-column: 2 / -1;
        justify-self: end;
        margin-top: 6px;
    }
    .dt-container .admin-table td.dt-cell--actions .dt-action-btn {
        width: 40px;
        height: 40px;
    }
    /* «Ver» ya es tocar la tarjeta: fuera, y la fila de acciones solo si queda otra. */
    .dt-container .admin-table td.dt-cell--actions .dt-action-show { display: none; }
    .dt-container .admin-table td.dt-cell--actions:not(:has(.dt-action-btn:not(.dt-action-show), .btn, a:not(.dt-action-show), button)) { display: none; }
    /* Una dato sin valor no se enseña con su etiqueta sola. */
    .dt-container .admin-table td.dt-cell--meta:empty { display: none; }

    .dt-footer {
        flex-direction: column;
        gap: 12px;
        align-items: center;
        padding: 12px 0 4px;
    }
}

/* ==========================================================================
   Tabs
   ========================================================================== */

.admin-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 24px;
    /* Pestañas en una sola línea: si no caben, se desplazan en horizontal. */
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
}

.admin-tabs > .admin-tab-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.admin-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition-speed);
}

.admin-tab-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(1);
}

.admin-tab-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.admin-tab-btn:hover {
    color: var(--color-text-secondary);
}

/* Pestaña activa: fondo de acción al 14 % y texto del acento. */
.admin-tab-btn.active {
    color: var(--color-primary-text);
    border-bottom-color: var(--color-primary-text);
    background: rgba(var(--color-primary-rgb), 0.14);
    border-radius: 10px 10px 0 0;
}

/* Contador dentro de una pestaña: legible en los dos temas y en la activa. */
.admin-tab-btn .badge {
    color: var(--color-text-secondary);
}
.admin-tab-btn.active .badge {
    color: var(--color-primary-text);
}

.admin-tab-btn.has-error {
    color: var(--color-danger, #f43f5e);
}

.admin-tab-content {
    display: none;
}

.admin-tab-content.active {
    display: block;
}

/* ==========================================================================
   Inline Add Forms
   ========================================================================== */

.inline-add-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 12px 16px;
    background: var(--color-surface);
    border-radius: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.inline-add-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 140px;
}

.inline-add-form .form-group label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.inline-add-form .form-group input,
.inline-add-form .form-group select {
    padding: 6px 10px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-primary);
    font-size: 0.8125rem;
}

.inline-add-form .form-group input:focus,
.inline-add-form .form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.inline-add-form .btn-add {
    padding: 6px 16px;
    background: var(--color-primary);
    color: var(--color-on-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition-speed);
}

.inline-add-form .btn-add:hover {
    background: var(--color-primary-hover);
}

/* ==========================================================================
   Sub-entity Tables
   ========================================================================== */

.sub-entity-table {
    width: 100%;
    border-collapse: collapse;
}

.sub-entity-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
}

.sub-entity-table td {
    padding: 10px 12px;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
}

.sub-entity-table tr:last-child td {
    border-bottom: none;
}

.sub-entity-table .btn-delete-row {
    padding: 4px 8px;
    background: none;
    border: 1px solid var(--color-tertiary);
    color: var(--color-tertiary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity var(--transition-speed), background var(--transition-speed);
}

.sub-entity-table .btn-delete-row:hover {
    opacity: 1;
    background: rgba(230, 57, 70, 0.1);
}

.sub-entity-empty {
    padding: 24px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ==========================================================================
   Gallery Grid
   ========================================================================== */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.gallery-item {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gallery-item-path {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    word-break: break-all;
}

.gallery-item-label {
    font-size: 0.8125rem;
    color: var(--color-text-primary);
}

.gallery-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.gallery-item .btn-delete-row {
    padding: 4px 8px;
    background: none;
    border: 1px solid var(--color-tertiary);
    color: var(--color-tertiary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity var(--transition-speed), background var(--transition-speed);
    align-self: flex-end;
}

.gallery-item .btn-delete-row:hover {
    opacity: 1;
    background: rgba(230, 57, 70, 0.1);
}

/* ==========================================================================
   Form Sections
   ========================================================================== */

.form-section {
    padding: 16px;
    background: var(--color-surface);
    border-radius: 8px;
    margin-bottom: 16px;
}

/* ==========================================================================
   Header Components (Refactored)
   ========================================================================== */

.admin-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* User Profile Container */
.user-profile-container {
    position: relative;
}

.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.theme-toggle-btn:hover {
    background: var(--sidebar-item-hover);
    color: var(--color-text-primary);
}

.theme-toggle-btn span {
    display: inline-flex;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-profile-btn:hover {
    background: rgba(var(--tint-rgb), 0.04);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: var(--color-on-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Avatar Upload Component */
.avatar-upload-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px 0;
}

.avatar-edit-wrapper {
    position: relative;
    width: 130px;
    height: 130px;
}

.avatar-preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 3px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-fast);
}

.avatar-edit-wrapper:hover .avatar-preview {
    border-color: var(--color-primary);
    transform: scale(1.02);
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-preview svg {
    width: 60px;
    height: 60px;
    color: var(--color-text-muted);
}

.avatar-edit-btn {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 42px;
    height: 42px;
    background: var(--color-dark-bg);
    color: var(--color-text-primary);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--color-dark-bg);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}

.avatar-edit-btn:hover {
    background: var(--color-primary);
    transform: scale(1.1);
}

.avatar-edit-btn svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    display: block;
}

.avatar-hint {
    font-size: 11px;
    color: var(--color-text-muted);
    text-align: center;
    max-width: 180px;
    line-height: 1.4;
}

.hidden {
    display: none;
}

.user-name {
    font-weight: 600;
    color: var(--color-text-primary);
    font-size: 14px;
}

.user-chevron {
    color: var(--color-text-muted);
}

.user-chevron svg {
    width: 16px;
    height: 16px;
}

/* Contador de la campana: rojo oscuro para que el número blanco pase AA. */
.header-count {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--color-danger-dark);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Buscador de pantallas. Por encima de la cabecera
   (9999) y por debajo de las ayudas guiadas (100100). */
.palette-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 10px 0 12px;
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-full);
    background: rgba(var(--tint-rgb), 0.04);
    color: var(--color-text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.palette-trigger:hover {
    color: var(--color-text-primary);
    background: var(--color-pressed);
}

.palette-trigger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.palette-trigger-kbd,
.palette-esc {
    padding: 1px 6px;
    border: 1px solid var(--color-card-border);
    border-radius: 6px;
    font-family: var(--font-family-base);
    font-size: 0.7rem;
    color: var(--color-text-muted);
}

.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh 16px 16px;
    background: rgba(10, 31, 29, 0.7);
}

.palette-backdrop[hidden] {
    display: none;
}

.palette {
    width: 100%;
    max-width: 560px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--color-card-bg);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.palette-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-separator);
    color: var(--color-text-secondary);
}

.palette-input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--color-text-primary);
    font-family: var(--font-family-base);
    font-size: 1rem;
}

.palette-input::placeholder {
    color: var(--color-text-muted);
}

.palette-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
}

.palette-option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: var(--radius-tile);
    cursor: pointer;
    color: var(--color-text-primary);
}

.palette-option.is-active {
    background: rgba(var(--color-primary-rgb), 0.14);
}

.palette-option-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--color-tile-bg);
    color: var(--color-tile-icon);
}

.palette-option-icon svg {
    width: 16px;
    height: 16px;
}

.palette-option-label {
    flex: 1;
    min-width: 0;
    font-size: 0.92rem;
    font-weight: 600;
}

.palette-option-group {
    font-size: 0.72rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Paso 2 (T56): cabecera de cada tipo y segunda línea de la ficha. */
.palette-group-label {
    padding: 10px 10px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.palette-option-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.palette-option-text .palette-option-label,
.palette-option-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-option-sub {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.palette-status {
    margin: 0;
    padding: 0 16px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.palette-status:not(:empty) {
    padding: 8px 16px 10px;
}

.palette-empty {
    margin: 0;
    padding: 18px 16px;
    font-size: 0.88rem;
    color: var(--color-text-secondary);
}

.palette-hint {
    margin: 0;
    padding: 10px 16px;
    border-top: 1px solid var(--color-separator);
    font-size: 0.72rem;
    color: var(--color-text-secondary);
}

@media (max-width: 640px) {
    .palette-trigger { padding: 0 10px; }
    .palette-trigger-label,
    .palette-trigger-kbd,
    .palette-hint,
    .palette-esc { display: none; }
    .palette-backdrop { padding-top: 8px; }
}

/* Menú de usuario: se abre con clic o teclado (Alpine), no al pasar. */
.user-profile-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.user-chevron {
    display: inline-flex;
    transition: transform var(--transition-fast) ease;
}

.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 240px;
    background: var(--color-card-bg);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-control);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    padding: 8px 0;
}

.profile-dropdown-head {
    display: flex;
    flex-direction: column;
    padding: 6px 16px 10px;
    border-bottom: 1px solid var(--color-separator);
    margin-bottom: 6px;
}

.profile-dropdown-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-text-primary);
}

.profile-dropdown-email {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-dropdown-label {
    padding: 4px 16px 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.profile-dropdown-langs {
    display: flex;
    gap: 6px;
    padding: 0 16px 6px;
}

.profile-dropdown-lang {
    flex: 1;
    min-height: 36px;
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.profile-dropdown-lang:hover {
    color: var(--color-text-primary);
    background: var(--color-pressed);
}

.profile-dropdown-lang.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-on-primary);
}

.profile-dropdown-item:focus-visible,
.profile-dropdown-lang:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.profile-dropdown.active {
    display: block;
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.profile-dropdown-item svg {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.profile-dropdown-item:hover {
    background: rgba(var(--tint-rgb), 0.05);
}

.profile-dropdown-item:hover svg {
    opacity: 1;
}

.profile-dropdown-item--danger {
    color: var(--color-danger-text);
}

.profile-dropdown-item--danger:hover {
    background: rgba(230, 57, 70, 0.1);
}

.profile-dropdown-item--warning {
    color: var(--color-warning-text);
}

.profile-dropdown-item--warning:hover {
    background: rgba(245, 158, 11, 0.1);
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--color-border-light);
    margin: 8px 0;
}

/* ==========================================================================
   SVG Icons Base Styles
   ========================================================================== */

.sidebar-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link:hover svg,
.sidebar-link.active svg {
    opacity: 1;
}

/* Flash message fade out animation */
.flash-fade-out {
    opacity: 0;
    transform: translateY(-8px);
    transition: all 0.4s ease-out;
}

/* ==========================================================================
   Switch Component (for forms)
   ========================================================================== */

.switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(var(--tint-rgb), 0.03);
    border-radius: 10px;
    transition: all 0.2s;
    border: 1px solid rgba(var(--tint-rgb), 0.05);
    cursor: pointer;
    gap: 12px;
    min-width: max-content;
    /* Ensure items don't squash and overlap */
}

.switch-container:hover {
    background: rgba(var(--tint-rgb), 0.06);
    border-color: rgba(var(--tint-rgb), 0.1);
}

.switch-container input {
    display: none;
}

.switch-label {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    font-family: var(--font-family-mono);
    user-select: none;
    white-space: nowrap;
    /* Keep on one line but don't internal scroll */
    overflow-x: auto;
    scrollbar-width: none;
    /* Hide scrollbar Firefox */
    -ms-overflow-style: none;
    /* Hide scrollbar IE/Edge */
}

.switch-label::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar Chrome/Safari/Brave */
}

.switch-toggle {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--color-switch-track);
    border-radius: 20px;
    transition: background 0.3s;
}

.switch-toggle::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 2px;
    left: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.switch-container input:checked~.switch-toggle {
    background: var(--color-secondary);
}

.switch-container input:checked~.switch-toggle::after {
    transform: translateX(16px);
}

/* ==========================================================================
   Dashboard Stats Additions
   ========================================================================== */

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 1rem;
}

/* ==========================================================================
   Maintenance Page Buttons (Refactored)
   ========================================================================== */

.btn-warning {
    background: var(--color-warning-light);
    color: var(--color-warning-text);
    border-color: var(--color-warning);
}

.btn-warning:hover {
    background: var(--color-warning-light);
    border-color: var(--color-warning-text);
}

.btn-danger-strong {
    background: rgba(230, 57, 70, 0.3);
    color: var(--color-danger-text-soft);
    border: 1px solid rgba(230, 57, 70, 0.5);
}

.btn-danger-strong:hover {
    background: rgba(230, 57, 70, 0.4);
    border-color: rgba(230, 57, 70, 0.7);
}

/* ==========================================================================
   Additional Utility Classes
   ========================================================================== */

.btn-full {
    width: 100%;
}

.admin-card-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ==========================================================================
   Form Utilities
   ========================================================================== */

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ==========================================================================
   Size Constraints
   ========================================================================== */

.max-w-xl {
    max-width: 36rem;
}

.max-w-2xl {
    max-width: 42rem;
}

.max-w-3xl {
    max-width: 48rem;
}

.w-full {
    width: 100%;
}

/* ==========================================================================
   Permission Groups (Role Editor)
   ========================================================================== */

.permission-group {
    margin-bottom: 24px;
    border-radius: 12px;
    background: rgba(var(--tint-rgb), 0.02);
    overflow-x: auto;
    /* Allow horizontal scroll if content is too wide */
    overflow-y: visible;
    /* Important for tooltips */
    border: 1px solid rgba(var(--tint-rgb), 0.05);
    position: relative;
}

.permission-group-header {
    background: rgba(var(--tint-rgb), 0.05);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(var(--tint-rgb), 0.05);
}

.permission-group-title {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-secondary);
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    padding: 12px;
    padding-top: 45px;
    /* Create space for tooltips on the first row */
}

@media (min-width: 640px) {
    .permission-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .permission-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.toggle-all-btn {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--color-text-dim);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.toggle-all-btn:hover {
    color: var(--color-text-primary);
}

/* ==========================================================================
   Search Input Fancy
   ========================================================================== */

.search-wrap {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-card-bg);
    padding: 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(var(--tint-rgb), 0.1);
}

.search-input-container {
    position: relative;
}

.search-input-container svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    width: 18px;
    height: 18px;
}

.search-input-fancy {
    width: 100%;
    background: rgba(var(--tint-rgb), 0.05);
    border: 1px solid rgba(var(--tint-rgb), 0.1);
    border-radius: var(--radius-md);
    padding: 10px 16px 10px 48px !important;
    color: white;
    outline: none;
    transition: all var(--transition-fast);
}

.search-input-fancy:focus {
    border-color: var(--color-secondary);
    background: rgba(var(--tint-rgb), 0.08);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.2);
}

/* ==========================================================================
   Tooltip Component
   ========================================================================== */

.tooltip-container {
    position: relative;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(var(--tint-rgb), 0.1);
    color: var(--color-text-muted);
    cursor: help;
    margin-left: 8px;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.info-icon svg {
    width: 12px;
    height: 12px;
}

.info-icon:hover {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.custom-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--color-tooltip-bg);
    color: var(--color-tooltip-text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    width: 200px;
    z-index: 100;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    border: 1px solid rgba(var(--tint-rgb), 0.1);
    text-align: center;
    line-height: 1.4;
}

.custom-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--color-tooltip-bg) transparent transparent transparent;
}

.info-icon:hover+.custom-tooltip,
.info-icon:focus+.custom-tooltip,
.info-icon:focus-visible+.custom-tooltip {
    visibility: visible;
    opacity: 1;
}

/* Variante para explicaciones de dos o tres frases: a 200 px centrados se
   convierten en una columna de palabras sueltas imposible de leer. */
.custom-tooltip.tooltip-wide {
    width: 280px;
    text-align: left;
    line-height: 1.45;
}

/* Etiqueta + «i» de ayuda en la misma línea: los `label` de `.admin-form` son
   `display:block`, así que un icono pegado detrás caía a la línea siguiente. */
.label-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.admin-form .label-row label,
.admin-form .label-row .form-label {
    margin-bottom: 0;
}

.label-row .info-icon {
    margin-left: 6px;
}

/* ==========================================================================
   Additional Utility Classes
   ========================================================================== */

.max-w-4xl {
    max-width: 56rem;
}

.mx-auto {
    margin-left: auto;
    margin-right: auto;
}

.min-w-140 {
    min-width: 140px;
}

.section-title-lg {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-xs {
    font-size: 0.75rem;
}

.border-top {
    border-top: 1px solid rgba(var(--tint-rgb), 0.1);
}

.pt-6 {
    padding-top: 1.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.switch-content {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.flex-row {
    display: flex;
    flex-direction: row;
    align-items: center;
}

.gap-sm {
    gap: 8px;
}

.color-chip {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    vertical-align: middle;
    border: 1px solid rgba(var(--tint-rgb), 0.2);
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}


/* Punto de aproximación del puerto: azul, para distinguirlo de la bocana. */


/* Vértice del recinto portuario: pequeño, para no tapar la costa que se está
   siguiendo al dibujar, pero con borde blanco para verse sobre el agua. */


/* ==========================================================================
   Fieldset Styling
   ========================================================================== */

.fieldset-box {
    border: 1px solid var(--color-border-light);
    border-radius: 12px;
    padding: 16px;
    margin: 0;
}

.fieldset-legend {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding: 0 8px;
}

/* ==========================================================================
   Coordinate Input Box
   ========================================================================== */

.coord-box {
    padding: 16px;
    background: var(--color-input-bg);
    border-radius: 8px;
}

/* ==========================================================================
   Section Headers for Forms
   ========================================================================== */

.section-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-dim);
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--color-border);
}

.section-header svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ==========================================================================
   Additional Margin/Padding Utilities
   ========================================================================== */

.mb-1 {
    margin-bottom: 4px;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.mt-1 {
    margin-top: 4px;
}

.mt-2 {
    margin-top: 8px;
}

.mt-3 {
    margin-top: 12px;
}

.pt-4 {
    padding-top: 1rem;
}

.border-t {
    border-top: 1px solid rgba(var(--tint-rgb), 0.1);
}

.border-b {
    border-bottom: 1px solid rgba(var(--tint-rgb), 0.1);
}

.pb-1 {
    padding-bottom: 4px;
}

.pb-2 {
    padding-bottom: 8px;
}


/* ==========================================================================
   Text Alignment
   ========================================================================== */

.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

/* ==========================================================================
   Flex Utilities
   ========================================================================== */

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

.mb-0 {
    margin-bottom: 0;
}

/* ==========================================================================
   Special Form Boxes
   ========================================================================== */

.registration-period-box {
    padding: 16px;
    background: rgba(var(--color-primary-rgb), 0.08);
    border: 1px solid rgba(var(--color-primary-rgb), 0.2);
    border-radius: 8px;
}

.registration-period-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--color-primary);
}

/* ==========================================================================
   Font Weights
   ========================================================================== */

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

.font-mono {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.p-3 {
    padding: 0.75rem;
}

.flex {
    display: flex;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

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

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.text-primary {
    color: var(--color-primary);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.font-bold {
    font-weight: 700;
}

.font-italic {
    font-style: italic;
}

/* ==========================================================================
   Alert Boxes
   ========================================================================== */
.alert-box {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.alert-box svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.alert-box-success {
    background: rgba(var(--color-primary-rgb), 0.08);
    border: 1px solid rgba(var(--color-primary-rgb), 0.25);
    color: var(--color-text-primary);
}

.alert-box-info {
    background: rgba(var(--color-primary-rgb), 0.06);
    border: 1px solid rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-text-primary);
}

/* ==========================================================================
   ORC Smart Fill Component
   ========================================================================== */

.orc-smart-fill-box {
    margin-bottom: 24px;
    padding: 20px;
    background: rgba(var(--color-primary-rgb), 0.06);
    border: 1px solid rgba(var(--color-primary-rgb), 0.15);
    border-radius: 12px;
}

.orc-sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: rgba(0, 0, 0, 0.03);
    padding: 4px;
    border-radius: 8px;
    width: fit-content;
}

.orc-tab-btn {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    background: transparent;
    color: var(--color-text-muted);
}

.orc-tab-btn.active {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.orc-search-container {
    position: relative;
    margin-bottom: 10px;
}

.orc-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-primary);
    opacity: 0.6;
    pointer-events: none;
    z-index: 2;
}

.orc-input-fancy {
    width: 100%;
    padding: 12px 16px 12px 42px;
    font-size: 1rem;
    border: 1px solid var(--color-border-light);
    border-radius: 10px;
    background: var(--color-input-bg);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    outline: none;
    color: var(--color-text-primary);
}

.orc-input-fancy:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.1);
}

.orc-results-dropdown {
    display: none;
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.orc-form-result {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.12s;
}

.orc-form-result:hover {
    background: rgba(var(--color-primary-rgb), 0.08);
}

.orc-form-result:last-child {
    border-bottom: none;
}

/* ==========================================================================
   Detail / Show Page Utilities
   ========================================================================== */

.detail-row {
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.detail-row-label {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.detail-row-value {
    font-size: 0.95rem;
    color: var(--color-text-primary);
    font-weight: 600;
    text-align: right;
}

.sub-entity-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.sub-entity-table th {
    text-align: left;
    padding: 10px;
    border-bottom: 2px solid var(--color-border-light);
    color: var(--color-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 600;
}

.sub-entity-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.9rem;
}

.sub-entity-empty {
    padding: 30px;
    text-align: center;
    color: var(--color-text-muted);
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    margin-bottom: 20px;
    font-style: italic;
}

.inline-add-form {
    background: var(--color-surface, #f8f9fa);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--color-border-light);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.gallery-item {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    padding: 12px;
    position: relative;
}

.gallery-item-path {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    word-break: break-all;
    margin-bottom: 8px;
}

.gallery-item-label {
    font-weight: 600;
    margin-bottom: 4px;
}

.gallery-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

/* ==========================================================================
   Form Switch
   ========================================================================== */

.form-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    vertical-align: middle;
}

.form-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.form-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-switch-track);
    transition: .4s;
    border-radius: 24px;
}

.form-switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.form-switch input:checked+.slider {
    background-color: var(--color-primary);
}

.form-switch input:focus+.slider {
    box-shadow: 0 0 1px var(--color-primary);
}

.form-switch input:checked+.slider:before {
    transform: translateX(20px);
}

.form-switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: rgba(var(--tint-rgb), 0.03);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    height: 42px;
    width: 100%;
}

.form-switch-row:hover {
    background: rgba(var(--tint-rgb), 0.06);
    border-color: rgba(var(--tint-rgb), 0.1);
}

.form-switch-row .form-switch-row-label {
    font-size: 13px;
    color: var(--color-text-secondary);
    flex: 1;
}

.form-switch-row .form-switch-row-label label {
    margin: 0;
    font-weight: 500;
}

.btn-delete-row {
    font-size: 0.75rem;
    color: var(--color-danger);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.btn-delete-row:hover {
    color: var(--color-danger-dark);
}

/* ==========================================================================
   VPP Tabs (ORC Index)
   ========================================================================== */
.vpp-tab.active {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.vpp-tab:not(.active) {
    background: var(--color-bg-alt, #e2e8f0);
    color: var(--color-text, #334155);
}

.vpp-content.hidden {
    display: none;
}

.pdf-preview-frame {
    width: 100%;
    height: 100%;
    min-height: 700px;
    border: none;
}

.polar-chart {
    width: 100%;
    height: 500px;
}

.pdf-preview-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 800px;
}

.table-scroll-container {
    overflow-y: auto;
    max-height: 400px;
}

.sticky-header {
    position: sticky;
    top: 0;
    background: var(--color-card-bg);
    /* Ensure opaque background */
    z-index: 5;
}

.color-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    vertical-align: middle;
    border: 1px solid rgba(var(--tint-rgb), 0.2);
    margin-right: 6px;
}

/* Form help text improvements */
.form-help,
.help-text,
.form-section small,
.form-row small,
.form-section .text-muted.text-xs {
    font-size: 0.75rem !important;
    color: var(--color-text-muted) !important;
    margin-top: 5px !important;
    display: block !important;
    line-height: 1.4 !important;
    font-weight: 400 !important;
}

/* TomSelect Dark Theme Overrides */
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background-color: var(--color-input-bg) !important;
    background-image: none !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border-light) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: none !important;
    padding: 10px 12px !important;
    min-height: 42px !important;
}

.ts-wrapper.single.input-active .ts-control,
.ts-wrapper.multi.input-active .ts-control {
    background: var(--color-input-bg) !important;
}

.ts-wrapper .ts-control input {
    color: var(--color-text-primary) !important;
    font-family: inherit !important;
}

.ts-wrapper .ts-dropdown {
    background-color: var(--color-card-bg) !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border-light) !important;
    border-radius: var(--radius-md) !important;
    margin-top: 4px !important;
    box-shadow: var(--shadow-lg) !important;
}

.ts-wrapper .ts-dropdown .option {
    padding: 10px 12px !important;
    transition: background 0.1s ease;
}

.ts-wrapper .ts-dropdown .active {
    background-color: rgba(var(--color-primary-rgb), 0.4) !important;
    color: var(--color-text-primary) !important;
}

.ts-wrapper .ts-control input::placeholder {
    color: var(--color-text-muted) !important;
    opacity: 0.6 !important;
}

.ts-wrapper .ts-control .item {
    background: var(--color-primary) !important;
    color: var(--color-on-primary) !important;
    border-radius: 4px !important;
    border: none !important;
    padding: 2px 8px !important;
}

.ts-wrapper.single .ts-control::after {
    border-color: var(--color-text-muted) transparent transparent transparent !important;
}

.ts-wrapper.single.input-active .ts-control::after {
    border-color: transparent transparent var(--color-text-muted) transparent !important;
}

/* Remove button enhancements */
.btn-remove-row {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--color-tertiary);
    background: rgba(var(--color-tertiary-rgb), 0.05);
    border: 1px solid rgba(var(--color-tertiary-rgb), 0.1);
    transition: all 0.2s ease;
    cursor: pointer;
    z-index: 10;
}

.btn-remove-row:hover {
    background: var(--color-tertiary);
    border-color: var(--color-tertiary);
    color: white;
    transform: scale(1.05);
}

/* Timezone search */
#timezone-search {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 34px;
}

[id*="_timezone"] option.hidden {
    display: none;
}

.form-group-validation {
    position: relative;
    margin-bottom: 4px;
}

/* Password Requirements */
.password-requirements {
    list-style: none;
    padding: 0;
    margin: 10px 0 0 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.requirement-item {
    font-size: 10px;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s ease;
}

.requirement-item svg {
    width: 12px;
    height: 12px;
    opacity: 0.3;
}

.requirement-item.met {
    color: var(--color-secondary);
}

.requirement-item.met svg {
    opacity: 1;
    color: var(--color-secondary);
}

/* ── PanelSelect: every <select> drawn with the panel's design ──────────────
   panel-select.js keeps the native <select> (hidden) and draws this control.
   The control inherits the select's own classes (dt-filter-select, min-w-*…). */
.panel-select {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
    max-width: 100%;
}

.panel-select--form,
.form-group > .panel-select {
    display: flex;
    width: 100%;
}

/* The native select stays for forms, Alpine and validation, out of sight but
   under the control so the browser's "fill in this field" bubble points there. */
.panel-select > select.panel-select-native {
    position: absolute !important;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.panel-select-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 34px;
    padding: 6px 10px;
    background: var(--color-input-bg);
    background-image: none !important;
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.panel-select-control.dt-per-page-select,
.panel-select-control.dt-filter-select {
    padding-right: 10px;
    min-height: 32px;
}

.panel-select--form .panel-select-control {
    min-height: 44px;
    padding: 10px 14px;
    border-color: var(--color-input-border);
    border-radius: var(--radius-control);
    font-size: 14px;
}

.inline-add-form .panel-select-control {
    min-height: 0;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8125rem;
}

.panel-select-control:hover {
    border-color: var(--color-border-strong, var(--color-primary));
}

.panel-select-control:focus-visible,
.panel-select.is-open .panel-select-control {
    border-color: var(--color-primary-text, var(--color-primary));
    background-color: var(--color-input-bg-focus, var(--color-input-bg));
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

.panel-select.is-invalid .panel-select-control {
    border-color: var(--color-danger);
}

.panel-select.is-placeholder .panel-select-value {
    color: var(--color-text-muted);
}

.panel-select-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.panel-select-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-select-arrow {
    display: flex;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: var(--color-text-muted);
    transition: transform 0.15s ease;
}

.panel-select-arrow svg {
    width: 100%;
    height: 100%;
}

.panel-select.is-open .panel-select-arrow {
    transform: rotate(180deg);
}

.panel-select-panel {
    position: fixed;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    width: max-content;
    background: var(--color-surface-elevated, var(--color-card-bg));
    border: 1px solid var(--color-border-light);
    border-radius: 10px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: panel-select-in 0.12s ease-out;
}

.panel-select-panel.is-up {
    animation-name: panel-select-in-up;
}

@keyframes panel-select-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes panel-select-in-up { from { opacity: 0; transform: translateY(4px); } }

.panel-select-panel[hidden],
.panel-select-search-wrap[hidden],
.panel-select-empty[hidden],
.panel-select-options > li[hidden] {
    display: none;
}

.panel-select-search-wrap {
    flex-shrink: 0;
    padding: 8px;
    border-bottom: 1px solid var(--color-border-light);
}

.panel-select-search {
    width: 100%;
    padding: 7px 10px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    outline: none;
}

.panel-select-search:focus {
    border-color: var(--color-primary);
}

.panel-select-options {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    list-style: none;
    overscroll-behavior: contain;
}

.panel-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--color-text-primary);
    font-size: 13px;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-select-option.is-placeholder {
    color: var(--color-text-muted);
}

.panel-select-option.is-active {
    background: var(--color-input-bg-focus, rgba(var(--tint-rgb), 0.06));
}

.panel-select-option.is-selected {
    color: var(--color-primary-text, var(--color-primary));
    font-weight: 600;
}

.panel-select-option.is-selected::after {
    content: '';
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.panel-select-option.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.panel-select-group {
    padding: 10px 10px 4px;
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: default;
}

.panel-select-empty {
    padding: 14px 10px;
    color: var(--color-text-muted);
    font-size: 12px;
    text-align: center;
}

.panel-select-options::-webkit-scrollbar { width: 6px; }
.panel-select-options::-webkit-scrollbar-track { background: transparent; }
.panel-select-options::-webkit-scrollbar-thumb { background: var(--color-border-light); border-radius: 3px; }

/* ==========================================================================
   Admin Modal (Reusable Confirmation Component)
   ========================================================================== */

.admin-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    /* Velo plano, sin desenfoque. */
    background: rgba(10, 31, 29, 0.7);
    z-index: 99999 !important;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease-out;
}

.admin-modal-overlay.active {
    display: flex;
}

/* ==========================================================================
   Plan Features Key/Value Editor (SubscriptionPlan form)
   ========================================================================== */

.features-editor {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 12px;
    background: var(--color-bg-card, rgba(255,255,255,0.02));
}

.features-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.feature-empty-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-align: center;
    padding: 12px 0 4px;
    font-style: italic;
}

.feature-editor-row {
    display: grid;
    grid-template-columns: 20px 1fr 1fr 28px;
    align-items: center;
    gap: 8px;
}

.feature-editor-drag {
    color: var(--color-text-muted);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.15s;
    &:hover { opacity: 1; }
}

.feature-key-input {
    font-weight: 600;
}

.feature-val-input {
    color: var(--color-text-secondary);
}

.feature-remove-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    padding: 0;
    flex-shrink: 0;
}

.feature-remove-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--color-danger);
}

/* ==========================================================================
   Roles Checkbox Grid (SubscriptionPlan form)
   ========================================================================== */

.roles-checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.role-checkbox-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-card, rgba(255,255,255,0.04));
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    user-select: none;
}

.role-checkbox-item:hover {
    border-color: var(--color-primary);
    background: rgba(var(--color-primary-rgb, 99,102,241), 0.08);
    color: var(--color-text-primary);
}

.role-checkbox-item.is-checked,
.role-checkbox-item:has(input:checked) {
    border-color: var(--color-primary);
    background: rgba(var(--color-primary-rgb, 99,102,241), 0.15);
    color: var(--color-primary);
}

/* Hide the native checkbox — the pill itself is the visual indicator */
.role-checkbox-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1.5px solid currentColor;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}

.role-checkbox-item input[type="checkbox"]::after {
    content: '';
    display: none;
    position: absolute;
    left: 3px;
    top: 0px;
    width: 5px;
    height: 9px;
    border: 2px solid var(--color-primary);
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

.role-checkbox-item input[type="checkbox"]:checked {
    background: rgba(var(--color-primary-rgb, 99,102,241), 0.2);
    border-color: var(--color-primary);
}

.role-checkbox-item input[type="checkbox"]:checked::after {
    display: block;
}

.admin-modal {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.admin-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
}

.admin-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.admin-modal-close {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    display: flex;
}

.admin-modal-close:hover {
    background: rgba(var(--tint-rgb), 0.05);
    color: var(--color-text-primary);
}

.admin-modal-body {
    padding: 24px;
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    line-height: 1.6;
}

.admin-modal-footer {
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid var(--color-border);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalScaleUp {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================================================
   BUTTON EXTRA-SMALL & SUCCESS GHOST
   ========================================================================== */

.btn-xs {
    min-height: 28px;
    padding: 4px 6px;
    font-size: 12px;
    line-height: 1;
    border-radius: 8px;
    height: 28px;
    width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-success-ghost {
    background: transparent;
    border: 1px solid var(--color-success);
    color: var(--color-success-text);
}

.btn-success-ghost:hover {
    background: var(--color-success-light);
    color: var(--color-success-text);
}

.btn-warning-ghost {
    background: transparent;
    border: 1px solid var(--color-warning-text, #f59e0b);
    color: var(--color-warning-text, #f59e0b);
}

.btn-warning-ghost:hover {
    background: var(--color-warning-light);
    color: var(--color-warning-text, #f59e0b);
}


/* Drag states */
.drag-handle {
    cursor: grab;
    text-align: center;
    color: var(--color-text-dim);
    transition: color 0.15s ease;
    user-select: none;
}

.drag-handle:hover {
    color: var(--color-text-secondary);
}

.drag-handle:active {
    cursor: grabbing;
}


/* Editing state */


/* Updating state (saving to server) */


@keyframes wp-updated-flash {
    0% {
        background: var(--color-success-light);
    }

    100% {
        background: transparent;
    }
}


/* Premium Custom Time Picker */
.premium-timepicker-container {
    position: relative;
    width: 100%;
}

.premium-timepicker-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast) ease;
    user-select: none;
    min-height: 42px;
}

.premium-timepicker-control:hover {
    border-color: var(--color-border);
}

.premium-timepicker-container.open {
    z-index: 1001;
}

.premium-timepicker-container.open .premium-timepicker-control {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

.premium-timepicker-value {
    font-size: 14px;
    color: var(--color-text-primary);
}

.premium-timepicker-arrow {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast) ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.premium-timepicker-container.open .premium-timepicker-arrow {
    color: var(--color-primary);
}

.premium-timepicker-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 200px;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast) ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.premium-timepicker-container.open .premium-timepicker-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.premium-timepicker-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-thead-bg);
    letter-spacing: 0.5px;
}

.premium-timepicker-columns {
    display: flex;
    height: 160px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-input-bg);
}

.premium-timepicker-column {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 4px 0;
    display: flex;
    flex-direction: column;
}

.premium-timepicker-column::-webkit-scrollbar {
    width: 4px;
}

.premium-timepicker-column::-webkit-scrollbar-track {
    background: transparent;
}

.premium-timepicker-column::-webkit-scrollbar-thumb {
    background: var(--color-border-light);
    border-radius: 2px;
}

.premium-timepicker-column:first-child {
    border-right: 1px solid var(--color-border);
}

.premium-timepicker-option {
    padding: 6px 0;
    font-size: 13px;
    text-align: center;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
    user-select: none;
}

.premium-timepicker-option:hover {
    background: var(--color-secondary-light);
    color: var(--color-text-primary);
}

.premium-timepicker-option.selected {
    background: rgba(var(--color-secondary-rgb), 0.2);
    color: var(--color-secondary);
    font-weight: 600;
}

.premium-timepicker-footer {
    padding: 8px;
    display: flex;
    justify-content: flex-end;
    background: var(--color-thead-bg);
}

/* Premium WYSIWYG Editor wrapper & Maximize feature */
.premium-wysiwyg-wrapper {
    position: relative;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-input-bg);
    overflow: hidden;
    margin-bottom: 12px;
    width: 100%;
}

.premium-wysiwyg-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 6px 12px;
    background: var(--color-thead-bg);
    border-bottom: 1px solid var(--color-border-light);
}

.wysiwyg-maximize-btn {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    transition: color 0.15s ease;
}

.wysiwyg-maximize-btn:hover {
    color: var(--color-primary);
}

.wysiwyg-maximize-btn svg {
    width: 14px;
    height: 14px;
}

/* Override Quill default layout & styles for dark theme */
.premium-wysiwyg-wrapper .ql-toolbar.ql-snow {
    background: var(--color-thead-bg) !important;
    border: none !important;
    border-bottom: 1px solid var(--color-border-light) !important;
    padding: 8px 12px !important;
}

.premium-wysiwyg-wrapper .ql-container.ql-snow {
    border: none !important;
    background: transparent !important;
}

.premium-wysiwyg-wrapper .ql-editor {
    min-height: 150px;
    max-height: 400px;
    color: var(--color-text-primary) !important;
    background: transparent !important;
    font-family: var(--font-family-base) !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    padding: 12px 16px !important;
}

/* Scrollbar inside Quill editor */
.premium-wysiwyg-wrapper .ql-editor::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.premium-wysiwyg-wrapper .ql-editor::-webkit-scrollbar-track {
    background: transparent;
}
.premium-wysiwyg-wrapper .ql-editor::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 3px;
}

/* Toolbar Buttons & SVGs styling */
.ql-snow.ql-toolbar button,
.ql-snow .ql-toolbar button {
    color: var(--color-text-secondary) !important;
    transition: color 0.15s ease, stroke 0.15s ease, fill 0.15s ease;
}

.ql-snow.ql-toolbar button svg,
.ql-snow .ql-toolbar button svg {
    stroke: var(--color-text-secondary) !important;
}

.ql-snow.ql-toolbar button svg .ql-stroke,
.ql-snow .ql-toolbar button svg .ql-stroke {
    stroke: var(--color-text-secondary) !important;
}

.ql-snow.ql-toolbar button svg .ql-fill,
.ql-snow .ql-toolbar button svg .ql-fill {
    fill: var(--color-text-secondary) !important;
}

/* Hover and Active states */
.ql-snow.ql-toolbar button:hover,
.ql-snow.ql-toolbar button.ql-active,
.ql-snow .ql-toolbar button:hover,
.ql-snow .ql-toolbar button.ql-active {
    color: var(--color-primary-text) !important;
}

.ql-snow.ql-toolbar button:hover svg .ql-stroke,
.ql-snow.ql-toolbar button.ql-active svg .ql-stroke,
.ql-snow .ql-toolbar button:hover svg .ql-stroke,
.ql-snow .ql-toolbar button.ql-active svg .ql-stroke {
    stroke: var(--color-primary-text) !important;
}

.ql-snow.ql-toolbar button:hover svg .ql-fill,
.ql-snow.ql-toolbar button.ql-active svg .ql-fill,
.ql-snow .ql-toolbar button:hover svg .ql-fill,
.ql-snow .ql-toolbar button.ql-active svg .ql-fill {
    fill: var(--color-primary-text) !important;
}

/* Dropdown Pickers (Font size, Header, Color...) */
.ql-snow .ql-picker {
    color: var(--color-text-secondary) !important;
    font-weight: 500 !important;
}

.ql-snow .ql-picker-label {
    border: 1px solid transparent !important;
    border-radius: var(--radius-sm) !important;
    color: var(--color-text-secondary) !important;
    transition: border-color var(--transition-fast) ease, color var(--transition-fast) ease;
}

.ql-snow .ql-picker-label:hover,
.ql-snow .ql-picker-label.ql-active {
    color: var(--color-primary-text) !important;
    border-color: var(--color-border-light) !important;
}

.ql-snow .ql-picker-label svg .ql-stroke {
    stroke: var(--color-text-secondary) !important;
}

.ql-snow .ql-picker-label:hover svg .ql-stroke,
.ql-snow .ql-picker-label.ql-active svg .ql-stroke {
    stroke: var(--color-primary-text) !important;
}

/* Picker Dropdown Options container */
.ql-snow .ql-picker-options {
    background-color: var(--color-surface-elevated) !important;
    border: 1px solid var(--color-border-light) !important;
    box-shadow: var(--shadow-lg) !important;
    border-radius: var(--radius-md) !important;
    padding: 8px !important;
    z-index: 1000 !important;
}

.ql-snow .ql-picker-item {
    color: var(--color-text-secondary) !important;
    padding: 4px 8px !important;
    border-radius: var(--radius-sm) !important;
    transition: background-color var(--transition-fast) ease, color var(--transition-fast) ease;
}

.ql-snow .ql-picker-item:hover,
.ql-snow .ql-picker-item.ql-selected {
    background-color: var(--color-hover-tint) !important;
    color: var(--color-primary-text) !important;
}

/* Custom Grid layout for Color palette picker */
.ql-snow .ql-color-picker .ql-picker-options {
    display: none !important;
    width: 220px !important;
    padding: 8px !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 6px !important;
}

.ql-snow .ql-color-picker.ql-expanded .ql-picker-options {
    display: grid !important;
}

.ql-snow .ql-color-picker .ql-picker-item {
    width: 20px !important;
    height: 20px !important;
    padding: 0 !important;
    border-radius: 4px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    cursor: pointer !important;
    transition: transform 0.1s ease, border-color 0.15s ease !important;
}

.ql-snow .ql-color-picker .ql-picker-item:hover {
    transform: scale(1.15) !important;
    border-color: #ffffff !important;
}

.ql-snow .ql-color-picker .ql-picker-item.ql-selected {
    border-color: var(--color-primary-text) !important;
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.5) !important;
}

/* Maximized WYSIWYG Wrapper */
.premium-wysiwyg-wrapper.is-maximized {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
    background: var(--color-dark-bg) !important;
    border: none !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 16px !important;
    margin: 0 !important;
}

.premium-wysiwyg-wrapper.is-maximized .premium-wysiwyg-header {
    background: transparent !important;
    border-bottom: none !important;
    padding: 0 0 12px 0 !important;
}

.premium-wysiwyg-wrapper.is-maximized .ql-container.ql-snow {
    flex-grow: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
}

.premium-wysiwyg-wrapper.is-maximized .ql-editor {
    flex-grow: 1 !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
}


/* ==========================================================================
   Librería ux-*: las piezas compartidas de la guía de estilo
  . Las pintan los parciales de
   templates/admin/_partials/ (_card, _stat, _status_pill, _empty_state,
   _detail_list, _entity_header, _toggle_row). Regla: lo que una
   segunda pantalla repite sube aquí; nunca colores fijos, siempre tokens.
   ========================================================================== */

/* Tarjeta: .admin-card ya es la receta; esto es su etiqueta y su cuerpo. */
.ux-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px 0;
}

.ux-card-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-family: var(--font-family-base);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.ux-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ux-card-body {
    padding: 14px 20px 20px;
}

.ux-card-body--flush {
    padding: 12px 0 0;
}

.ux-divider {
    height: 1px;
    margin: 14px 0;
    background: var(--color-separator);
}

.ux-tile {
    padding: 12px 14px;
    border: 1px solid rgba(var(--tint-rgb), 0.1);
    border-radius: var(--radius-control);
    background: rgba(var(--tint-rgb), 0.04);
}

/* Cifras: columnas separadas por línea fina dentro de una tarjeta. */
.ux-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.ux-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 20px;
    border-left: 1px solid var(--color-separator);
    color: inherit;
    text-decoration: none;
}

.ux-stat:first-child {
    border-left: 0;
    padding-left: 0;
}

a.ux-stat {
    border-radius: var(--radius-tile);
    transition: background-color var(--transition-fast) ease;
}

a.ux-stat:hover {
    background: var(--color-pressed);
}

a.ux-stat:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.ux-stat-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.ux-stat-value {
    font-family: var(--font-family-heading);
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
}

.ux-stat-value small {
    margin-left: 4px;
    font-family: var(--font-family-base);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.ux-stat-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.ux-stat-trend.is-good { color: var(--color-success-text); }
.ux-stat-trend.is-bad { color: var(--color-danger-text); }
.ux-stat-trend.is-flat { color: var(--color-text-secondary); }

.ux-stat-note {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.ux-flip-y {
    transform: scaleY(-1);
}

@media (max-width: 640px) {
    .ux-stat { padding: 10px 0; border-left: 0; border-top: 1px solid var(--color-separator); }
    .ux-stat:first-child { border-top: 0; }
}

/* Estado en píldora: fondo suave y texto del mismo tono, con punto. */
.ux-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    background: rgba(var(--tint-rgb), 0.08);
    color: var(--color-text-secondary);
}

.ux-pill-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: currentColor;
}

.ux-pill--success { background: var(--color-success-light); color: var(--color-success-text); }
.ux-pill--warning { background: var(--color-warning-light); color: var(--color-warning-text); }
.ux-pill--danger { background: var(--color-danger-light); color: var(--color-danger-text); }
.ux-pill--info { background: var(--color-info-light); color: var(--color-info-text); }
.ux-pill--accent { background: rgba(var(--color-primary-rgb), 0.14); color: var(--color-primary-text); }

/* Estado vacío. */
.ux-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 36px 16px;
    text-align: center;
}

.ux-empty--compact {
    padding: 20px 12px;
}

.ux-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-bottom: 6px;
    border-radius: var(--radius-tile);
    background: var(--color-tile-bg);
    color: var(--color-tile-icon);
}

/* Error de carga: la misma forma, con la loseta en rojo de estado. */
.ux-empty--error .ux-empty-icon {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
}

/* Dentro de una tabla, la fila vacía no se resalta al pasar. */
.admin-table tr.dt-empty-row:hover td {
    background: transparent;
}

.ux-empty-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.ux-empty-text {
    max-width: 440px;
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

.ux-empty-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

/* Lista de cosas por hacer o próximas: icono en loseta,
   etiqueta y pista, estado y acción; con línea fina entre filas. */
.ux-todo {
    margin: 0;
    padding: 0;
    list-style: none;
}
.ux-todo > li + li,
.ux-todo + .ux-todo,
.ux-todo-link + .ux-todo { border-top: 1px solid var(--color-separator); }
.ux-todo-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 10px 0;
}
.ux-todo-link {
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-control);
}
.ux-todo-link:hover { background: var(--color-pressed); }
.ux-todo-link:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25); }
.ux-todo-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-tile);
    background: var(--color-tile-bg);
    color: var(--color-tile-icon);
}
.ux-todo-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.ux-todo-label {
    font-weight: 600;
    color: var(--color-text-primary);
}
.ux-todo-hint {
    font-size: 0.82rem;
    color: var(--color-text-secondary);
}

/* Selector de pocas opciones excluyentes (periodo 7/30/90 del dashboard). */
.ux-segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-control);
    background: rgba(var(--tint-rgb), 0.03);
}
.ux-segmented-item {
    padding: 6px 12px;
    white-space: nowrap;
    border-radius: calc(var(--radius-control) - 4px);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-decoration: none;
}
.ux-segmented-item:hover { color: var(--color-text-primary); }
.ux-segmented-item.is-active {
    background: rgba(var(--color-primary-rgb), 0.14);
    color: var(--color-primary-text);
}
.ux-segmented-item:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25); }

@media (max-width: 640px) {
    .ux-segmented-item { padding: 6px 10px; white-space: nowrap; }
    /* El estado y la acción bajan a su línea, alineados a la derecha. */
    .ux-todo-item { flex-wrap: wrap; }
    .ux-todo-item .ux-todo-text { flex-basis: calc(100% - 48px); }
    .ux-todo-item .ux-pill { margin-left: 48px; }
    .ux-todo-item .ux-pill + .btn { margin-left: auto; }
}

/* Lista etiqueta / valor de una ficha. */
.ux-details {
    margin: 0;
}

.ux-details-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-top: 1px solid var(--color-separator);
}

.ux-details-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.ux-details-row dt {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.ux-details-row dd {
    margin: 0;
    text-align: right;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-primary);
    overflow-wrap: anywhere;
}

@media (min-width: 768px) {
    .ux-details--2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; }
    .ux-details--2 .ux-details-row:nth-child(2) { border-top: 0; padding-top: 0; }
}

.ux-mono {
    font-variant-numeric: tabular-nums;
    font-family: var(--font-family-mono);
}

.ux-muted {
    color: var(--color-text-muted);
    font-weight: 400;
}

/* Cabecera de ficha. */
.ux-entity {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

.ux-entity-media {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-control);
    object-fit: cover;
}

.ux-entity-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-tile-bg);
    color: var(--color-tile-icon);
}

.ux-entity-main {
    min-width: 0;
    flex: 1;
}

.ux-entity-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.ux-entity-title {
    margin: 0;
    font-family: var(--font-family-heading);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text-primary);
    overflow-wrap: anywhere;
}

.ux-entity-subtitle {
    margin: 2px 0 0;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.ux-entity-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin: 12px 0 0;
}

.ux-entity-facts dt {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.ux-entity-facts dd {
    margin: 2px 0 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

/* Sí/no como fila con interruptor (mosaico de la guía §4.1). */
/* Con `.admin-form label` delante para ganar a la etiqueta genérica del formulario. */
.ux-toggle,
.admin-form label.ux-toggle {
    display: flex;
    margin: 0;
    font-size: inherit;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    border: 1px solid rgba(var(--tint-rgb), 0.1);
    border-radius: var(--radius-control);
    background: rgba(var(--tint-rgb), 0.04);
    cursor: pointer;
}

.ux-toggle-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ux-toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.ux-toggle-desc {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--color-text-secondary);
}

.ux-toggle-input,
.admin-form input.ux-toggle-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.ux-toggle-switch {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 26px;
    border-radius: var(--radius-full);
    background: var(--color-switch-track);
    transition: background-color var(--transition-fast) ease;
}

.ux-toggle-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    background: #ffffff;
    transition: transform var(--transition-fast) ease;
}

.ux-toggle-input:checked + .ux-toggle-switch {
    background: var(--color-primary);
}

.ux-toggle-input:checked + .ux-toggle-switch::after {
    transform: translateX(18px);
}

.ux-toggle-input:focus-visible + .ux-toggle-switch {
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

/* ==========================================================================
   UX del panel: piezas comunes de las pantallas de edición (skill admin-ux §3 y §4: pantallas de edición)

   Rejilla con resumen fijo (.ux-layout / .ux-main / .ux-aside), pasos
   numerados (.ux-step), plantillas y chips (.ux-presets, .ux-chip, .is-custom),
   botones pequeños (.ux-icon-btn, .ux-add, .ux-add-block, .ux-link),
   menús (.ux-menu), notas y errores (.ux-note, .ux-alert, .ux-error),
   resumen (.ux-summary-head, .ux-dirty, .ux-total, .ux-facts, .ux-status,
   .ux-warnings, .ux-shortcut), fechas rápidas (.ux-quick), selector de días
   (.ux-weekday-picker) y plegado (.ux-fold). El estado vacío es el .ux-empty de
   arriba. Solo tokens del tema.
   ========================================================================== */
.ux-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
@media (min-width: 1180px) {
    .ux-layout { grid-template-columns: minmax(0, 1fr) 320px; }
    .ux-aside { position: sticky; top: 88px; }
}
.ux-main, .ux-aside { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ux-step { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; color: var(--color-text-primary); margin-bottom: 16px; }
.ux-step span {
    display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 999px;
    font-size: 12px; background: rgba(var(--color-primary-rgb), .16); color: var(--color-primary-text);
}
.ux-step-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ux-help { font-size: 12px; color: var(--color-text-muted); margin-top: 10px; }
.ux-alert {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 16px; border-radius: 12px;
    background: var(--color-danger-light); color: var(--color-danger-text); border: 1px solid var(--color-danger-light); font-size: 13px;
}
.ux-alert ul { display: flex; flex-direction: column; gap: 2px; }
/* Presets / chips */
.ux-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.ux-presets-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.ux-presets-hint { font-size: 12px; color: var(--color-text-muted); }
.ux-chip {
    padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer;
    border: 1px solid var(--color-border-light); background: var(--color-panel-sunken); color: var(--color-text);
    transition: border-color .15s, background-color .15s, color .15s;
}
.ux-chip:hover { border-color: rgba(var(--color-primary-rgb), .6); color: var(--color-text-primary); }
.ux-chip.is-on { border-color: var(--color-primary); background: rgba(var(--color-primary-rgb), .16); color: var(--color-primary-text); }
.ux-icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 7px;
    border: 0; background: transparent; color: var(--color-text-muted); cursor: pointer;
}
.ux-icon-btn:hover { background: var(--color-danger-light); color: var(--color-danger-text); }
.ux-add {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 10px; cursor: pointer;
    border: 1px dashed var(--color-border-strong); background: transparent; color: var(--color-text-secondary); font-size: 13px; font-weight: 500;
}
.ux-add:hover { border-color: var(--color-primary); color: var(--color-primary-text); background: rgba(var(--color-primary-rgb), .08); }
.ux-icon-btn.is-copy:hover, .ux-icon-btn.is-copy[aria-expanded="true"] { background: rgba(var(--color-primary-rgb), .16); color: var(--color-primary-text); }
.ux-menu-title { padding: 6px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); }
.ux-menu {
    position: absolute; z-index: 30; top: calc(100% + 6px); right: 0; min-width: 220px; padding: 6px; border-radius: 12px;
    background: var(--color-surface-elevated); border: 1px solid var(--color-border-light); box-shadow: var(--shadow-md);
    display: flex; flex-direction: column;
}
.ux-menu button {
    text-align: left; padding: 8px 10px; border-radius: 8px; border: 0; background: transparent; cursor: pointer;
    color: var(--color-text); font-size: 13px;
}
.ux-menu button:hover { background: rgba(var(--color-primary-rgb), .14); color: var(--color-text-primary); }
.ux-note {
    display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
    background: var(--color-info-light); color: var(--color-text);
}
.ux-note svg { color: var(--color-info-text); flex-shrink: 0; margin-top: 1px; }
/* Summary */
.ux-summary-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-secondary); }
.ux-dirty {
    text-transform: none; letter-spacing: 0; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: var(--color-warning-light); color: var(--color-warning-text);
}
.ux-total { margin: 10px 0 16px; }
.ux-total strong { display: block; font-size: 34px; font-weight: 800; line-height: 1.1; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.ux-total span { font-size: 13px; color: var(--color-text-secondary); }
.ux-facts { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--color-border); margin-bottom: 14px; }
.ux-facts > div { display: flex; align-items: baseline; gap: 8px; }
.ux-facts dt { font-weight: 700; color: var(--color-text-primary); font-variant-numeric: tabular-nums; min-width: 84px; }
.ux-facts dd { font-size: 13px; color: var(--color-text-secondary); }
.ux-status { border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.ux-status.is-ok { display: flex; align-items: center; gap: 8px; background: var(--color-success-light); color: var(--color-success-text); font-weight: 600; }
.ux-status.is-pending { background: var(--color-warning-light); color: var(--color-warning-text); }
.ux-status-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.ux-status ul { display: flex; flex-direction: column; gap: 4px; padding-left: 26px; }
.ux-status li { list-style: disc; }
.ux-status li button { background: none; border: 0; padding: 0; text-align: left; color: inherit; cursor: pointer; font: inherit; }
.ux-status li button:hover { text-decoration: underline; }
.ux-shortcut { margin-top: 12px; font-size: 11px; color: var(--color-text-muted); text-align: center; }
/* Custom template panel («Personalizado…») */
.ux-chip.is-custom { display: inline-flex; align-items: center; gap: 6px; border-style: dashed; }
.ux-chip.is-custom.is-on { border-style: solid; }
.ux-weekday-picker { display: inline-flex; gap: 6px; }
.ux-weekday {
    width: 36px; height: 36px; border-radius: 999px; font-size: 13px; font-weight: 700; cursor: pointer;
    border: 1px solid var(--color-border-light); background: var(--color-panel-sunken); color: var(--color-text-secondary);
    transition: background-color .15s, border-color .15s, color .15s;
}
.ux-weekday:hover { border-color: var(--color-primary); }
.ux-weekday.is-on { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
.ux-link { background: none; border: 0; padding: 0; font-size: 13px; font-weight: 600; color: var(--color-primary-text); cursor: pointer; }
.ux-link:hover { text-decoration: underline; }
.ux-link.is-danger { color: var(--color-danger-text); }
.ux-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-text); cursor: pointer; width: fit-content; }
.ux-check input { width: 16px; height: 16px; accent-color: var(--color-primary); }
/* Quick values, inline errors, add/empty/fold blocks, warnings */
.ux-intro { font-size: 13px; color: var(--color-text-secondary); margin: -8px 0 18px; }
.ux-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ux-quick button {
    padding: 2px 9px; border-radius: 999px; font-size: 12px; cursor: pointer;
    border: 1px solid var(--color-border-light); background: transparent; color: var(--color-text-secondary);
}
.ux-quick button:hover { border-color: var(--color-primary); color: var(--color-primary-text); }
.ux-error { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--color-danger-text); }
.ux-add-block {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; width: 100%; margin-top: 14px; padding: 14px;
    border-radius: 14px; border: 2px dashed var(--color-border-strong); background: transparent; cursor: pointer;
    color: var(--color-text-secondary); font-size: 14px; font-weight: 600;
}
.ux-add-block small { flex-basis: 100%; text-align: center; font-weight: 400; font-size: 12px; color: var(--color-text-muted); }
.ux-add-block:hover { border-color: var(--color-primary); color: var(--color-primary-text); background: rgba(var(--color-primary-rgb), .06); }
.ux-warnings { border-radius: 10px; padding: 10px 12px; font-size: 13px; background: var(--color-warning-light); color: var(--color-warning-text); }
.ux-warnings ul { display: flex; flex-direction: column; gap: 4px; padding-left: 18px; }
.ux-warnings li { list-style: disc; }
.ux-warnings button { background: none; border: 0; padding: 0; text-align: left; color: inherit; cursor: pointer; font: inherit; }
.ux-warnings button:hover { text-decoration: underline; }
.ux-fold {
    display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--color-border-light); background: var(--color-panel-sunken); color: var(--color-text-secondary); font-size: 13px; font-weight: 500;
}
.ux-fold:hover { border-color: var(--color-primary); color: var(--color-primary-text); }

