/* Import des variables */
@import url('./variables.css');

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Lato', sans-serif;
    background-color: var(--gris-light);
    color: var(--gris-texte);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--bleu-principal, #3b82f6);
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 14px;
    line-height: 1.4;
}

.toast-visible {
    transform: translateX(0);
    opacity: 1;
}

.toast-exit {
    transform: translateX(120%);
    opacity: 0;
}

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    color: #333;
}

.toast-close {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    flex-shrink: 0;
    line-height: 1;
}

.toast-close:hover {
    color: #333;
}

.toast-success {
    border-left-color: #10b981;
}

.toast-success .toast-icon {
    color: #10b981;
}

.toast-error {
    border-left-color: #ef4444;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-warning {
    border-left-color: #f59e0b;
}

.toast-warning .toast-icon {
    color: #f59e0b;
}

.toast-info {
    border-left-color: var(--bleu-principal, #3b82f6);
}

.toast-info .toast-icon {
    color: var(--bleu-principal, #3b82f6);
}

@media (max-width: 480px) {
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* Loading Spinner */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--bleu-new-agency);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 8px;
}

/* Alerts */
.alert {
    padding: 13px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background: var(--beige-clair);
    color: var(--bleu-new-agency);
    border: 1px solid var(--beige-sable);
}

/* === SIDEBAR NAVIGATION (Commun à tous les dashboards) === */
.main-container {
    display: flex;
    margin-top: 80px;
}

.sidebar {
    width: 280px;
    background: var(--blanc);
    box-shadow: 1px 0 8px rgba(14, 42, 71, 0.06);
    border-right: 1px solid var(--app-border, #e2e8f0);
    padding: 0;
    position: fixed;
    top: 80px;
    left: 0;
    height: calc(100vh - 80px);
    overflow: hidden;
    z-index: 999;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* Sidebar collapse/expand toggle button */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--app-text-light, #64748b);
    font-size: 16px;
    transition: color 0.2s ease;
    flex-shrink: 0;
    border-bottom: 1px solid var(--app-border, #e2e8f0);
    width: 100%;
}

.sidebar-toggle:hover {
    color: var(--bleu-new-agency);
    background: var(--beige-clair);
}

.sidebar-toggle .toggle-icon {
    transition: transform 0.25s ease;
}

/* Navigation wrapper — flex layout to push Parametres to bottom */
.nav-menu-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 12px 0;
}

.nav-menu {
    list-style: none;
    flex: 1;
}

/* Bottom section for Parametres */
.nav-menu-bottom {
    list-style: none;
    border-top: 1px solid var(--app-border, #e2e8f0);
    padding-top: 8px;
    margin-top: 8px;
    flex-shrink: 0;
}

.nav-item {
    margin-bottom: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    text-decoration: none;
    color: var(--gris-texte);
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    border-radius: 0 6px 6px 0;
    margin-right: 12px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover {
    background: var(--beige-clair);
    color: var(--bleu-new-agency);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(14, 42, 71, 0.06) 0%, rgba(196, 164, 108, 0.08) 100%);
    color: var(--bleu-new-agency);
    font-weight: 600;
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: linear-gradient(180deg, var(--bleu-new-agency) 0%, var(--beige-sable) 100%);
    border-radius: 0 2px 2px 0;
}

/* Nav link text label — hidden when collapsed */
.nav-link-text {
    transition: opacity 0.2s ease;
}

.nav-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Dropdown menu */
.nav-dropdown {
    position: relative;
}

.dropdown-content {
    display: none;
    background: var(--beige-clair);
    margin-left: 36px;
    border-radius: 4px;
    overflow: hidden;
}

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

.dropdown-link {
    display: block;
    padding: 8px 16px;
    text-decoration: none;
    color: var(--gris-texte);
    font-size: 14px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
}

.dropdown-link:hover {
    background: rgba(14, 42, 71, 0.06);
    color: var(--bleu-new-agency);
}

/* Active styling for dropdown links (sub-items) */
.dropdown-link.active {
    background: rgba(14, 42, 71, 0.08);
    color: var(--bleu-new-agency);
    font-weight: 600;
    border-left: 2px solid var(--bleu-new-agency);
}

.dropdown-arrow {
    margin-left: auto;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.dropdown-arrow.rotated {
    transform: rotate(180deg);
}

/* === SIDEBAR COLLAPSED STATE === */
.sidebar.collapsed {
    width: 68px;
}

.sidebar.collapsed .sidebar-toggle {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .sidebar-toggle .toggle-icon {
    transform: rotate(180deg);
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px 0;
    margin-right: 0;
    border-radius: 0;
    gap: 0;
}

.sidebar.collapsed .nav-link-text,
.sidebar.collapsed .dropdown-arrow {
    display: none;
}

.sidebar.collapsed .nav-icon {
    width: 100%;
    font-size: 18px;
}

.sidebar.collapsed .dropdown-content {
    display: none !important;
}

/* Tooltip for collapsed sidebar nav items */
.sidebar.collapsed .nav-link {
    position: relative;
}

.sidebar.collapsed .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bleu-nuit);
    color: var(--blanc);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1000;
    margin-left: 8px;
    font-weight: 500;
}

.sidebar.collapsed .nav-link:hover::after {
    opacity: 1;
}

/* Main Content — adjusts to sidebar width */
.content {
    flex: 1;
    padding: 24px 24px 0px 24px;
    background: var(--gris-light);
    margin-left: 280px;
    min-height: calc(100vh - 80px);
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed ~ .content {
    margin-left: 68px;
}

/* SECURITY FIX [CSP]: Animations du loader global — externalisées depuis dashboard.html
   pour permettre la suppression de unsafe-inline dans styleSrc CSP */
@keyframes global-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

body.loaded #global-loader {
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

body.loaded #global-loader.fade-out {
    display: none;
}

/* === MOBILE HAMBURGER MENU BUTTON === */
.mobile-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--gris-texte);
    font-size: 22px;
    border-radius: var(--app-radius, 6px);
    transition: background var(--transition-fast, 0.15s ease), color var(--transition-fast, 0.15s ease);
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus-visible {
    background: var(--beige-clair);
    color: var(--bleu-new-agency);
}

/* === SIDEBAR OVERLAY BACKDROP === */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

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

/* === RESPONSIVE: MOBILE (max-width: 768px) === */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    /* Ajuster le layout pour la hauteur réduite du header (56px) */
    .main-container {
        margin-top: 56px;
    }

    .sidebar {
        top: 56px;
        height: calc(100vh - 56px);
    }

    .content {
        min-height: calc(100vh - 56px);
    }

    /* Touch-friendly tap targets for nav links */
    .nav-link {
        min-height: 44px;
        padding: 12px 20px;
    }

    .dropdown-link {
        min-height: 44px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
    }

    /* Prevent horizontal overflow */
    html, body {
        overflow-x: hidden;
    }

    /* Alerts and form adjustments for mobile */
    .alert {
        font-size: 13px;
        padding: 11px 14px;
    }

    .form-control {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
}

/* === RESPONSIVE: TABLET (769px - 1024px) === */
@media (min-width: 769px) and (max-width: 1024px) {
    .mobile-menu-toggle {
        display: none;
    }

    /* Ajuster le layout pour la hauteur réduite du header (70px) */
    .main-container {
        margin-top: 70px;
    }

    .sidebar {
        top: 70px;
        height: calc(100vh - 70px);
    }

    .content {
        min-height: calc(100vh - 70px);
    }
}

/* === RESPONSIVE: SMALL MOBILE (max-width: 480px) === */
@media (max-width: 480px) {
    /* Ajuster le layout pour la hauteur réduite du header (52px) */
    .main-container {
        margin-top: 52px;
    }

    .sidebar {
        top: 52px;
        height: calc(100vh - 52px);
    }

    .content {
        min-height: calc(100vh - 52px);
    }

    body {
        font-size: 14px;
        line-height: 1.5;
    }

    .alert {
        font-size: 13px;
        padding: 10px 12px;
        border-radius: 6px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .form-control {
        padding: 10px 12px;
        font-size: 16px;
        border-radius: 6px;
    }
}