/* ============================================
   OCTO V3 - DIRECTION - Styles Communs
   ERP LIDR Solution
   ============================================ */

/* --- Variables CSS --- */
:root {
    --primary-dark: #1a2744;
    --primary: #243656;
    --primary-light: #2e4a6e;
    --primary-hover: #3a5f8a;
    --accent: #4a90d9;
    --accent-light: #6baaf0;
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --text-white: #ffffff;
    --text-light: #c8d6e5;
    --text-muted: #8395a7;
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --border-color: #e1e5eb;
    --border-light: #f0f2f5;
    --success: #27ae60;
    --success-light: #e8f8ef;
    --warning: #f39c12;
    --warning-light: #fef9e7;
    --danger: #e74c3c;
    --danger-light: #fdedec;
    --info: #3498db;
    --info-light: #ebf5fb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 0.25s ease;
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- Reset CSS --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-main);
    color: #333;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

ul, ol {
    list-style: none;
}

button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
}

input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    outline: none;
}

/* --- Layout Principal --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    overflow-x: hidden;
    transition: margin-left var(--transition);
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--primary-dark);
    color: var(--text-white);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    transition: transform var(--transition);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sidebar-header .logo {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--text-white);
}

.sidebar-header .subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

/* Menu principal */
.menu-item {
    position: relative;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
    border-left: 3px solid transparent;
    gap: 10px;
}

.menu-link:hover {
    background: var(--primary-light);
    color: var(--text-white);
    border-left-color: var(--accent);
}

.menu-link.active {
    background: var(--primary);
    color: var(--text-white);
    border-left-color: var(--accent);
}

.menu-link .menu-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.menu-link .menu-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-link .menu-arrow {
    font-size: 0.65rem;
    transition: transform var(--transition);
    opacity: 0.6;
}

.menu-link.expanded .menu-arrow {
    transform: rotate(90deg);
}

/* Sous-menus */
.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    background: rgba(0,0,0,0.15);
}

.submenu.open {
    max-height: 1500px;
}

.submenu-link {
    display: block;
    padding: 8px 20px 8px 53px;
    color: var(--text-muted);
    font-size: 0.82rem;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.submenu-link:hover {
    color: var(--text-white);
    background: rgba(255,255,255,0.05);
    border-left-color: var(--accent-light);
}

.submenu-link.active {
    color: var(--accent-light);
    background: rgba(255,255,255,0.05);
}

/* --- Mobile Burger --- */
.burger-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    background: var(--primary-dark);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: var(--shadow-md);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* --- Header de page --- */
.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.page-header .breadcrumb {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.page-header .breadcrumb a {
    color: var(--accent);
}

.page-header .breadcrumb a:hover {
    text-decoration: underline;
}

/* --- Cartes de statistiques --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 14px;
}

.stat-card .stat-icon.blue { background: var(--info-light); color: var(--info); }
.stat-card .stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-card .stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon.red { background: var(--danger-light); color: var(--danger); }

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-dark);
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.stat-card .stat-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 10px;
    padding: 3px 8px;
    border-radius: 20px;
}

.stat-trend.up { background: var(--success-light); color: var(--success); }
.stat-trend.down { background: var(--danger-light); color: var(--danger); }

/* --- Tableaux dynamiques --- */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}

.table-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 220px;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.data-table thead {
    background: var(--bg-main);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-light);
    color: #444;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

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

.data-table .no-data {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* --- Boutons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover {
    background: #3a7bc8;
    box-shadow: var(--shadow-sm);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: #219a52;
}

.btn-warning {
    background: var(--warning);
    color: white;
}
.btn-warning:hover {
    background: #e08e0b;
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #c0392b;
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}
.btn-outline:hover {
    background: var(--accent);
    color: white;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* --- Modals --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s ease;
}

.modal-lg {
    max-width: 1200px;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-main);
    color: var(--danger);
}

.modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* --- Onglets --- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.tab {
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
    white-space: nowrap;
    background: none;
}

.tab:hover {
    color: var(--primary-dark);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

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

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    transition: border-color var(--transition);
    background: white;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.form-check label {
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
}

/* --- Fil de discussion --- */
.discussion-panel {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 300px;
}

.discussion-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-dark);
}

.discussion-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.discussion-message {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.discussion-message .msg-author {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--accent);
}

.discussion-message .msg-date {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: 8px;
}

.discussion-message .msg-text {
    font-size: 0.85rem;
    margin-top: 4px;
    color: #444;
}

.discussion-input {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.discussion-input input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.discussion-input button {
    padding: 8px 14px;
    background: var(--accent);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}

.discussion-input button:hover {
    background: #3a7bc8;
}

/* --- Graphiques (conteneurs) --- */
.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.chart-container h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 16px;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 300px;
}

/* --- Grilles de contenu --- */
.content-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 0.74rem;
    font-weight: 600;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }

/* --- Widget IA --- */
.ai-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), #6c5ce7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 3000;
    box-shadow: 0 4px 16px rgba(74,144,217,0.4);
    transition: transform var(--transition), box-shadow var(--transition);
}

.ai-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(74,144,217,0.5);
}

.ai-chat {
    display: none;
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.25s ease;
}

.ai-chat.open {
    display: flex;
}

.ai-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--accent), #6c5ce7);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-header h4 {
    font-size: 0.95rem;
    font-weight: 600;
}

.ai-chat-close {
    background: none;
    color: white;
    font-size: 1.2rem;
    opacity: 0.8;
}

.ai-chat-close:hover {
    opacity: 1;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.ai-msg {
    margin-bottom: 12px;
    display: flex;
}

.ai-msg.bot {
    justify-content: flex-start;
}

.ai-msg.user {
    justify-content: flex-end;
}

.ai-msg .msg-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.ai-msg.bot .msg-bubble {
    background: var(--bg-main);
    color: #333;
    border-bottom-left-radius: 4px;
}

.ai-msg.user .msg-bubble {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-chat-input {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.ai-chat-input input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.85rem;
}

.ai-chat-input input:focus {
    border-color: var(--accent);
}

.ai-chat-input button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-input button:hover {
    background: #3a7bc8;
}

/* --- Responsive : Tablette (768px) --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .burger-btn {
        display: flex;
    }

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

    .main-content {
        margin-left: 0;
        padding: 70px 16px 24px;
        width: 100%;
        max-width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 12px;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .table-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-input {
        width: 100%;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    .modal {
        max-width: 100%;
        max-height: 95vh;
        margin: 10px;
        border-radius: var(--radius-md);
        overflow: hidden;
    }

    .ai-chat {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 80px;
        height: 60vh;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

/* --- Responsive : Mobile (480px) --- */
@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    .main-content {
        padding: 64px 12px 20px;
        width: 100%;
        max-width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 1.5rem;
    }

    .page-header h1 {
        font-size: 1.3rem;
    }

    .tabs {
        gap: 0;
    }

    .tab {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .btn {
        padding: 7px 12px;
        font-size: 0.8rem;
    }

    .ai-bubble {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
        bottom: 16px;
        right: 16px;
    }

    .ai-chat {
        bottom: 72px;
        height: 65vh;
    }
}

/* --- Utilitaires --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-100 { width: 100%; }
