/**
 * FacilityAI v2.0 - Complete Fixed Styles
 * Fixed: Mobile menu, Modal z-index, Filter UI
 */

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #2d3748;
    background: #f7fafc;
}

/* ===== LAYOUT ===== */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* ===== HEADER ===== */
.header {
    background: #2d3748;
    color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
}

.logo-icon {
    font-size: 1.5rem;
}

.nav {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.nav-link {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
}

/* Desktop user area */
.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    color: rgba(255,255,255,0.9);
    font-weight: 500;
}

/* Mobile user dropdown (par défaut caché en desktop) */
.nav-user-mobile {
    display: none;
}

.nav-user-toggle {
    width: 100%;
    background: none;
    border: none;
    color: rgba(255,255,255,0.9);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
}

.nav-user-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.nav-user-label {
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-user-chevron {
    font-size: 0.8rem;
}

.nav-user-menu {
    display: none;
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: rgba(15,23,42,0.9);
}

.nav-user-menu.open {
    display: block;
}

.nav-user-logout {
    display: inline-block;
    font-size: 0.85rem;
    color: #fed7d7;
    text-decoration: none;
}

.nav-user-logout:hover {
    text-decoration: underline;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.burger-icon {
    width: 24px;
    height: 18px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.burger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: white;
    transition: all 0.3s;
}

.mobile-menu-toggle.active .burger-icon span:nth-child(1) {
    transform: rotate(45deg) translateY(8px);
}

.mobile-menu-toggle.active .burger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .burger-icon span:nth-child(3) {
    transform: rotate(-45deg) translateY(-8px);
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 0.25rem;
}

.page-subtitle {
    color: #718096;
    font-size: 1rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* ===== CARDS ===== */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2,
.card-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a202c;
    margin: 0;
}

.card-body {
    padding: 1.5rem;
}

.alert-card {
    border-left: 4px solid #e53e3e;
}

.alert-card .card-header {
    background: #fff5f5;
}

/* ===== METRICS GRID ===== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #4299e1;
    transition: transform 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.metric-card.metric-danger {
    border-left-color: #e53e3e;
}

.metric-card.metric-warning {
    border-left-color: #ed8936;
}

.metric-card.metric-success {
    border-left-color: #38a169;
}

.metric-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.metric-content {
    flex: 1;
}

.metric-label {
    font-size: 0.875rem;
    color: #718096;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1a202c;
    line-height: 1;
}

.metric-detail {
    font-size: 0.875rem;
    color: #a0aec0;
    margin-top: 0.5rem;
}

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}

/* ===== STATUS BAR ===== */
.status-bar-container {
    margin-bottom: 1.5rem;
}

.status-bar {
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    background: #f7fafc;
}

.status-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s;
}

.status-segment:hover {
    filter: brightness(1.1);
}

.status-segment.green {
    background: #38a169;
}

.status-segment.yellow {
    background: #ed8936;
}

.status-segment.red {
    background: #e53e3e;
}

.status-legend {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-dot.green {
    background: #38a169;
}

.legend-dot.yellow {
    background: #ed8936;
}

.legend-dot.red {
    background: #e53e3e;
}

/* ===== TABLES ===== */
.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: #f7fafc;
}

.data-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.data-table tbody tr:hover {
    background: #f7fafc;
}

.data-table.compact td,
.data-table.compact th {
    padding: 0.75rem;
}

.text-center {
    text-align: center;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    font-size: 0.875rem;
}

.btn-primary {
    background: #4299e1;
    color: white;
}

.btn-primary:hover {
    background: #3182ce;
}

.btn-secondary {
    background: #718096;
    color: white;
}

.btn-secondary:hover {
    background: #4a5568;
}

.btn-danger {
    background: #e53e3e;
    color: white;
}

.btn-danger:hover {
    background: #c53030;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* ===== FORMS ===== */
.form-control {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: border-color 0.2s;
    background: white;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

textarea.form-control {
    resize: vertical;
    font-family: inherit;
}

/* ===== BADGES ===== */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-danger {
    background: #fff5f5;
    color: #e53e3e;
    border: 1px solid #feb2b2;
}

/* ===== STATUS DOTS ===== */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status-dot.green {
    background: #38a169;
}

.status-dot.yellow {
    background: #ed8936;
}

.status-dot.red {
    background: #e53e3e;
}

/* ===== MODALS ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    overflow-y: auto;
    padding: 2rem 1rem;
}

.modal.show {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    margin: 2rem auto;
    position: relative;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #718096;
    padding: 0.5rem;
    line-height: 1;
}

.modal-close:hover {
    color: #2d3748;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    position: sticky;
    bottom: 0;
    background: white;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #2d3748;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(100px);
    transition: all 0.3s;
    z-index: 10001;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: #38a169;
}

.toast-error {
    background: #e53e3e;
}

.toast-warning {
    background: #ed8936;
}

.toast-info {
    background: #4299e1;
}

/* ===== FOOTER ===== */
.footer {
    background: #2d3748;
    color: rgba(255,255,255,0.8);
    padding: 2rem;
    margin-top: 4rem;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-logo {
    font-size: 1.125rem;
    font-weight: 700;
    color: white;
}

.footer-tagline {
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.footer-info {
    text-align: right;
}

.footer-company {
    font-size: 0.875rem;
}

.footer-company a {
    color: #4299e1;
    text-decoration: none;
}

.footer-version {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 968px) {
    .main-content {
        padding: 1rem;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .header-actions .form-control {
        flex: 1;
        min-width: 150px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .nav {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: #2d3748;
        flex-direction: column;
        padding: 1rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }
    
    .nav.active {
        display: flex;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
    }
    
    .mobile-menu-toggle {
        display: block;
    }
    
    .user-menu {
        margin-left: auto;
    }
    
    /* Sur mobile: cacher le nom desktop, afficher le bloc user mobile */
    .user-name {
        display: none;
    }
    
    .nav-user-mobile {
        display: block;
        margin-top: 0.75rem;
        border-top: 1px solid rgba(255,255,255,0.1);
        padding-top: 0.75rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .footer-info {
        text-align: center;
    }
    
    .modal-content {
        margin: 1rem auto;
    }
}

/* ===== FILTERS, SAFETY, MAINTENANCE, SETTINGS ===== */
/* (tu peux garder tels quels tes blocs filters-section, safety-stats-grid,
   maintenance-stats-grid, settings-grid, etc., que tu avais en bas) */
   
.user-menu .logout-link {
    color: #fed7d7;
    text-decoration: none;
    font-size: 0.9rem;
}
.user-menu .logout-link:hover {
    text-decoration: underline;
}

/* ===== CHANGE PASSWORD PAGE ===== */
.pw-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #4f46e5 0, #111827 55%, #020617 100%);
    padding: 20px;
}

.pw-box {
    background: rgba(15,23,42,0.96);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    padding: 32px 28px;
    width: 100%;
    max-width: 460px;
    color: #e5e7eb;
    border: 1px solid rgba(148,163,184,0.4);
    backdrop-filter: blur(10px);
}

.pw-header {
    text-align: center;
    margin-bottom: 24px;
}

.pw-logo {
    font-size: 32px;
    margin-bottom: 6px;
}

.pw-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #f9fafb;
    margin-bottom: 4px;
}

.pw-header p {
    color: #9ca3af;
    font-size: 13px;
}

.pw-warning,
.pw-error,
.pw-success {
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.pw-warning {
    background: #fffbeb;
    border: 1px solid #facc15;
    color: #92400e;
}

.pw-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
}

.pw-success {
    background: #ecfdf3;
    border: 1px solid #6ee7b7;
    color: #166534;
}

.pw-requirements {
    background: rgba(15,23,42,0.9);
    border-radius: 10px;
    border: 1px solid rgba(148,163,184,0.5);
    padding: 12px 14px;
    margin-bottom: 18px;
    font-size: 12px;
}

.pw-requirements h3 {
    font-size: 13px;
    color: #e5e7eb;
    margin-bottom: 6px;
}

.pw-requirements ul {
    list-style: none;
    padding-left: 0;
}

.pw-requirements li {
    color: #9ca3af;
    padding: 3px 0;
    padding-left: 18px;
    position: relative;
}

.pw-requirements li::before {
    content: "•";
    position: absolute;
    left: 4px;
    color: #22c55e;
}

.pw-form-group {
    margin-bottom: 14px;
}

.pw-form-group label {
    display: block;
    margin-bottom: 6px;
    color: #e5e7eb;
    font-size: 13px;
    font-weight: 500;
}

.pw-form-group input {
    width: 100%;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px solid #4b5563;
    background: #020617;
    color: #f9fafb;
    font-size: 13px;
}

.pw-form-group input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 1px rgba(99,102,241,0.5);
}

.pw-submit-btn {
    width: 100%;
    padding: 10px;
    margin-top: 6px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: white;
    border: none;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(79,70,229,0.45);
}

.pw-submit-btn:hover {
    background: linear-gradient(135deg, #4338ca, #4f46e5);
}

.pw-footer {
    text-align: center;
    margin-top: 18px;
    font-size: 11px;
    color: #6b7280;
}

.pw-footer span {
    color: #e5e7eb;
}

@media (max-width: 480px) {
    .pw-box {
        padding: 24px 18px;
    }
}
/* Improved Filter Section */
.filters-section {
    background: white;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)); /* 4 colonnes fixes sur desktop */
    gap: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5568;
}

.search-box input,
.filter-group .form-control {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    height: 32px;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.filter-actions .btn {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

/* Mobile: repasser en grille auto-fit plus respirable */
@media (max-width: 968px) {
    .filters-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 0.75rem;
    }
}
