/* ===== SIDEBAR 2.0 - RAIL + DRAWER ARCHITECTURE ===== */
/* Created: 2026-01-07 */

/* Layout Tokens */
:root {
    --sidebar-rail-width: 90px;
    --sidebar-drawer-width: 820px;
}

/* 1. SIDEBAR CONTAINER (The Rail) */
.dashboard-sidebar {
    /* Fixed Rail Dimensions */
    width: var(--sidebar-rail-width) !important;
    height: 100vh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 10000 !important;
    /* Highest priority */

    /* Rail Styling */
    background-color: #050505 !important;
    /* Darkest Black */
    border-right: 1px solid rgba(255, 255, 255, 0.05) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding: 20px 0 !important;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5) !important;
}

/* 2. RAIL HEADER (Logo) */
.sidebar-header {
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.sidebar-header .logo-image {
    width: 40px;
    height: auto;
    filter: brightness(0) invert(1) !important;
    /* Force white logo */
}

/* 3. RAIL CATEGORIES */
.sidebar-rail-nav {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.rail-item {
    width: 65px;
    /* Smaller than container to have margins */
    height: 60px;
    margin: 0 auto;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;

    border-radius: 12px;
    color: rgba(255, 255, 255, 0.5) !important;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    background: transparent !important;
    border: none !important;
}

.rail-item:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: #fff !important;
    transform: translateY(-2px);
}

.rail-item.active {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%) !important;
    color: #fff !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.rail-item i {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.rail-item span {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-align: center;
}

/* 4. FOOTER (User/Settings) */
.sidebar-footer {
    width: 100%;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* 5. SIDEBAR DRAWER (The Panel) */
.sidebar-drawer {
    position: fixed;
    top: 0;
    left: var(--sidebar-rail-width);
    /* Starts after Rail */
    width: min(var(--sidebar-drawer-width), calc(100vw - var(--sidebar-rail-width)));
    height: 100vh;
    background: #121212 !important;
    /* Solid dark background to prevent bleed-through */
    /* backdrop-filter: blur(20px); */
    /* -webkit-backdrop-filter: blur(20px); */
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    /* Distinct border */
    z-index: 9999 !important;
    /* Extremely high Z-index to force it on top */

    display: flex;
    flex-direction: column;

    /* Animation - Slide In/Out */
    transform: translateX(calc(-1 * var(--sidebar-drawer-width)));
    /* Fully hidden to left */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    /* Stronger shadow */
}

.sidebar-drawer.open {
    transform: translateX(0);
    /* Aligned right next to rail */
}

/* Drawer Content */
.drawer-header {
    height: 80px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: transparent;
}

.drawer-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff !important;
    /* Force White */
    letter-spacing: 1px;
    text-transform: uppercase;
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 12px;
}

/* ===== MEGA DRAWER LAYOUT ===== */
.drawer-content.mega {
    padding: 20px 20px 28px;
}

.drawer-mega-grid {
    --drawer-grid-gap: 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--drawer-grid-gap);
    max-width: 760px;
    margin: 0 auto;
}

/* Um único módulo não deve ocupar toda a área do drawer */
.drawer-mega-grid > .drawer-module-card:only-child {
    grid-column: 1 / -1;
    width: 100%;
    max-width: min(460px, 100%);
}

/*
 * Balanceia linhas ímpares em desktop:
 * 3 itens -> 2x1 (último centralizado)
 * 5 itens -> 2x2x1
 */
.drawer-mega-grid > .drawer-module-card:last-child:nth-child(odd):not(:only-child) {
    grid-column: 1 / -1;
    width: 100%;
    max-width: calc(50% - (var(--drawer-grid-gap) / 2));
    justify-self: center;
}

.drawer-module-card {
    position: relative;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.055) 0%, rgba(255, 255, 255, 0.03) 100%);
    border: 1px solid rgba(153, 201, 235, 0.2);
    border-radius: 14px;
    padding: 14px 14px 12px;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 150px;
}

.drawer-module-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 1px;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.06) 70%, transparent 100%);
    pointer-events: none;
    opacity: 0.55;
}

.drawer-module-card.active {
    border-color: rgba(190, 230, 255, 0.35);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.035) 100%);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
}

.drawer-module-card:hover {
    transform: translateY(-2px);
    border-color: rgba(190, 230, 255, 0.42);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.3);
}

.drawer-module-card.locked {
    opacity: 0.6;
}

.drawer-module-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: #f6fbff;
    margin-bottom: 2px;
    font-size: 1rem;
    letter-spacing: 0.1px;
}

.drawer-module-header i {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #d8efff;
    background: rgba(87, 147, 194, 0.2);
    border: 1px solid rgba(151, 205, 237, 0.25);
}

.drawer-module-actions {
    display: grid;
    gap: 8px;
}

.drawer-module-card.has-lists {
    min-height: 170px;
}

.drawer-module-fields {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
    display: grid;
    gap: 8px;
}

.drawer-field label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 6px;
}

.drawer-field-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.drawer-field-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.82rem;
    color: #ffffff;
    outline: none;
}

.drawer-field-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.drawer-field-action {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.drawer-field-action:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.drawer-module-lists {
    margin-top: 10px;
    display: grid;
    gap: 10px;
}

.drawer-module-list {
    padding-top: 10px;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
    display: grid;
    gap: 6px;
}

.drawer-module-list-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: rgba(255, 255, 255, 0.55);
}

.drawer-module-list-body {
    display: grid;
    gap: 6px;
}

.drawer-module-list-loading,
.drawer-module-list-empty {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 8px 10px;
}

.drawer-list-item {
    text-align: left;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 8px 10px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    display: grid;
    gap: 4px;
    transition: all 0.2s ease;
}

.drawer-list-item:hover {
    background: rgba(255, 255, 255, 0.09);
    color: #ffffff;
    transform: translateY(-1px);
}

.drawer-list-item.locked {
    opacity: 0.6;
    cursor: not-allowed;
}

.drawer-list-item-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 600;
}

.drawer-list-item-title i {
    width: 16px;
    text-align: center;
}

.drawer-list-item-meta {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.55);
}

.drawer-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 11px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.035) 100%);
    color: rgba(241, 250, 255, 0.92);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    transition: all 0.2s ease;
}

.drawer-action i {
    width: 16px;
    text-align: center;
    color: rgba(214, 238, 255, 0.94);
}

.drawer-action span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-action:hover {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.07) 100%);
    border-color: rgba(182, 223, 250, 0.3);
    color: #ffffff;
    transform: translateY(-1px);
}

.drawer-action.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #ffffff;
}

.drawer-action.locked {
    cursor: not-allowed;
    opacity: 0.7;
}

.drawer-empty {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.95rem;
    padding: 16px;
}

@media (max-width: 1080px) {
    .drawer-mega-grid {
        grid-template-columns: 1fr;
        max-width: 560px;
    }

    .drawer-mega-grid > .drawer-module-card:only-child,
    .drawer-mega-grid > .drawer-module-card:last-child:nth-child(odd):not(:only-child) {
        grid-column: auto;
        max-width: none;
        width: 100%;
        justify-self: stretch;
    }
}

/* Drawer Links */
.drawer-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    margin-bottom: 4px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8) !important;
    /* Force White/Grey */
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.95rem;
    position: relative;
    z-index: 10002;
    background: transparent !important;
    /* Remove any inherited background */
}

.drawer-item:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
    transform: translateX(4px);
}

.drawer-item.active {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%) !important;
    color: #ffffff !important;
    border-left: 3px solid #ffffff;
}

.drawer-item i {
    width: 24px;
    font-size: 1.1rem;
    margin-right: 12px;
    text-align: center;
    color: inherit;
    /* Inherit forced color */
}

/* ================= MOBILE OVERRIDES ================= */
/* Hide sidebar completely on mobile - use mobile-menu.js overlay instead */
@media (max-width: 768px) {
    .dashboard-sidebar {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    .sidebar-drawer {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Ensure main content takes full width on mobile */
    .dashboard-main {
        margin-left: 0 !important;
    }
}

/* ================= GRUPO PLANTA VIVA (COLAPSÁVEL) ================= */
.planta-viva-group {
    list-style: none;
    margin: 0;
    padding: 0;
}

.planta-viva-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: left;
}

.planta-viva-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.planta-viva-toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.planta-viva-toggle i:first-child {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.planta-viva-caret {
    margin-left: auto;
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.planta-viva-toggle[aria-expanded="true"] .planta-viva-caret {
    transform: rotate(180deg);
}

.planta-viva-items {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.2);
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    margin-left: 16px;
}

.planta-viva-items .nav-item {
    margin: 0;
}

.planta-viva-items .nav-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s ease;
}

.planta-viva-items .nav-item a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.planta-viva-items .nav-item.active a {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.2) 0%, transparent 100%);
    color: #fff;
    border-left: 2px solid #3b82f6;
    margin-left: -2px;
}

.planta-viva-items .nav-item a i {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
}

/* ================= DRAWER COLLAPSIBLE GROUP (Planta Viva & Bank Reconciliation) ================= */
.planta-viva-drawer-group,
.bank-reconciliation-drawer-group {
    margin-bottom: 6px;
}

.drawer-group-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 0;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    text-align: left;
}

.drawer-group-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.drawer-group-toggle.active {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0%, transparent 100%);
    color: #ffffff;
}

.planta-viva-drawer-caret,
.bank-reconciliation-drawer-caret {
    margin-left: auto;
    transition: transform 0.3s ease;
}

.planta-viva-drawer-items,
.bank-reconciliation-drawer-items {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 0 0 8px 8px;
    margin-top: 2px;
    overflow: hidden;
}

.drawer-sub-item {
    border-left: 2px solid transparent;
}

.drawer-sub-item:hover {
    border-left-color: rgba(255, 255, 255, 0.3);
}

.drawer-sub-item.active {
    border-left-color: #3b82f6 !important;
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.15) 0%, transparent 100%) !important;
}

/* ================= GRUPO COMPRAS (COLAPSÁVEL) ================= */
.purchases-group {
    list-style: none;
    margin: 0;
    padding: 0;
}

.purchases-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: left;
}

.purchases-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

/* ===== VOYGER THEME ENGINE — Sidebar overrides ===== */
/* When html.vt-themed is set, use CSS variables from voyger-theme.js */

.vt-themed .dashboard-sidebar {
    background-color: var(--vt-sidebar-bg, #050505) !important;
    border-right-color: var(--vt-sidebar-border, rgba(255,255,255,0.05)) !important;
}

.vt-themed .sidebar-drawer {
    background: var(--vt-sidebar-drawer, #121212) !important;
    border-right-color: var(--vt-sidebar-border, rgba(255,255,255,0.08)) !important;
}

.vt-themed .rail-item:hover {
    background-color: var(--vt-sidebar-hover, rgba(255,255,255,0.05)) !important;
}

.vt-themed .rail-item.active {
    background: var(--vt-sidebar-active, rgba(255,255,255,0.1)) !important;
    border-color: var(--vt-sidebar-border, rgba(255,255,255,0.08)) !important;
}

.vt-themed .drawer-item.active {
    background: var(--vt-drawer-active-bg, linear-gradient(90deg, rgba(255,255,255,0.1) 0%, transparent 100%)) !important;
    border-left-color: var(--vt-drawer-active-border, #ffffff) !important;
}

.vt-themed .drawer-item:hover {
    background: var(--vt-sidebar-hover, rgba(255,255,255,0.1)) !important;
}

.vt-themed .drawer-sub-item.active {
    border-left-color: var(--vt-sidebar-accent, #3b82f6) !important;
    background: var(--vt-drawer-active-bg, linear-gradient(90deg, rgba(59,130,246,0.15) 0%, transparent 100%)) !important;
}

.vt-themed .planta-viva-items .nav-item.active a {
    background: var(--vt-drawer-active-bg) !important;
    border-left-color: var(--vt-sidebar-accent, #3b82f6) !important;
}

.purchases-toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.purchases-toggle i:first-child {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.purchases-caret {
    margin-left: auto;
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.purchases-toggle[aria-expanded="true"] .purchases-caret {
    transform: rotate(180deg);
}

.purchases-items {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.2);
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    margin-left: 16px;
}

.purchases-items .nav-item {
    margin: 0;
}

.purchases-items .nav-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s ease;
}

.purchases-items .nav-item a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.purchases-items .nav-item.active a {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.2) 0%, transparent 100%);
    color: #fff;
    border-left: 2px solid #3b82f6;
    margin-left: -2px;
}

.purchases-items .nav-item a i {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
}
