:root {
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --primary-green: #48bb78;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --amazon-orange: #ff9900;
    --ml-yellow: #fff159;
    --shopify-blue: #96bf48;
    --btn-hover: #334155;
    --distribucion-blue: #3b82f6;
}

.platform-distribucion {
    color: var(--distribucion-blue);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

.mobile-appbar,
.mobile-sidebar-backdrop {
    display: none;
}

/* Sidebar Layout */
.sidebar {
    width: 260px;
    min-width: 0;
    flex-shrink: 0;
    background: var(--card-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}

.sidebar.sidebar-collapsed {
    display: none;
}

/* Al ocultar el menú, el contenido recupera el margen de 260px
   que maestros.css reservaba para el menú fijo. */
.sidebar.sidebar-collapsed ~ .main-content {
    margin-left: 0;
}

/* Asa de plegado — discreta, dentro del borde derecho del menú */
.sidebar-toggle-btn {
    position: fixed;
    top: 50%;
    left: 260px;
    transform: translate(-100%, -50%);
    z-index: 1100;
    width: 18px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 1;
    pointer-events: auto;
    transition: left 0.22s ease, background 0.15s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #94a3b8;
}

/* Con el menú plegado, el asa queda como pestañita en el borde izquierdo */
.sidebar-toggle-btn.is-collapsed {
    left: 0;
    transform: translate(0, -50%);
    background: var(--card-bg);
    border-radius: 0 6px 6px 0;
}

/* ── Sub-navegación horizontal de módulo (pestañas de subsección) ── */
.module-subnav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    margin-bottom: 22px;
}

.module-subnav-tab {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.module-subnav-tab:hover {
    color: var(--text-main);
}

.module-subnav-tab.active {
    color: var(--text-main);
    border-bottom-color: #6366f1;
}

.sidebar-header {
    padding: 20px 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header img {
    height: 40px;
    margin-bottom: 10px;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 10px;
}

.main-content {
    flex: 1;
    padding: 0 30px 30px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ── Top Bar — botón de usuario flotante en la esquina (sin franja) ── */
.sv-topbar {
    position: fixed;
    top: 10px;
    right: 30px;
    z-index: 600;
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;
    background: transparent;
}
.sv-topbar-left { display: none; }
.sv-topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Settings wrapper (contains icon + dropdown) */
.sv-topbar-settings {
    position: relative;
}
.sv-topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.25s ease;
}
.sv-topbar-btn:hover {
    background: rgba(99,102,241,0.1);
    color: #a5b4fc;
}
.sv-topbar-btn--active {
    background: rgba(99,102,241,0.15);
    color: #a5b4fc;
}

/* Dropdown Menu — click-based */
.sv-settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    min-width: 220px;
    background: rgba(17,20,34,0.98);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(148,163,184,0.1);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.97);
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}
.sv-settings-dropdown.sv-settings-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Accordion group header */
.sv-dd-group {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #e2e8f0;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}
.sv-dd-group:hover {
    background: rgba(99,102,241,0.08);
}
.sv-dd-group.sv-dd-group--expanded {
    color: #a5b4fc;
}
.sv-dd-group-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    flex-shrink: 0;
}
.sv-dd-group.sv-dd-group--expanded .sv-dd-group-icon {
    color: #818cf8;
}
.sv-dd-arrow {
    margin-left: auto;
    font-size: 1.1rem;
    color: #475569;
    transition: transform 0.2s ease;
    line-height: 1;
}
.sv-dd-group.sv-dd-group--expanded .sv-dd-arrow {
    transform: rotate(90deg);
    color: #818cf8;
}
/* No arrow on direct links */
.sv-dd-group--link .sv-dd-arrow { display: none; }

/* Collapsible submenu */
.sv-dd-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    padding-left: 12px;
}
.sv-dd-submenu.sv-dd-submenu--open {
    max-height: 300px;
}

/* Divider */
.sv-dd-divider {
    height: 1px;
    margin: 4px 10px;
    background: rgba(148,163,184,0.08);
}

/* Sub-menu item */
.sv-settings-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    white-space: nowrap;
}
.sv-settings-item:hover {
    background: rgba(99,102,241,0.1);
    color: #e2e8f0;
}
.sv-settings-item svg {
    color: #818cf8;
    flex-shrink: 0;
}

/* Sidebar Accordion */
.nav-group {
    margin-bottom: 6px;
}

.nav-group-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: #f1f5f9;
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

.nav-group-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.nav-group.active .nav-group-header {
    color: var(--primary-green);
    background: rgba(72, 187, 120, 0.05);
}

.nav-group-header .arrow {
    font-size: 0.7rem;
    transition: transform 0.3s;
    opacity: 0.5;
}

.nav-group.active .nav-group-header .arrow {
    transform: rotate(180deg);
    opacity: 1;
}

.nav-sub-menu {
    display: none;
    padding-left: 18px;
    margin-top: 8px;
    flex-direction: column;
    gap: 6px;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    margin-left: 15px;
}

.nav-group.active .nav-sub-menu {
    display: flex;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.nav-item {
    padding: 8px 14px;
    color: #e2e8f0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
    color: var(--primary-green);
    background: rgba(72, 187, 120, 0.1);
}

@media (max-width: 900px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        display: block;
        min-height: 100dvh;
        background: #0a0e1a;
    }

    body.sv-mobile-nav-open {
        overflow: hidden;
    }

    .mobile-appbar {
        position: fixed;
        inset: 0 0 auto 0;
        z-index: 1200;
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 56px;
        padding: 9px 58px 9px 12px;
        background: rgba(10, 14, 26, 0.92);
        border-bottom: 1px solid rgba(148, 163, 184, 0.14);
        backdrop-filter: blur(16px) saturate(1.25);
        -webkit-backdrop-filter: blur(16px) saturate(1.25);
    }

    .mobile-nav-btn {
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(148, 163, 184, 0.18);
        border-radius: 10px;
        background: rgba(18, 24, 40, 0.86);
        color: #e2e8f0;
        cursor: pointer;
    }

    .mobile-nav-icon {
        width: 17px;
        height: 13px;
        display: inline-flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .mobile-nav-icon span {
        display: block;
        width: 100%;
        height: 2px;
        border-radius: 999px;
        background: currentColor;
        transition: transform 0.18s ease, opacity 0.18s ease;
    }

    .mobile-nav-btn.is-open .mobile-nav-icon span:nth-child(1) {
        transform: translateY(5.5px) rotate(45deg);
    }

    .mobile-nav-btn.is-open .mobile-nav-icon span:nth-child(2) {
        opacity: 0;
    }

    .mobile-nav-btn.is-open .mobile-nav-icon span:nth-child(3) {
        transform: translateY(-5.5px) rotate(-45deg);
    }

    .mobile-appbar-brand {
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 9px;
        color: #f8fafc;
        font-size: 0.9rem;
        font-weight: 700;
    }

    .mobile-appbar-brand img {
        height: 24px;
        max-width: 128px;
        object-fit: contain;
    }

    .mobile-sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1240;
        background: rgba(3, 7, 18, 0.58);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    body.sv-mobile-nav-open .mobile-sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar,
    .sidebar.sidebar-collapsed {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1300;
        display: flex;
        width: min(86vw, 320px);
        height: 100dvh;
        transform: translateX(-104%);
        transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
        background: rgba(18, 24, 40, 0.98);
        box-shadow: 26px 0 58px rgba(0, 0, 0, 0.42);
        border-right: 1px solid rgba(148, 163, 184, 0.16);
    }

    .sidebar.is-mobile-open {
        transform: translateX(0);
    }

    .sidebar-header {
        padding: 18px 16px 14px;
        text-align: left;
    }

    .sidebar-header img {
        height: 32px;
        margin: 0 0 8px;
    }

    .sidebar-header h1 {
        font-size: 1.05rem;
        line-height: 1.2;
    }

    .sidebar-nav {
        padding: 12px 10px 22px;
    }

    .nav-group-header {
        min-height: 44px;
        padding: 11px 13px;
        font-size: 0.84rem;
        font-weight: 650;
        letter-spacing: 0;
    }

    .nav-sub-menu {
        padding-left: 10px;
        margin-left: 12px;
        gap: 4px;
    }

    .nav-item {
        min-height: 40px;
        padding: 10px 12px;
        font-size: 0.8rem;
        font-weight: 560;
    }

    .sidebar-toggle-btn {
        display: none;
    }

    .main-content,
    .sidebar.sidebar-collapsed ~ .main-content {
        width: 100%;
        min-width: 0;
        margin-left: 0;
        padding: 66px 12px 24px;
    }

    .sv-topbar {
        top: 12px;
        right: 12px;
        z-index: 1210;
    }

    .sv-topbar-btn {
        width: 38px;
        height: 38px;
        border: 1px solid rgba(148, 163, 184, 0.14);
        background: rgba(18, 24, 40, 0.72);
    }

    .module-section {
        min-width: 0;
    }

    .module-subnav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        margin: -2px -2px 16px;
        padding: 4px 2px 10px;
        scrollbar-width: none;
    }

    .module-subnav::-webkit-scrollbar {
        display: none;
    }

    .module-subnav-tab {
        flex: 0 0 auto;
        min-height: 38px;
        padding: 8px 13px;
        border: 1px solid rgba(148, 163, 184, 0.14);
        border-radius: 999px;
        background: rgba(15, 23, 42, 0.58);
        font-size: 0.78rem;
    }

    .module-subnav-tab.active {
        color: #dbeafe;
        border-color: rgba(99, 102, 241, 0.46);
        background: rgba(99, 102, 241, 0.16);
    }
}

/* Sections */
.module-section {
    display: none;
}

.module-section.active {
    display: block;
    /* animation: fadeIn 0.4s ease; */
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Sub-Module stabilization */
.sub-module-section {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
}

@keyframes fadeInSub {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Old sub-nav compatibility */
.sub-nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.sub-nav-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.sub-nav-btn.active {
    background: rgba(72, 187, 120, 0.1);
    color: var(--primary-green);
}

/* ── Database Section: Category Chips & Table ── */
.db-chips-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    padding: 10px 0;
}

.db-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 20px;
    border: 1px solid #334155;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
}

.db-chip:hover {
    border-color: #475569;
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.04);
}

.db-chip.active {
    background: var(--chip-color, #3b82f6);
    border-color: var(--chip-color, #3b82f6);
    color: #fff;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.25);
}

.db-chip .chip-count {
    font-size: 0.65rem;
    opacity: 0.7;
    font-weight: 400;
}

/* Frozen first column */
.db-table-wrap {
    overflow-x: auto;
    border: 1px solid #334155;
    border-radius: 10px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    position: relative;
}

.db-table {
    border-collapse: collapse;
    font-size: 0.78rem;
    min-width: 100%;
}

.db-table thead {
    position: sticky;
    top: 0;
    z-index: 3;
}

.db-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #1e293b;
    border-bottom: 2px solid #334155;
    white-space: nowrap;
}

.db-table td {
    padding: 6px 10px;
    color: #cbd5e1;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.db-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.06);
}

.db-table .db-frozen {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #0f172a;
    border-right: 2px solid #334155;
    font-weight: 600;
    color: #e2e8f0;
}

.db-table thead .db-frozen {
    z-index: 4;
    background: #1e293b;
}

.db-table td.db-null {
    color: #475569;
    font-style: italic;
}

.db-table td.db-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.73rem;
    text-align: right;
}

/* Group header in table */
.db-table th.db-group-sep {
    border-left: 2px solid rgba(59, 130, 246, 0.3);
}
