/* ==========================================================================
   components.css  –  Shared UI components (BEM)
   Depends on: base.css  (must be loaded first)
   Architecture: base.css → components.css → pages/[name].css
   ========================================================================== */

/* ── 1. PAGE HEADER ──────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 177, 183, 0.15);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    box-shadow: 0 4px 20px rgba(0, 52, 73, 0.15);
    min-height: 100px;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
    padding: 0 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex: 1;
    min-width: 280px;
}

.header-logo {
    width: 64px;
    height: 64px;
    background: #ffffff;
    border-radius: var(--radius-md);
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 177, 183, 0.2);
    flex-shrink: 0;
    padding: 8px;
}

.header-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.header-title-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.header-title-group h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-brand-primary-dark);
    margin: 0;
    line-height: 1.2;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Status indicator (shared — admin-users + admin-dashboard) ───────────── */

/* Dot-span variant: <span class="status-dot"><span class="status-dot-pulse"></span><span class="status-dot-solid"></span></span> */
.header-status-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.status-dot {
    display: inline-flex;
    position: relative;
    align-items: center;
    justify-content: center;
    width: 8px;
    height: 8px;
}

.status-dot-pulse {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

.status-dot-solid {
    position: relative;
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
}

@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    50%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* JS-functional names referenced by admin-users markup */
.status-text {
    color: var(--color-success);
    font-weight: 700;
    font-size: 0.75rem;
}

.status-divider {
    color: #cbd5e1;
    margin: 0 0.25rem;
}

.status-time {
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.75rem;
}

/* FA-icon dot variant: dashboard.js sets statusEl.className = `status-indicator ${status}`
   <i class="fas fa-circle"> is turned into a CSS dot (font-size:0 hides the glyph). */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-indicator > i {
    font-size: 0;          /* hide FA glyph */
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-warn);
    flex-shrink: 0;
    animation: pulse-dot 2s infinite;
}

.status-indicator > span { color: var(--color-warn); }

.status-indicator.connected > i {
    background: var(--color-success);
}

.status-indicator.connected > span  { color: var(--color-success); }

.status-indicator.disconnected > i {
    background: var(--color-danger);
    animation: none;
}

.status-indicator.disconnected > span { color: var(--color-danger); }

/* .connecting: defaults (warn colour + pulse) already set above */


.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

/* Material Symbols in the header must match the button font-size so they
   don't inflate the button height beyond what FA icons produce (36.8px). */
.header-actions .material-symbols-outlined {
    font-size: 0.875rem;
}

.header-actions .btn-secondary {
    border: 1.3px solid var(--color-brand-primary);
}

/* ── Hamburger toggle button (hidden at wide screens, shown at ≤680px) ───── */
.nav-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--color-border-brand);
    background: transparent;
    color: var(--color-brand-primary-dark);
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.nav-toggle-btn:hover {
    background: var(--color-brand-primary-subtle);
    color: var(--color-brand-primary);
}

/* ── Header responsive breakpoints ──────────────────────────────────────── */

/* 1260px — reducir gap y ocultar etiquetas (botón icono, mismo tamaño) */
@media (max-width: 1260px) {
    .header-actions { gap: 0.5rem; }
    .header-actions .btn-label-hidden-mobile { display: none; }
}

/* 960px — compactar logo y título */
@media (max-width: 960px) {
    .header-logo {
        width: 48px;
        height: 48px;
        padding: 6px;
    }

    .header-title-group h1 { font-size: 1.2rem; }
}

/* 680px — menú hamburguesa */
@media (max-width: 680px) {
    /* Mostrar el botón hamburguesa */
    .nav-toggle-btn { display: flex; }

    /* Ocultar los botones del header (se muestran como dropdown con .nav-open) */
    .header-actions {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0.4rem;
        padding: 0.875rem 1rem;
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid var(--color-border-brand);
        border-bottom: 2px solid var(--color-border-brand);
        box-shadow: 0 8px 24px rgba(0, 52, 73, 0.12);
        z-index: var(--z-dropdown);
    }

    /* Mostrar el dropdown cuando .nav-open está en .page-header */
    .page-header { position: relative; }
    .page-header.nav-open .header-actions { display: flex; }

    /* En el menú abierto, los botones ocupan todo el ancho y las etiquetas vuelven a aparecer */
    .header-actions .btn {
        width: 100%;
        justify-content: flex-start;
    }

    .header-actions .btn-label-hidden-mobile { display: inline; }
}


/* ── 2. BUTTONS ──────────────────────────────────────────────────────────── */
/* Base */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-base);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Variants — functional alias + BEM modifier on same rule */
.btn-primary,
.btn--primary {
    background: var(--color-brand-primary);
    color: #fff;
    border: none;
}

.btn-primary:hover:not(:disabled),
.btn--primary:hover:not(:disabled) {
    background: var(--color-brand-primary-dark);
    color: #fff;
}

.btn-secondary,
.btn--secondary {
    background: transparent;
    color: var(--color-brand-primary);
    border: none;
}

.btn-secondary:hover:not(:disabled),
.btn--secondary:hover:not(:disabled) {
    background: var(--color-brand-primary);
    color: #fff;
}

.btn-danger,
.btn--danger {
    background: linear-gradient(135deg, #fa6b6b, #ed5757);
    color: #fff;
}

.btn-danger:hover:not(:disabled),
.btn--danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #ed5757, #d23e3e);
}

.btn-ghost,
.btn--ghost {
    background: transparent;
    color: var(--color-text-muted);
    border: 1.5px solid var(--color-border);
}

.btn-ghost:hover:not(:disabled),
.btn--ghost:hover:not(:disabled) {
    border-color: var(--color-brand-primary);
    color: var(--color-brand-primary);
    background: rgba(0, 177, 183, 0.05);
}

.btn-outline,
.btn--outline {
    background: transparent;
    color: var(--color-text-muted);
    border: 1.5px solid var(--color-border);
}

.btn-outline:hover:not(:disabled),
.btn--outline:hover:not(:disabled) {
    border-color: var(--color-brand-primary);
    color: var(--color-brand-primary);
    background: rgba(0, 177, 183, 0.05);
}

/* Size modifier */
.btn-sm,
.btn--sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
}


/* ── 3. BADGES ───────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-admin,
.badge--admin {
    background: rgba(0, 177, 183, 0.15);
    color: #00738d;
    border: 1px solid rgba(0, 177, 183, 0.3);
    min-width: 5.5rem;
    justify-content: center;
}

.badge-user,
.badge--user {
    background: rgba(100, 116, 139, 0.12);
    color: #334155;
    border: 1px solid rgba(100, 116, 139, 0.25);
    min-width: 5.5rem;
    justify-content: center;
}

.badge-warn,
.badge--warn {
    background: rgba(245, 158, 11, 0.15);
    color: #a16207;
    border: 1px solid rgba(245, 158, 11, 0.3);
}


/* ── 4. TABLE CARD ───────────────────────────────────────────────────────── */
.table-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    border: 1px solid rgba(0, 177, 183, 0.1);
}

.table-scroll { overflow-x: auto; }

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

thead {
    background: linear-gradient(135deg,
        rgba(0, 177, 183, 0.08),
        rgba(0, 52, 73, 0.08));
}

th {
    padding: 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-brand-primary-dark);
    border-bottom: 2px solid rgba(0, 177, 183, 0.2);
    white-space: nowrap;
}

td {
    padding: 0.95rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(0, 177, 183, 0.1);
    vertical-align: middle;
    color: var(--color-text);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: rgba(0, 177, 183, 0.05); }


/* ── 5. STATUS CELL & ICONS ──────────────────────────────────────────────── */
.status-cell {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.status-icon { font-size: 18px; }

.icon-warn { color: var(--color-warn); }
.icon-ok   { color: var(--color-success); }

.actions-cell {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}


/* ── 6. STATE ROWS (empty / loading / error) ─────────────────────────────── */
.state-row td {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--color-text-muted);
}

.state-row .state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

.state-row p { font-size: 0.875rem; }


/* ── 7. TOOLBAR ──────────────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
    max-width: 420px;
}

.search-wrap .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    font-size: 18px;
    pointer-events: none;
}

.toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.7rem 0.95rem;
    background: #f1f5f9;
    color: #475569;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: none;
    user-select: none;
}


/* ── 8. TOAST ────────────────────────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 1.75rem;
    right: 1.75rem;
    z-index: var(--z-toast);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-sans);
    box-shadow: var(--shadow-modal);
    transform: translateY(16px);
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    max-width: 360px;
    pointer-events: none;
}

#toast.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#toast.toast-ok {
    background: #f0fdf4;
    color: #15803d;
    border: 1.5px solid #86efac;
}

#toast.toast-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1.5px solid #fecaca;
}


/* ── 9. MODAL ────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    background: rgba(0, 52, 73, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    transition: opacity 0.25s;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: var(--color-surface);
    border-radius: 14px;
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 480px;
    /* Limitar altura al viewport para que no se corte en portátiles o con zoom */
    max-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(0, 177, 183, 0.1);
}

.modal-overlay.open .modal-card {
    transform: translateY(0) scale(1);
}

.modal-header {
    background: var(--gradient-brand);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.modal-header h2 {
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    flex: 1;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.modal-close:hover { background: rgba(255, 255, 255, 0.3); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* necesario para que overflow funcione dentro de flex */
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 177, 183, 0.1);
}

.modal-form-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    color: #991b1b;
    border-radius: var(--radius-sm);
    font-size: 0.8375rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: none;
    font-weight: 600;
}


/* ── 10. FORM GROUPS ─────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 0.45rem;
    text-transform: capitalize;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid rgba(0, 177, 183, 0.2);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--color-text);
    background: #fff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input::placeholder,
.form-group select::placeholder {
    color: #cbd5e1;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--color-brand-primary);
    box-shadow: 0 0 0 3px rgba(0, 177, 183, 0.12);
}

/* JS-functional class — must remain as CSS target */
.form-group input.field-error {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* BEM alias */
.form-group input.form-group__input--error {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.field-error-msg {
    font-size: 0.775rem;
    color: #dc2626;
    margin-top: 0.35rem;
    display: none;
    font-weight: 600;
}

/* Read-only input helper */
.input--readonly {
    background: #f8fafc !important;
    color: #94a3b8 !important;
    cursor: not-allowed !important;
}

/* Hint text under a field */
.form-group__hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.3rem;
}


/* ── 11. PASSWORD WRAP ───────────────────────────────────────────────────── */
.password-wrap { position: relative; }

.password-wrap input { padding-right: 2.8rem; }

/* JS-functional class — must remain as CSS target */
.toggle-pw {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: color 0.15s;
    -webkit-appearance: none;
}

.toggle-pw:hover { color: var(--color-brand-primary); }

.toggle-pw:focus {
    outline: 2px solid var(--color-brand-primary);
    outline-offset: 2px;
    border-radius: 4px;
}


/* ── 12. ICON SIZE HELPERS ───────────────────────────────────────────────── */
.material-symbols-outlined { font-weight: 300; }
.icon-size-lg { font-size: 18px; }
.icon-size-md { font-size: 16px; }
.icon-size-sm { font-size: 15px; }
.icon-faded   { opacity: 0.3; }

/* ── 13. TABLE UTILITIES ─────────────────────────────────────────────────── */
.th--right { text-align: right; }


/* ── 14. USER MENU ───────────────────────────────────────────────────────── */
/*  Shared across all pages that include a header user-menu icon + dropdown.
    pages/user-dashboard.css and pages/quota-table.css repeat these styles
    for historical reasons; this definition makes the component available to
    admin pages without extra per-page CSS.  */

/* NO position:relative here — the dropdown must position itself relative to
   .page-header (position:sticky), so it spans the full header width and sits
   flush with the right edge, ignoring the padding of .header-container.     */
.user-menu {
    position: static;
}

.user-menu__toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--color-brand-primary-dark);
    font-size: 2.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.user-menu__toggle:hover,
.user-menu__toggle[aria-expanded="true"] {
    color: var(--color-brand-primary);
}

.user-menu__dropdown {
    position: absolute;
    top: 100%;              /* flush — grows downward from header bottom line  */
    right: 0;
    min-width: 240px;

    background: rgba(255, 255, 255);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    border-top: 3px solid var(--color-brand-primary);
    border-left: 1px solid var(--color-border-brand);
    border-bottom: 1px solid var(--color-border-brand);
    border-right: none;
    border-radius: 0 0 0 var(--radius-md);
    box-shadow: -4px 8px 28px rgba(0, 52, 73, 0.18);

    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: var(--z-dropdown);

    /* Slide-from-right + fade — start state */
    transform: translateX(32px);
    opacity: 0;
    pointer-events: none;
    transition:
        transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        opacity   0.22s ease;
}

.user-menu__dropdown.is-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.user-menu__dropdown[hidden] { display: none !important; }

.user-menu__greeting {
    display: block;
    padding: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: default;
}

.user-menu__divider {
    height: 1px;
    background: var(--color-border);
    margin: 0.1rem 0;
}

/* Dropdown buttons: full width, centred */
.user-menu__dropdown .btn {
    width: 100%;
    justify-content: center;
}

/* Secondary buttons inside dropdown get the same teal border as in .header-actions */
.user-menu__dropdown .btn-secondary,
.user-menu__dropdown .btn--secondary {
    border: 1.3px solid var(--color-brand-primary);
}
