/* _core/css/theme_master.css */
/* EXTRACCIÓN DEL DISEÑO DE "CONTROL DE EQUIPO" (JD LABS) */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap');

:root {
    /* --- PALETA DE COLORES (Extradia de Tailwind Slate) --- */
    --bg-body: var(--ops-0f172a, #0f172a);
    /* El fondo azul muy oscuro */
    --bg-card: var(--ops-1e293b, #1e293b);
    /* El fondo de las tarjetas/header */
    --bg-input: var(--ops-334155, #334155);
    /* Fondo de inputs */

    --border-color: var(--ops-334155, #334155);
    /* Color de bordes sutiles */

    --text-primary: var(--ops-f8fafc, #f8fafc);
    /* Texto blanco brillante */
    --text-secondary: var(--ops-94a3b8, #94a3b8);
    /* Texto gris claro para etiquetas */

    /* --- COLORES DE ACCIÓN --- */
    --primary: #3b82f6;
    /* Azul brillante (Botones principales) */
    --primary-hover: #2563eb;

    --success: #10b981;
    /* Verde Esmeralda (Activos/Guardar) */
    --warning: #f59e0b;
    /* Ambar (Patio/Alertas) */
    --danger: #ef4444;
    /* Rojo (Eliminar/Error) */

    /* --- DIMENSIONES --- */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;
    --sidebar-transition-ms: 180ms;
    --header-height: 70px;
    --radius: 0.75rem;
    /* Bordes redondeados modernos (12px) */

    /* --- ALIAS DE COMPATIBILIDAD ---
       Variables usadas en módulos específicos como alias
       de las variables canónicas del sistema.
       No cambian ningún color visible. */
    --text-muted: var(--text-secondary);
    /* var(--ops-94a3b8, #94a3b8) — textos label/placeholder */
    --text-main: var(--text-primary);
    /* var(--ops-f8fafc, #f8fafc) — texto principal           */
    --bg-main: var(--bg-body);
    /* var(--ops-0f172a, #0f172a) — fondo global              */
    --bg-dark: var(--bg-card);
    /* var(--ops-1e293b, #1e293b) — fondos oscuros            */
    --card-bg: var(--bg-card);
    /* var(--ops-1e293b, #1e293b) — fondo de tarjetas         */
    --accent: var(--primary);
    /* #3b82f6 — color de acento           */
}

/* --- RESET BÁSICO --- */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- RESPONSIVO: Ajustes para pantallas pequeñas --- */
@media (max-width: 1400px) {
    :root {
        font-size: 14px;
        /* Base más pequeña */
    }

    .app-sidebar {
        width: 220px;
        padding: 15px;
    }

    .app-main {
        padding: 20px;
    }
}

@media (max-width: 1200px) {
    :root {
        font-size: 13px;
    }

    .app-sidebar {
        width: 200px;
        padding: 12px;
    }

    .nav-link {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
}

/* --- BARRA LATERAL (SIDEBAR) --- */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-card);
    /* Mismo tono que tus tarjetas */
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    flex-shrink: 0;
    contain: layout paint;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.app-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 800;
    color: white;
    text-decoration: none;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    text-align: center;
    flex-shrink: 0;
}

.app-sidebar nav,
.app-sidebar .sidebar-nav,
#sidebar-nav {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 10px;
    padding-right: 5px;
}

/* Scrollbar fina para el sidebar */
.app-sidebar nav::-webkit-scrollbar,
.app-sidebar .sidebar-nav::-webkit-scrollbar,
#sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.app-sidebar nav::-webkit-scrollbar-track,
.app-sidebar .sidebar-nav::-webkit-scrollbar-track,
#sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar nav::-webkit-scrollbar-thumb,
.app-sidebar .sidebar-nav::-webkit-scrollbar-thumb,
#sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* --- SECCIÓN USUARIO EN SIDEBAR --- */
.sidebar-user-section {
    margin-top: auto;
    padding: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: center;
}

.sidebar-logout-btn {
    width: 100%;
    padding: 10px;
    background: rgba(248, 113, 113, 0.2);
    border: 1px solid rgba(248, 113, 113, 0.4);
    color: #f87171;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.sidebar-logout-btn:hover {
    background: rgba(239, 68, 68, 0.25);
}

.sidebar-logout-text {
    display: inline-block;
    max-width: 160px;
    opacity: 1;
    transform: translateX(0);
    white-space: nowrap;
    overflow: hidden;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    background-color: rgba(59, 130, 246, 0.15);
    /* Azul suave transparente - mejorado para contraste */
    color: #60a5fa;
    /* Azul más brillante para mejor contraste */
}

.nav-icon {
    margin-right: 12px;
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
}

/* --- ÁREA PRINCIPAL --- */
.app-main {
    flex-grow: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* --- TARJETAS (CARDS) --- */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 25px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    /* Sombra oscura */
}

h1,
h2,
h3 {
    margin-top: 0;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    margin-bottom: 5px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0;
}

/* --- FORMULARIOS & INPUTS (ESTILO DARK) --- */
label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.05em;
}

input,
select,
textarea {
    width: 100%;
    background-color: rgba(var(--ops-rgb-15-23-42, 15, 23, 42), 0.5);
    /* Fondo input oscuro */
    border: 1px solid var(--border-color);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* --- BOTONES --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.1s, box-shadow 0.2s;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background-color: var(--danger);
    color: white;
}

/* --- TABLAS OSCURAS --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    table-layout: fixed;
}

thead th {
    text-align: center;
    padding: 15px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody td {
    text-align: center;
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

/* --- UTILIDADES VISUALES --- */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-active {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-inactive {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* --- PESTAÑAS (TABS) --- */
.tabs-container {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px 0;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* --- MODAL --- */
.modal-overlay {
    background: rgba(0, 0, 0, 0.8);
    /* Fondo más oscuro estilo tu CRM */
    backdrop-filter: blur(4px);
    /* Efecto borroso elegante */
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: white;
}

/* --- TOAST MODAL (Reemplazo de alert/confirm nativos) --- */
.toast-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.toast-modal-overlay.active {
    display: flex;
}

.toast-modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    animation: toastSlideIn 0.3s ease-out;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.toast-modal-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.toast-modal-icon.success {
    color: var(--success);
}

.toast-modal-icon.error {
    color: var(--danger);
}

.toast-modal-icon.warning {
    color: var(--warning);
}

.toast-modal-icon.question {
    color: var(--primary);
}

.toast-modal-message {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 25px;
    line-height: 1.5;
}

.toast-modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.toast-modal-buttons .btn {
    min-width: 100px;
    padding: 12px 24px;
}

/* ==========================================
   DESKTOP - Sidebar collapsible toggle
   ========================================== */

/* Smooth transition for sidebar and main */
.app-sidebar {
    overflow-y: auto;
    overflow-x: hidden;
}

/* Subtle sidebar scrollbar */
.app-sidebar::-webkit-scrollbar {
    width: 4px;
}

.app-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Toggle button at bottom of sidebar */
.sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 8px;
    color: #60a5fa;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
    margin-top: 10px;
}

.sidebar-toggle-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: #3b82f6;
}

/* Nav link text wrapper for hide/show */
.nav-text {
    display: inline-block;
    max-width: 180px;
    opacity: 1;
    transform: translateX(0);
    white-space: nowrap;
    overflow: hidden;
}

/* Sidebar user section text */
.sidebar-user-section {
    overflow: hidden;
}

body.sidebar-transitioning .app-sidebar {
    transition: width var(--sidebar-transition-ms) cubic-bezier(0.2, 0, 0, 1),
        padding var(--sidebar-transition-ms) cubic-bezier(0.2, 0, 0, 1);
    will-change: width, padding;
}

body.sidebar-transitioning .nav-text,
body.sidebar-transitioning .sidebar-logout-text,
body.sidebar-transitioning .sidebar-user-section,
body.sidebar-transitioning .sidebar-header-mobile .app-logo {
    transition: opacity calc(var(--sidebar-transition-ms) - 40ms) ease,
        transform calc(var(--sidebar-transition-ms) - 40ms) ease,
        max-width calc(var(--sidebar-transition-ms) - 40ms) ease;
}

/* --- COLLAPSED STATE --- */
body.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
    padding: 10px 8px;
}

body.sidebar-collapsed .sidebar-header-mobile .app-logo {
    font-size: 0;
    gap: 0;
    justify-content: center;
    align-items: center;
    padding-bottom: 10px;
    margin-bottom: 15px;
    width: 100%;
}

body.sidebar-collapsed .sidebar-header-mobile .app-logo i {
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

body.sidebar-collapsed .sidebar-close-btn {
    display: none;
}

body.sidebar-collapsed .nav-link {
    padding: 12px;
    justify-content: center;
    margin-bottom: 4px;
}

body.sidebar-collapsed .nav-text {
    max-width: 0;
    opacity: 0;
    transform: translateX(-8px);
    margin: 0;
    pointer-events: none;
}

body.sidebar-collapsed .nav-icon {
    margin-right: 0;
    width: auto;
    font-size: 1.15rem;
}

body.sidebar-collapsed .sidebar-user-section {
    opacity: 1;
    pointer-events: auto;
    height: auto;
    padding: 0;
    margin-top: 10px;
    border-top: none;
    overflow: visible;
}

body.sidebar-collapsed .sidebar-toggle-btn {
    padding: 8px;
    font-size: 0.9rem;
}

body.sidebar-collapsed .sidebar-logout-btn {
    padding: 8px;
    font-size: 0.9rem;
    gap: 0;
}

body.sidebar-collapsed .sidebar-logout-text {
    max-width: 0;
    opacity: 0;
    transform: translateX(-6px);
}

/* Tooltip on hover when collapsed */
body.sidebar-collapsed .nav-link {
    position: relative;
}

body.sidebar-collapsed .nav-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: white;
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

/* ==========================================
   MOBILE RESPONSIVE - Sidebar colapsable
   ========================================== */

/* Botón hamburguesa INLINE (dentro del header) - oculto por defecto */
.mobile-menu-btn-inline {
    display: none;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* Header del sidebar para móvil - botón cerrar */
.sidebar-header-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    padding-right: 0;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.sidebar-header-mobile .app-logo {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Botón cerrar sidebar - oculto en desktop */
.sidebar-close-btn {
    display: none;
    width: 36px;
    height: 36px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #ef4444;
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex: 0 0 auto;
    margin-left: 0;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.sidebar-close-btn:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Overlay para cerrar sidebar en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-overlay.active {
    display: block;
}

/* Clase para ocultar en móvil */
.hide-on-mobile {
    display: inline;
}

@media (max-width: 768px) {

    /* Mostrar botón hamburguesa INLINE */
    .mobile-menu-btn-inline {
        display: flex;
    }

    .sidebar-close-btn {
        display: none !important;
    }

    /* Ocultar elementos en móvil */
    .hide-on-mobile {
        display: none !important;
    }

    /* Sidebar se convierte en overlay */
    .app-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        width: 280px;
        z-index: 999;
        transition: left 0.3s ease;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.5);
        padding-bottom: 34px;
        contain: none;
    }

    .app-sidebar.mobile-open {
        left: 0;
    }

    /* Main content ocupa todo el ancho */
    .app-main {
        width: 100%;
        padding: 20px 15px;
    }

    .sidebar-toggle-btn {
        margin-bottom: 12px;
    }

    /* Ajustes generales para móvil */
    body {
        flex-direction: column;
    }

    .page-title {
        font-size: 1.4rem;
    }

    .card {
        padding: 15px;
    }

    /* Grid de tablas responsive */
    .table-container {
        overflow-x: auto;
    }

    table {
        min-width: 600px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .nav-text,
    .sidebar-logout-text,
    .sidebar-toggle-btn,
    .sidebar-logout-btn,
    .sidebar-user-section {
        transition: none !important;
    }
}
