/* OneProde base styles */

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Tema Azul (Predeterminado) */
    --bg-sidebar: #1e3a5f;
    --bg-main: #f5f7fa;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-table-header: #f8fafc;
    --bg-hover: #f1f5f9;
    --bg-input: #ffffff;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-sidebar: #b8c5d6;
    --text-sidebar-hover: #ffffff;
    --text-sidebar-active-bg: rgba(59, 130, 246, 0.3);
    --text-sidebar-active-border: #3b82f6;

    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.08);

    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --primary-text: #ffffff;

    --badge-success-bg: #d1fae5;
    --badge-success-text: #065f46;
    --badge-danger-bg: #fee2e2;
    --badge-danger-text: #991b1b;
    --badge-warning-bg: #fef3c7;
    --badge-warning-text: #92400e;

    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.35);

    /* Colores base para el preview del admin */
    --blue-color: #3b82f6;
    --green-color: #22c55e;
    --red-color: #ef4444;
    --orange-color: #f97316;
}

/* ======================================= */
/* ==   NUEVAS PALETAS DE COLOR           == */
/* ======================================= */

html[data-company-theme="red"] {
    --primary-color: #ef4444; /* Rojo brillante (para botones/links) */
    --primary-hover: #dc2626; /* Rojo más oscuro para hover */
    --primary-text: #ffffff;

    /* Colores de Sidebar */
    --bg-sidebar: #800020;
    --text-sidebar: #f1f5f9; /* Un blanco suave */
    /* Tu color para el panel */
    --text-sidebar-active-bg: rgba(239, 68, 68, 0.3); /* Transparente del primario */
    
    /* Colores derivados */
    --text-sidebar-active-border: #FFFFFF;
    --focus-ring: 0 0 0 3px rgba(239, 68, 68, 0.35);
}

/* == Tema Verde == */
html[data-company-theme="green"] {
    --primary-color: #22c55e; /* verde-500 */
    --primary-hover: #16a34a; /* verde-600 */
    --primary-text: #ffffff;
    
    /* Colores de Sidebar */
    --bg-sidebar: #14532d; /* Un verde oscuro, ej: verde-900 */
    --text-sidebar-active-bg: rgba(34, 197, 94, 0.3); /* Un verde claro transparente */

    /* Colores derivados */
    --text-sidebar-active-border: #22c55e;
    --focus-ring: 0 0 0 3px rgba(34, 197, 94, 0.35);
}

/* == Tema Naranja == */
html[data-company-theme="orange"] {
    --primary-color: #f97316; /* naranja-500 */
    --primary-hover: #ea580c; /* naranja-600 */
    --primary-text: #ffffff;
    
    /* Colores de Sidebar */
    --bg-sidebar: #7c2d12; /* Un naranja oscuro, ej: naranja-900 */
    --text-sidebar-active-bg: rgba(249, 115, 22, 0.3); /* Un naranja claro transparente */

    /* Colores derivados */
    --text-sidebar-active-border: #f97316;
    --focus-ring: 0 0 0 3px rgba(249, 115, 22, 0.35);
}

/* ======================================= */
/* ==   FIN DE NUEVAS PALETAS           == */
/* ======================================= */


html {
    color-scheme: light;
    scroll-behavior: smooth;
}

html.dark {
    --bg-sidebar: #1f2937;
    --bg-main: #111827;
    --bg-card: #1f2937;
    --bg-header: #1f2937;
    --bg-table-header: #374151;
    --bg-hover: #374151;
    --bg-input: #374151;

    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-sidebar: #9ca3af;
    --text-sidebar-hover: #ffffff;
    --text-sidebar-active-bg: rgba(59, 130, 246, 0.18); /* <-- Este es el default azul */
    --border-color: #374151;
    --shadow-color: rgba(0, 0, 0, 0.2);

    --badge-success-bg: #064e3b;
    --badge-success-text: #d1fae5;
    --badge-danger-bg: #991b1b;
    --badge-danger-text: #fee2e2;
    --badge-warning-bg: #78350f;
    --badge-warning-text: #fef3c7;

    color-scheme: dark;
}


/* ======================================================== */
/* ==   TEMA DE EMPRESA PARA MODO OSCURO   == */
/* ======================================================== */


html[data-company-theme="red"].dark {
    --bg-sidebar: #800020; /* Mantenemos tu color en modo oscuro (CORREGIDO) */
    --text-sidebar-active-bg: rgba(239, 68, 68, 0.18); /* Rojo transparente */
}
html[data-company-theme="green"].dark {
    --bg-sidebar: #14532d; /* Mantenemos verde oscuro */
    --text-sidebar-active-bg: rgba(34, 197, 94, 0.18); /* Verde transparente */
}
html[data-company-theme="orange"].dark {
    --bg-sidebar: #7c2d12; /* Mantenemos naranja oscuro */
    --text-sidebar-active-bg: rgba(249, 115, 22, 0.18); /* Naranja transparente */
}




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

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 16px;
    background: var(--primary-color);
    color: var(--primary-text);
    padding: 10px 16px;
    z-index: 1100;
    border-radius: 8px;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 16px;
}

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

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    /* overflow-y: auto; */ /* <-- MODIFICADO: Eliminado para que flex funcione */
    transition: all 0.3s ease-in-out;
    z-index: 1000;
    border-right: 1px solid rgba(255, 255, 255, 0.08);

    display: flex; /* <-- MODIFICADO: Añadido */
    flex-direction: column; /* <-- MODIFICADO: Añadido */
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar-header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-sidebar-hover);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-sidebar-hover);
    font-size: 20px;
}

.sidebar-menu {
    padding: 20px 0;
    flex: 1; /* <-- MODIFICADO: Añadido */
    overflow-y: auto; /* <-- MODIFICADO: Añadido */
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-sidebar);
    border-left: 3px solid transparent;
    transition: background 0.2s ease, color 0.2s ease, border 0.2s ease;
    gap: 12px;
}

.menu-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.menu-item-label {
    flex: 1;
}

.icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    fill: none;
    stroke: currentColor;
}

.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .sidebar-toggle {
    margin: 0 auto;
}

.sidebar.collapsed .sidebar-logo {
    display: none;
}

.menu-item:hover,
.menu-item:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-sidebar-hover);
}

.menu-item.active {
    background: var(--text-sidebar-active-bg);
    color: var(--text-sidebar-hover);
    border-left-color: var(--text-sidebar-active-border);
}

.sidebar.collapsed .menu-item-label,
.sidebar.collapsed .logo-text {
    display: none;
}

.sidebar.collapsed .sidebar-logo-img {
    display: none;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    min-width: 0;
    transition: margin-left 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.main-content.expanded {
    margin-left: 80px;
}

.app-header {
    background: var(--bg-header);
    padding: 15px 30px;
    box-shadow: 0 2px 4px var(--shadow-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 900;
    border-bottom: 1px solid var(--border-color);
}

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

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

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
}

.notifications {
    position: relative;
    font-size: 20px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: background 0.2s ease, color 0.2s ease;
}

.notifications:hover,
.notifications:focus-visible {
    color: var(--text-primary);
    background: var(--bg-hover);
    text-decoration: none;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.user-menu {
    position: relative;
}

.user-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 15px;
    background: var(--bg-hover);
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 14px;
    color: var(--text-primary);
}

.avatar-container {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--primary-color);
    color: var(--primary-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

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

.user-avatar-initials {
    font-size: 13px;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
    min-width: 220px;
    display: none;
    z-index: 1000;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.user-dropdown.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--text-primary);
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
    background: var(--bg-hover);
}

.dropdown-item.logout {
    color: #ef4444;
}

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

.dropdown-item .menu-item-label {
    flex: 1;
}

.theme-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    gap: 12px;
}

.theme-buttons {
    display: inline-flex;
    border-radius: 8px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.theme-buttons button {
    background: none;
    border: none;
    padding: 6px 12px;
    font-size: 16px;
    line-height: 1;
}

.theme-buttons button.active {
    background: var(--primary-color);
    color: var(--primary-text);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.content-wrapper {
    padding: 30px;
    flex: 1;
    display: block;
}

.card {
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 2px 8px var(--shadow-color);
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

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

.card-title {
    font-size: 19px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 6px;
}

.card-content {
    padding: 24px;
    font-size: 15px;
    color: var(--text-secondary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    background: var(--bg-hover);
    color: var(--text-primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    text-decoration: none;
}

.btn:hover,
.btn:focus-visible {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

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

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary-color);
}

.form-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
}

.invite-autocomplete {
    position: relative;
}

.invite-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.invite-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 13px;
}

.invite-chip button {
    background: none;
    border: none;
    color: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.invite-chip button:hover,
.invite-chip button:focus-visible {
    color: var(--badge-danger-text);
}

.invite-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    max-height: 280px;
    overflow-y: auto;
    z-index: 60;
}

.invite-suggestion {
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-primary);
    cursor: pointer;
}

.invite-suggestion strong {
    font-size: 14px;
}

.invite-suggestion span {
    font-size: 12px;
    color: var(--text-secondary);
}

.invite-suggestion:hover,
.invite-suggestion:focus-visible {
    background: var(--bg-hover);
    outline: none;
}

.invite-suggestion.empty {
    cursor: default;
    color: var(--text-secondary);
}

.error {
    color: var(--badge-danger-text);
    background: var(--badge-danger-bg);
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-weight: 600;
}

.status-message {
    position: fixed;
    top: 90px;
    right: 30px;
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    min-width: 220px;
    display: none;
    z-index: 1200;
}

.status-message.show {
    display: block;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th {
    background: var(--bg-table-header);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
}

td {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

tr:hover td {
    background: var(--bg-hover);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: var(--badge-success-bg);
    color: var(--badge-success-text);
}

.badge-danger {
    background: var(--badge-danger-bg);
    color: var(--badge-danger-text);
}

.badge-warning {
    background: var(--badge-warning-bg);
    color: var(--badge-warning-text);
}

.empty-state {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state strong {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.breadcrumb a {
    color: inherit;
}

.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 600;
}

.footer {
    padding: 24px 30px;
    font-size: 13px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    background: transparent;
    text-align: center;
}


/* ======================================= */
/* ==   Estilos para los Logos (NUEVO)    == */
/* ======================================= */

/* Logo de empresa en el Header (tu caja roja superior) */
.header-company-logo {
    height: 36px; /* Ajusta a la altura de tu header */
    width: auto;
    max-width: 150px; /* Evita que sea gigante */
    display: none; /* Oculto en móvil por defecto */
    object-fit: contain;
}

/* Logo de empresa en el Sidebar (tu caja roja inferior) */
.sidebar-footer-logo {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    flex-shrink: 0; /* Evita que el logo se encoja */
}
.sidebar-footer-logo img {
    max-width: 100%;
    height: auto;
    max-height: 50px; /* Límite de altura */
    object-fit: contain;
    display: block;
    margin: 0 auto;
    opacity: 0.85;
}


@media (max-width: 1024px) {
    .sidebar {
        left: -260px;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.35);
    }

    .sidebar.visible {
        left: 0;
    }

    .main-content,
    .main-content.expanded {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    .sidebar-toggle {
        display: none;
    }

    .mobile-toggle {
        display: inline-flex;
    }

    .header-right {
        gap: 12px;
    }

    .user-menu-btn span:nth-child(2) {
        display: none;
    }

    .content-wrapper {
        padding: 24px 20px;
    }

    .card-header,
    .card-content {
        padding: 20px;
    }

    table {
        min-width: 500px;
    }
}

/* MODIFICADO: Añadido media query para el logo del header */
@media (min-width: 768px) {
    .header-company-logo {
        display: block; /* Visible en tablet/desktop */
        margin-left: 16px;
    }
}


@media (max-width: 480px) {
    .content-wrapper {
        padding: 20px 16px;
    }

    .card {
        margin-bottom: 20px;
    }

    table {
        min-width: 420px;
    }
}

/* ======================================= */
/* ==   Estilos para el Admin de Temas    == */
/* ======================================= */
.theme-selector-admin {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 12px;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.theme-option:has(input:checked) {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.theme-option input[type="radio"] {
    /* Oculta el radio button default */
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-preview {
    display: block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--theme-preview-color, #ccc); /* Usa la variable! */
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* MODIFICADO: Ocultar logo del footer en sidebar colapsado */
.sidebar.collapsed .sidebar-footer-logo {
    display: none; /* Ocultar en sidebar colapsado */
}

/* Estilo para el nuevo logo en el sidebar */
.sidebar-logo-img {
    width: 30px;  /* Ajusta este tamaño si es necesario */
    height: 30px;
    object-fit: contain; /* Para que no se deforme */
}

/* ======================================= */
/* ==   Estilos para Logos de Empresa     == */
/* ======================================= */

/* --- Logo del Encabezado (Header) --- */
.header-company-logo {
    display: block;
    /* Ajusta esta altura a lo que necesites */
    max-height: 32px; 
    width: auto;
    object-fit: contain;
    /* Evita que se encoja o desaparezca si no hay espacio */
    flex-shrink: 0; 
}

/* --- Logo del Pie del Panel (Sidebar) --- */
.sidebar-footer-logo {
    padding: 20px;
    margin-top: auto; /* Esto lo empuja al fondo */
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar-footer-logo img {
    width: 100%;
    /* Ajusta esta altura máxima */
    max-height: 50px; 
    object-fit: contain;
    display: block;
}

/* ======================================= */
/* ==   Botón Back to Top                 == */
/* ======================================= */

.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    color: var(--primary-text);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--shadow-color);
    transition: opacity 0.3s ease, transform 0.2s ease, background-color 0.2s ease;
    z-index: 1000;
    font-size: 20px;
    opacity: 0;
}

.back-to-top.visible {
    display: flex;
    opacity: 1;
}

.back-to-top:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-color);
}

.back-to-top:active {
    transform: translateY(0);
}

.back-to-top svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 768px) {
    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
    
    .back-to-top svg {
        width: 20px;
        height: 20px;
    }
}