/* =========================================================
   Success UI Framework v2.0 (core)
   Autor: Fernando Salguero — Limpieza y consolidación
   Notas:
   - Unifica tokens, elimina duplicados y mejora accesibilidad.
   - Mantiene compatibilidad con las clases usadas en index.html.
   ========================================================= */

/* ---------- Tokens / Reset ---------- */
:root {
    --primary-color: #5b21b6;
    --sidebar-bg: #fff;
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 70px;
    --transition: 0.3s ease;
    --text-color: #333;
    --icon-color: #5b21b6;
    --shadow: 0 0 10px rgba(0, 0, 0, 0.06);
    --border-radius: 12px;
    --font-family: 'Segoe UI', sans-serif;

    /* neutrales utilitarias */
    --neutral-100: #f5f5f5;
    --neutral-200: #eee;
    --neutral-300: #e7e7e7;
}

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

body {
    font-family: var(--font-family);
    background: var(--neutral-100);
    color: var(--text-color);
    overflow-x: auto;
}

/* Utilidad para lectores de pantalla */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ---------- Layout principal ---------- */
.layout {
    display: flex;
    min-height: 100vh;
    transition: var(--transition);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    max-height: 100vh;
    overflow-y: auto;
    transition: var(--transition);
    z-index: 1000;
}

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

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

.sidebar-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
    color: var(--icon-color);
    font-size: 1.8rem;
}

.logo-text {
    font-size: 1.2rem;
    font-weight: bold;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .link-text {
    display: none;
}

.sidebar-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sidebar-menu li {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-menu li:hover {
    background: #f0f0f0;
}

.sidebar-footer {
    padding: 1rem;
    text-align: center;
    background: #fff;
    position: sticky;
    bottom: 0;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--icon-color);
    font-size: 1.5rem;
}

/* Contenido principal */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
    min-width: 0;
}

/* Navbar */
.navbar {
    background: #fff;
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.navbar-title {
    font-size: 1.2rem;
    font-weight: bold;
}

/* Contenido */
.content {
    padding: 2rem;
}

.card {
    background: #fff;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    box-sizing: border-box;
}

/* Variante neutra para demostraciones */
.card-neutral {
    background-color: var(--neutral-200);
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .card-grid.grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100dvh;
        z-index: 1000;
        left: -250px;
        width: var(--sidebar-width);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar.collapsed {
        left: -70px;
    }

    .main {
        margin-left: 0;
    }

    .form-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-buttons {
        display: flex;
        flex-direction: column;
        gap: 1.2rem;
        margin-top: 1rem;
    }

    .form-buttons .btn {
        width: 100%;
        padding: 0.85rem;
        font-size: 1rem;
    }

    .card-grid.grid-2,
    .card-grid.grid-3,
    .card-grid.grid-4 {
        grid-template-columns: 1fr !important;
    }
}

/* ---------- Botones ---------- */
.btn {
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.2s ease;
    color: #fff;
}

.btn-aceptar {
    background-color: #4caf50;
}

.btn-aceptar:hover {
    background-color: #43a047;
}

.btn-cancelar {
    background-color: #f44336;
}

.btn-cancelar:hover {
    background-color: #e53935;
}

.btn-info {
    background-color: #2196f3;
}

.btn-info:hover {
    background-color: #1976d2;
}

.btn-disabled {
    background-color: #ccc !important;
    color: #666 !important;
    cursor: not-allowed !important;
    pointer-events: none;
    box-shadow: none;
}

/* ---------- Formularios ---------- */
.form-modern {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* NUEVO: capa mínima para .form-modern */

.form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.form-grid.grid-2,
.form-grid.grid-3,
.form-grid.grid-4 {
    display: grid;
    gap: 1rem;
}

.form-grid.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-grid.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-grid.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.input-group label {
    margin-bottom: 0.1rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.input-icon {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    padding: 0.6rem 1rem;
    gap: 0.5rem;
}

.input-icon span.material-icons {
    color: var(--icon-color);
    font-size: 1.2rem;
}

.input-icon input,
.input-icon select,
.input-icon textarea {
    border: none;
    outline: none;
    font-size: 1rem;
    width: 100%;
    background: transparent;
}

/* Errores */
.has-error .input-icon {
    border: 1px solid #f44336;
}

.input-error-text {
    color: #f44336;
    font-size: 0.85rem;
    margin-top: 0.3rem;
    display: none;
}

/* ---------- Tabla de datos (consolidado) ---------- */
.tabla-card {
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    background: #fff;
    overflow: hidden;
}

.tabla-wrapper {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    table-layout: auto;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid #ddd;
}

/* ---------- Badges ---------- */
.badge {
    padding: 0.3rem 0.7rem;
    border-radius: 100px;
    font-size: 0.8rem;
    color: #fff;
}

.badge.success {
    background-color: #4caf50;
}

.badge.warning {
    background-color: #ff9800;
}

.badge.danger {
    background-color: #f44336;
}

/* ---------- Alertas flotantes ---------- */
.floating-alert {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 1rem 2rem;
    border-radius: 8px;
    color: #333;
    font-weight: bold;
    z-index: 2000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.3s ease;
}

.floating-alert.success {
    background-color: #d4edda;
    color: #155724;
}

.floating-alert.error {
    background-color: #f8d7da;
    color: #721c24;
}

.floating-alert.info {
    background-color: #d1ecf1;
    color: #0c5460;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 500px;
    width: 90%;
    text-align: center;
    animation: fadeInModal 0.3s ease;
}

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

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

/* ---------- Grillas de tarjetas ---------- */
.card-grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card-grid.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.card-grid.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.card-grid.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* ---------- Tooltip ---------- */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    font-size: 0.75rem;
    padding: 0.4rem 0.7rem;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 99999;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ---------- Spinner global ---------- */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 6px solid #ccc;
    border-top: 6px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.hidden {
    display: none;
}

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

/* ---------- Tabs ---------- */
.tabs {
    margin-top: 1rem;
}

.tab-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.tab-button {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: #e0e0e0;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s ease;
}

.tab-button.active {
    background-color: var(--primary-color);
    color: #fff;
}

.tab-content {
    display: none;
    background: #fff;
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

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

/* ---------- Select/Options (mantener compatibilidad doc) ---------- */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select {
    width: 100%;
    position: relative;
    cursor: pointer;
}

.custom-select input {
    border: none;
    outline: none;
    font-size: 1rem;
    width: 100%;
    background: transparent;
}

.custom-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: #fff;
    box-shadow: var(--shadow);
    border-radius: 8px;
    max-height: 160px;
    overflow-y: auto;
    display: none;
    padding: 0.3rem 0;
    margin-top: 0.3rem;
}

.custom-options li {
    padding: 0.6rem 1rem;
    cursor: pointer;
}

.custom-options li:hover {
    background: #f0f0f0;
}

/* ---------- Switch ---------- */
.switch {
    position: relative;
    display: inline-block;
    width: 45px;
    height: 25px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    background-color: #ccc;
    border-radius: 50px;
    inset: 0;
    transition: 0.3s;
}

.slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 3.5px;
    background: #fff;
    transition: 0.3s;
    border-radius: 50%;
}

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

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

/* ---------- Acordeón ---------- */
.accordion {
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    background: var(--neutral-300);
}

.accordion-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    font-weight: bold;
    border-bottom: 1px solid #112c4e;
}

.accordion-body {
    padding: 1rem;
    display: none;
}

/* Estados abiertos por clase (evita estilos inline desde JS) */
.accordion.open .accordion-body {
    display: block;
}

.subcategorias.open {
    display: block;
}


/* ---------- Selector simple / múltiple ---------- */
.selector-list label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0;
    font-size: 0.95rem;
    color: var(--text-color);
    cursor: pointer;
    transition: color 0.3s ease;
}

.selector-list input[type="checkbox"]:checked+span,
.selector-list input[type="radio"]:checked+span {
    color: var(--primary-color);
    font-weight: 600;
}

/* ---------- Smart selector ---------- */
.smart-selector {
    max-width: 400px;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    background: #fff;
}

.smart-selector-search {
    margin-top: 12px;
    width: 100%;
    padding: 0.6rem 0.8rem;
    margin-bottom: 1rem;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    font-size: 1rem;
}

.smart-selector-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.smart-selector-list label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.95rem;
    color: var(--text-color);
}

.smart-selector-list input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

/* ---------- Toastify ---------- */
#toast-container,
#toast-container-boton {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* Base compartida para toasts (DRY) */
.toast,
.toast-boton {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: fadeInRight 0.4s ease;
}

/* Solo los toasts auto-ocultables animan salida */
.toast {
    animation: fadeInRight 0.4s ease, fadeOut 0.4s ease 4.5s forwards;
}


.toast.success {
    background-color: #4caf50;
}

.toast.error {
    background-color: #f44336;
}

.toast.info {
    background-color: #2196f3;
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

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

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.toast-boton {
    min-width: 250px;
    padding: 1rem 1.2rem;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: fadeInRight 0.4s ease;
}

.toast-boton.success {
    background-color: #4caf50;
}

.toast-boton.error {
    background-color: #f44336;
}

.toast-boton.info {
    background-color: #2196f3;
}

.toast-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
}

/* ---------- Tarjetas de usuario / producto (consolidado) ---------- */
.user-card {
    border: 2px solid var(--primary-color);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.user-name {
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    font-weight: normal;
    font-size: 1rem;
}

.icon-email {
    font-size: 20px;
    color: #7e22ce;
}

.product-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
    transition: box-shadow 0.2s ease;
}

.product-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.product-header {
    background-color: #e0e7ff;
    padding: 1rem;
    border-bottom: 1px solid #ccc;
}

.product-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: bold;
    color: #1e1e2f;
}

.product-header p {
    margin: 0.4rem 0 0;
    font-size: 0.85rem;
    color: #666;
}

.product-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.product-top {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: space-between;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.role {
    font-size: 0.85rem;
    color: #5b21b6;
}

.team-avatars {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.extra-count {
    background-color: #e0f7fa;
    color: #00bcd4;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
}

.product-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.metric {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: #555;
}

.metric strong {
    font-size: 1.1rem;
    color: #000;
}

.btn-view {
    padding: 0.5rem 1rem;
    background-color: #e0e0ff;
    color: #333;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s ease;
}

.btn-view:hover {
    background-color: #c7d2fe;
}

/* ---------- Acordeón de categorías ---------- */
.accordion-categorias {
    list-style: none;
    padding: 0;
    margin: 0;
}

.accordion-categorias li {
    margin-bottom: 0.5rem;
}

.categoria-btn {
    background: none;
    border: none;
    padding: 0.4rem 0;
    font-size: 1rem;
    color: var(--text-color);
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-weight: 500;
    transition: color 0.2s ease;
}

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

.subcategorias {
    display: none;
    padding-left: 1rem;
    margin-top: 0.3rem;
    list-style: none;
}

.subcategorias li {
    padding: 0.3rem 0;
    font-size: 0.95rem;
    border-bottom: 1px dashed #eee;
    cursor: pointer;
}

.subcategorias li:hover {
    color: var(--primary-color);
}

/* ---------- Responsive triple layout ---------- */
.triple-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.triple-categorias {
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.triple-categorias h3 {
    margin-bottom: 1rem;
}

.triple-categorias ul {
    list-style: none;
    padding: 0;
}

.triple-categorias li {
    padding: 0.5rem 0;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.triple-categorias li:hover {
    color: var(--primary-color);
}

.triple-derecha {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.triple-form {
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.triple-form h3 {
    margin-bottom: 1rem;
}

.triple-form form input,
.triple-form form select {
    width: 100%;
}

.triple-tarjetas .card {
    min-height: 120px;
}

@media (max-width: 768px) {
    .triple-layout {
        grid-template-columns: 1fr;
    }

    .triple-categorias,
    .triple-form,
    .triple-tarjetas {
        width: 100%;
    }

    .triple-tarjetas.card-grid.grid-3 {
        grid-template-columns: 1fr;
    }

    .triple-derecha {
        gap: 1.5rem;
    }

    .form-grid.grid-4 {
        grid-template-columns: 1fr !important;
    }

    .triple-form .input-group {
        width: 100%;
    }

    .product-card {
        flex-direction: column;
    }

    .product-footer {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ===== Dropdown multiselección (checkbox) ===== */
.dropdown {
    position: relative;
    width: 100%;
}

.dropdown-toggle {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    background: #fff;
    text-align: left;
    cursor: pointer;
}

.dropdown-toggle:focus {
    outline: 2px solid rgba(91, 33, 182, 0.35);
    outline-offset: 2px;
}

.dropdown-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 0.4rem 0.4rem;
    display: none;
    z-index: 1200;
    max-height: 220px;
    overflow-y: auto;
}

.dropdown.open .dropdown-panel {
    display: block;
}

.dropdown-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
}

.dropdown-option:hover {
    background: #f6f6f6;
}

.dropdown-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
    cursor: pointer;
}