/* ===== SIDEBAR ===== */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --sidebar-bg: #1a1a2e;
    --sidebar-hover: #16213e;
    --sidebar-active: #0f3460;
    --sidebar-text: #a0aec0;
    --sidebar-text-active: #ffffff;
    --sidebar-accent: #FF6600;
    --topbar-height: 60px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
}

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-collapsed);
    right: 0;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    transition: left 0.3s ease;
}

.topbar .menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #333;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.topbar .menu-toggle:hover {
    background: #f0f0f0;
}

.topbar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: #1a1a2e;
}

.topbar-brand span {
    color: var(--sidebar-accent);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666;
    font-size: 0.9rem;
}

.topbar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--sidebar-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Notificaciones (campanita) */
.topbar-notif {
    position: relative;
}

.notif-bell {
    font-size: 1.2rem;
    color: #475569;
    line-height: 1;
}

.notif-bell:hover {
    color: var(--sidebar-accent);
}

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 330px;
    max-width: 90vw;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 1200;
    display: none;
    padding: 0;
    overflow: hidden;
}

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

.notif-dropdown .dropdown-header {
    background: #1a1a2e;
    color: #fff;
    padding: 10px 14px;
    font-size: 0.85rem;
}

.notif-dropdown .notif-items {
    max-height: 320px;
    overflow-y: auto;
}

.notif-dropdown .notif-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    text-decoration: none;
    color: #333;
}

.notif-dropdown .notif-item:hover {
    background: #f8fafc;
}

.notif-dropdown .notif-item .n-icon {
    color: #dc2626;
    font-size: 1.1rem;
    padding-top: 2px;
}

.notif-dropdown .notif-item .n-text {
    font-size: 0.85rem;
    line-height: 1.3;
}

.notif-dropdown .notif-item small {
    color: #94a3b8;
    font-size: 0.75rem;
}

.notif-dropdown .dropdown-divider {
    margin: 0;
}

.notif-dropdown .dropdown-item.small {
    font-size: 0.8rem;
    padding: 10px 14px;
    color: var(--sidebar-accent);
    font-weight: 600;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-collapsed);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1100;
    transition: width 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

.sidebar-header {
    padding: 20px 15px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-header .logo-icon {
    width: 40px;
    height: 40px;
    background: var(--sidebar-accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-header .logo-text,
.sidebar-header .logo-sub {
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-header .logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.sidebar-header .logo-sub {
    font-size: 0.7rem;
    color: var(--sidebar-text);
    font-weight: 400;
}

/* Nav */
.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.sidebar-nav .nav-section {
    padding: 8px 20px 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.25);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav .nav-item {
    padding: 0 12px;
    margin: 2px 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s ease;
    font-size: 0.88rem;
    font-weight: 500;
    position: relative;
    white-space: nowrap;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-nav .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--sidebar-accent);
    border-radius: 0 4px 4px 0;
}

.sidebar-nav .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-nav .nav-link .badge {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 2px 6px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px 15px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-footer .version {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.2);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-collapsed);
    padding-top: var(--topbar-height);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

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

/* Los módulos usan ancho completo independiente del tamaño del monitor */
.main-content .content-wrapper .container {
    max-width: 100%;
}

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1050;
}

/* ===== EXPANDIDO (hover en desktop) ===== */
.sidebar.expanded,
.sidebar:hover {
    width: var(--sidebar-width);
}

.sidebar.expanded ~ .topbar,
.sidebar:hover ~ .topbar {
    left: var(--sidebar-width);
}

.sidebar.expanded ~ .main-content,
.sidebar:hover ~ .main-content {
    margin-left: var(--sidebar-width);
}

/* ===== COLAPSADO (desktop): solo iconos ===== */
@media (min-width: 769px) {
    .sidebar:not(.expanded):not(:hover) .sidebar-nav .nav-link span,
    .sidebar:not(.expanded):not(:hover) .sidebar-nav .nav-link .badge,
    .sidebar:not(.expanded):not(:hover) .sidebar-nav .nav-section,
    .sidebar:not(.expanded):not(:hover) .sidebar-header .logo-text,
    .sidebar:not(.expanded):not(:hover) .sidebar-header .logo-sub,
    .sidebar:not(.expanded):not(:hover) .sidebar-footer .version {
        display: none;
    }

    .sidebar:not(.expanded):not(:hover) .sidebar-header {
        justify-content: center;
        padding: 20px 8px 16px;
        gap: 0;
    }

    .sidebar:not(.expanded):not(:hover) .sidebar-nav .nav-item {
        padding: 0 8px;
    }

    .sidebar:not(.expanded):not(:hover) .sidebar-nav .nav-link {
        justify-content: center;
        gap: 0;
        padding: 10px 0;
    }

    .sidebar:not(.expanded):not(:hover) .sidebar-footer {
        padding: 16px 8px;
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

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

    .sidebar.expanded,
    .sidebar:hover {
        width: var(--sidebar-width);
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .topbar {
        left: 0;
    }

    .topbar .menu-toggle {
        display: block;
    }

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

    .main-content .content-wrapper {
        padding: 16px;
    }
}

/* Los modales deben quedar por encima del sidebar (z-index 1100) */
.modal {
    --bs-modal-zindex: 1200;
}

.modal-backdrop {
    --bs-backdrop-zindex: 1150;
}

/* Capa para los desplegables que se dibujan sobre un modal abierto (autocompletado
   de clientes y calendario de fechas). Van anclados al body, asi que su z-index se
   mide contra el modal y no contra el contenido: tiene que quedar por encima. */
:root {
    --cr-capa-sobre-modal: 1210;
}
