/* Estils principals per al tauler de control (Dashboard) */
:root {
    --primary: #009CFF;
    --light: #F3F6F9;
    --dark: #191C24;
    --secondary: #757575;
    --white: #ffffff;
    --sidebar-width: 250px;
    --header-height: 64px;
}

body {
    font-family: 'Heebo', sans-serif;
    background-color: var(--light);
    margin: 0;
    color: var(--secondary);
    overflow-y: scroll;
    /* Force vertical scrollbar to prevent layout shift */
}

a {
    text-decoration: none;
    color: inherit;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--white);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
    z-index: 999;
    transition: transform 0.3s ease-in-out;
    overflow-y: auto;
    transform: translateX(0);
    /* Visible by default on desktop */
}

/* Desktop: Sidebar hidden state (collapsed) */
.sidebar.open {
    transform: translateX(-100%);
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-user {
    display: flex;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--light);
}

.sidebar-user img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 1rem;
}

.sidebar-nav {
    padding: 1rem 0;
}

.nav-item {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--secondary);
    font-weight: 500;
    transition: 0.3s;
    display: flex;
    align-items: center;
}

.nav-item i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

.nav-item:hover,
.nav-item.active {
    color: var(--primary);
    background: var(--light);
    border-left: 3px solid var(--primary);
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
    z-index: 998;
    transition: left 0.3s ease-in-out;
}

.header-left {
    display: flex;
    align-items: center;
}

.search-form input {
    border: none;
    background: var(--light);
    padding: 0.5rem 1rem;
    border-radius: 5px;
    width: 250px;
    outline: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-icon {
    position: relative;
    cursor: pointer;
}

.user-dropdown {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.user-dropdown img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    margin-right: 10px;
}

/* Contingut Principal */
.content {
    margin-left: var(--sidebar-width);
    padding-top: 0;
    min-height: 100vh;
    transition: margin-left 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    flex-grow: 1;
    /* Ocupa tot l'espai disponible restant el marge */
    width: auto;
}

/* Desktop: Content expands when sidebar is hidden */
.content.open {
    margin-left: 0;
    width: auto;
}

.content.open .header {
    left: 0;
}

.container-fluid {
    width: 100%;
    max-width: 100%;
    flex: 1;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Footer */
.footer {
    background: var(--white);
    padding: 1.5rem;
    text-align: center;
    color: var(--secondary);
    margin-top: auto;
}

/* Utilitats */
.text-primary {
    color: var(--primary);
}

.bg-light {
    background-color: var(--light);
}

/* Back to Top */
.back-to-top {
    position: fixed;
    display: none;
    right: 45px;
    bottom: 45px;
    z-index: 99;
}

/* Square Buttons */
.btn-square,
.btn-sm-square,
.btn-lg-square {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: normal;
    border-radius: 2px;
}

.btn-square {
    width: 38px;
    height: 38px;
}

.btn-sm-square {
    width: 30px;
    height: 30px;
}

.btn-lg-square {
    width: 48px;
    height: 48px;
}

/* Sidebar Overlay (Backdrop) */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    /* Below sidebar (999) but above content */
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* Dropdown - funciona amb clic (Bootstrap) a totes les pantalles */
.dropdown .dropdown-menu.show {
    display: block;
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        /* Hidden by default on mobile */
        margin-left: 0;
        /* Reset margin logic */
    }

    .sidebar.open {
        transform: translateX(0);
        /* Visible when open on mobile */
        margin-left: 0;
    }

    .content {
        margin-left: 0;
    }

    .content.open {
        margin-left: 0;
        /* Content doesn't move on mobile */
    }

    .header {
        left: 0;
    }

    /* Millores pel dropdown en mòbil */
    .header-right {
        gap: 10px;
    }

    .dropdown .dropdown-menu {
        position: absolute;
        right: 0;
        top: 100%;
        min-width: 150px;
    }

    .dropdown .dropdown-toggle {
        padding: 5px;
    }
}

/* Dropdown on hover for desktop */
@media (min-width: 992px) {
    .dropdown:hover .dropdown-menu {
        display: block;
        margin-top: 0;
    }
}

/* Correccions afegides */
@media (min-width: 992px) {

    /* Amagar superposició a l'escriptori */
    .sidebar-overlay,
    .sidebar-overlay.open {
        display: none !important;
    }
}

@media (max-width: 991.98px) {

    /* Correccions del menú desplegable mòbil */
    .dropdown .dropdown-menu {
        z-index: 1001 !important;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    }
}

/* Correcció visibilitat menú desplegable mòbil */
@media (max-width: 991.98px) {
    /* Assegurar posicionament relatiu pel contenidor dropdown */
    .header-right .dropdown {
        position: relative !important;
    }

    .dropdown .dropdown-menu.show {
        display: block !important;
        position: absolute !important;
        right: 0 !important;
        top: 100% !important;
        z-index: 1050 !important;
        transform: none !important;
        left: auto !important;
    }
}

/* Augmentar mida icones capçalera */
.header-icon {
    font-size: 1.25rem;
    padding: 5px;
}

/* Correcció posicionament menú desplegable escriptori */
@media (min-width: 992px) {
    .dropdown {
        position: relative !important;
    }

    .dropdown-menu {
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
    }
}

/* Correcció final per al menú desplegable d'escriptori */
@media (min-width: 992px) {
    .dropdown {
        position: relative !important;
    }

    .dropdown:hover .dropdown-menu {
        display: block !important;
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        margin-top: 0 !important;
        z-index: 1050 !important;
    }
}

/* Correcció desplaçament al fer clic (sobreescriure Popper.js) */
@media (min-width: 992px) {

    .dropdown:hover .dropdown-menu,
    .dropdown .dropdown-menu.show {
        display: block !important;
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        margin-top: 0 !important;
        z-index: 1050 !important;
        transform: none !important;
        left: auto !important;
    }
}

/* Dark Mode Styles */
body.dark {
    --light: #050505;
    /* Fons pràcticament negre per fer ressaltar els mòduls */
    --white: #1E222D;
    /* Gris fosc amb to blavós per Sidebar/Header/Cards */
    --secondary: #B0B0B0;
    /* Text secundari més clar */
    --dark: #FFFFFF;
}

/* Afegim vora subtil per separar millor les àrees en mode fosc */
body.dark .sidebar,
body.dark .header,
body.dark .card,
body.dark .bg-light {
    border: 1px solid rgba(255, 255, 255, 0.05);
}

body.dark .bg-white {
    background-color: var(--white) !important;
    color: var(--secondary);
}

body.dark .bg-light {
    background-color: var(--light) !important;
}

body.dark .text-dark {
    color: var(--dark) !important;
}

body.dark .dropdown-menu {
    background-color: var(--white) !important;
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark .dropdown-item {
    color: var(--secondary);
}

body.dark .dropdown-item:hover {
    background-color: var(--light);
    color: var(--primary);
}

body.dark .form-control,
body.dark .form-select {
    background-color: var(--light);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--secondary);
}

body.dark .form-control:focus,
body.dark .form-select:focus {
    background-color: var(--light);
    color: var(--secondary);
    border-color: var(--primary);
}


/* Millores Mode Fosc */
body.dark {
    color: var(--secondary);
}

body.dark h1,
body.dark h2,
body.dark h3,
body.dark h4,
body.dark h5,
body.dark h6 {
    color: var(--dark) !important;
}

body.dark .text-muted {
    color: #6c7293 !important;
}

body.dark .table {
    color: var(--secondary);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark .table-hover tbody tr:hover {
    color: var(--secondary);
    background-color: rgba(255, 255, 255, 0.075);
}

body.dark .table thead th {
    color: var(--dark);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark .btn-link {
    color: var(--primary);
}

body.dark .nav-item.active {
    background: var(--light);
}

body.dark .sidebar {
    background: var(--white);
}

body.dark .sidebar .nav-item {
    color: var(--secondary);
}

body.dark .sidebar .nav-item:hover,
body.dark .sidebar .nav-item.active {
    color: var(--primary);
    background: var(--light);
}

body.dark .header {
    background: var(--white);
}

/* Animacions i efectes */
.hover-scale {
    transition: transform 0.2s ease-in-out;
}

.hover-scale:hover {
    transform: scale(1.05);
}

/* Alertes personalitzades */
.alert-soft-primary {
    background-color: rgba(0, 156, 255, 0.1);
    color: var(--primary);
    border: 1px solid rgba(0, 156, 255, 0.2);
    border-radius: 10px;
    padding: 1rem;
}

/* Correccions per a mòbil - evitar overflow horitzontal */
@media (max-width: 767.98px) {
    body {
        overflow-x: hidden;
    }

    .container-fluid {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        max-width: 100vw !important;
        overflow-x: hidden;
    }

    .card-body {
        padding: 0.75rem !important;
    }

    .tab-pane {
        max-width: 100%;
        overflow-x: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Textos llargs */
    p,
    span,
    label,
    td,
    th {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Taules responsives */
    .table {
        font-size: 0.85rem;
    }

    /* Formularis */
    .form-label {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }
}

/* Millores transició sidebar i contingut */

/* Control d'overflow per a taules */
.table-responsive {
    overflow-x: auto;
    max-width: 100%;
}

/* Assegurar que les files amb taules no desbordin */
/* Assegurar que les files amb taules no desbordin */
/* Rule removed to fix negative margins */

/* Wrapper exterior - evitar desbordament */
body>.container-fluid {
    overflow: hidden;
    max-width: 100vw;
}

/* ==============================================
   Estabilització de pestanyes (tabs) de navegació
   Evitar canvi de mida en hover/active
   ============================================== */
.nav-tabs {
    border-bottom: 1px solid #dee2e6;
}

.nav-tabs .nav-link {
    border: none !important;
    border-bottom: 3px solid transparent !important;
    border-radius: 0 !important;
    margin-bottom: -1px;
    transition: color 0.15s ease-in-out, border-color 0.15s ease-in-out;
    background-color: transparent !important;
}

.nav-tabs .nav-link:hover,
.nav-tabs .nav-link:focus {
    border: none !important;
    border-bottom: 3px solid var(--primary) !important;
    color: var(--primary);
    outline: none;
}

.nav-tabs .nav-link.active {
    border: none !important;
    border-bottom: 3px solid var(--primary) !important;
    color: var(--primary);
    background-color: transparent !important;
}

/* Assegurar que els nav-item no canviin de mida */
.nav-tabs .nav-item {
    flex: 1 1 auto;
}