/* CRM AI-Forward — Modern Styles */

* { box-sizing: border-box; }
body { background: #f0f4f8; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Nav links */
.nav-link { color: #94a3b8; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
.nav-link.active { background: linear-gradient(135deg, rgba(59,130,246,0.2), rgba(99,102,241,0.15)); color: #60a5fa; border-left: 3px solid #60a5fa; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.badge-prospect { background: #eff6ff; color: #2563eb; }
.badge-client { background: #ecfdf5; color: #059669; }
.badge-partenaire { background: #fffbeb; color: #d97706; }
.badge-perdu { background: #fef2f2; color: #dc2626; }
.badge-lead { background: #f1f5f9; color: #475569; }
.badge-proposition { background: #eff6ff; color: #2563eb; }
.badge-en_cours { background: #fff7ed; color: #ea580c; }
.badge-termine { background: #ecfdf5; color: #059669; }
.badge-gagne { background: #ecfdf5; color: #059669; }
.badge-haute { background: #fef2f2; color: #dc2626; }
.badge-normale { background: #f1f5f9; color: #475569; }
.badge-basse { background: #eff6ff; color: #2563eb; }
.badge-task { background: #f1f5f9; color: #475569; }
.badge-call { background: #fff7ed; color: #ea580c; }
.badge-meeting { background: #eff6ff; color: #2563eb; }
.badge-email { background: #f5f3ff; color: #7c3aed; }
.badge-note { background: #ecfdf5; color: #059669; }

/* KPI Cards */
.kpi-card {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6, #6366f1);
    opacity: 0;
    transition: opacity 0.3s;
}
.kpi-card:hover {
    box-shadow: 0 8px 25px -5px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}
.kpi-card:hover::before { opacity: 1; }
.kpi-value { font-size: 1.75rem; font-weight: 800; color: #0f172a; letter-spacing: -0.02em; }
.kpi-label { font-size: 0.7rem; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.5rem; }

/* KPI special colors */
.kpi-green .kpi-value { color: #059669; }
.kpi-green::before { background: linear-gradient(90deg, #059669, #10b981); }
.kpi-blue .kpi-value { color: #2563eb; }
.kpi-blue::before { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.kpi-purple .kpi-value { color: #7c3aed; }
.kpi-purple::before { background: linear-gradient(90deg, #7c3aed, #8b5cf6); }
.kpi-orange .kpi-value { color: #ea580c; }
.kpi-orange::before { background: linear-gradient(90deg, #ea580c, #f97316); }

/* Cards */
.card {
    background: white;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}
.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
}
.card-body { padding: 1.5rem; }

/* Pipeline Kanban */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; min-height: 500px; }
.kanban-column { min-width: 280px; flex: 1; background: #f8fafc; border-radius: 16px; padding: 0.75rem; border: 1px solid #e2e8f0; }
.kanban-column-header { font-size: 0.875rem; font-weight: 600; padding: 0.75rem; margin-bottom: 0.5rem; border-radius: 12px; }
.kanban-card { background: white; border-radius: 12px; padding: 1rem; margin-bottom: 0.5rem; border: 1px solid #e2e8f0; cursor: grab; transition: all 0.2s; }
.kanban-card:hover { box-shadow: 0 8px 25px -5px rgba(0,0,0,0.08); transform: translateY(-1px); }
.kanban-card.dragging { opacity: 0.5; }
.kanban-column.drag-over { background: #eff6ff; border-color: #3b82f6; }

/* Table */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th { text-align: left; padding: 0.875rem 1rem; font-size: 0.7rem; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; border-bottom: 1px solid #e2e8f0; background: #fafbfc; }
.data-table th:first-child { border-radius: 12px 0 0 0; }
.data-table th:last-child { border-radius: 0 12px 0 0; }
.data-table td { padding: 0.875rem 1rem; font-size: 0.875rem; border-bottom: 1px solid #f1f5f9; }
.data-table tr:hover td { background: #f8fafc; }
.data-table tr { cursor: pointer; transition: background 0.15s; }

/* Toast */
.toast { padding: 0.875rem 1.25rem; border-radius: 12px; font-size: 0.875rem; color: white; animation: slideIn 0.3s ease-out; min-width: 280px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.15); backdrop-filter: blur(10px); }
.toast-success { background: linear-gradient(135deg, #059669, #10b981); }
.toast-error { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast-info { background: linear-gradient(135deg, #2563eb, #3b82f6); }
@keyframes slideIn { from { transform: translateX(100%) scale(0.95); opacity: 0; } to { transform: translateX(0) scale(1); opacity: 1; } }

/* Chart */
.chart-bar { transition: height 0.6s cubic-bezier(0.4,0,0.2,1); border-radius: 4px 4px 0 0; }

/* Overdue */
.overdue { border-left: 3px solid #dc2626; background: #fef2f2 !important; }

/* Avatar */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; font-weight: 600; color: white; flex-shrink: 0; }
.avatar-sm { width: 2rem; height: 2rem; font-size: 0.7rem; border-radius: 8px; }
.avatar-md { width: 2.5rem; height: 2.5rem; font-size: 0.8rem; }

/* Loading spinner */
.spinner { border: 3px solid #e2e8f0; border-top-color: #3b82f6; border-radius: 50%; width: 2rem; height: 2rem; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: #94a3b8; }

/* Tab */
.tab { padding: 0.625rem 1.25rem; font-size: 0.875rem; font-weight: 500; color: #94a3b8; border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.2s; border-radius: 8px 8px 0 0; }
.tab:hover { color: #475569; background: #f8fafc; }
.tab.active { color: #2563eb; border-bottom-color: #2563eb; background: #eff6ff; }

/* Progress bar */
.progress-bar { height: 8px; border-radius: 9999px; background: #e2e8f0; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 9999px; background: linear-gradient(90deg, #3b82f6, #6366f1); transition: width 0.6s cubic-bezier(0.4,0,0.2,1); }

/* Sidebar */
#sidebar > div {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
}

/* Header */
header {
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(12px);
}

/* Global search */
#global-search {
    background: #f1f5f9;
    border: 1px solid transparent;
    transition: all 0.2s;
}
#global-search:focus {
    background: white;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* Buttons */
button, [type="submit"] {
    transition: all 0.2s;
}

/* AI Panel */
#ai-panel {
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

/* Mobile menu */
@media (max-width: 1023px) {
    .kanban-board { flex-direction: column; }
    .kanban-column { min-width: 100%; }
}

/* ===========================
   DEVIS MODULE
   =========================== */

/* Devis status badges */
.badge-brouillon { background: #f1f5f9; color: #475569; }
.badge-envoye { background: #eff6ff; color: #2563eb; }
.badge-vu { background: #fff7ed; color: #ea580c; }
.badge-signe { background: #ecfdf5; color: #059669; }
.badge-refuse { background: #fef2f2; color: #dc2626; }
.badge-expire { background: #f1f5f9; color: #94a3b8; }

/* Two-panel devis form layout */
.devis-form-layout {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 1279px) {
    .devis-form-layout {
        grid-template-columns: 1fr;
    }
}

/* A4 preview wrapper */
.devis-preview-wrapper {
    position: sticky;
    top: 1rem;
    background: #f1f5f9;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
}
.devis-preview-inner {
    padding: 32px;
    font-family: 'Inter', sans-serif;
    background: white;
    margin: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.devis-preview-scale {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Line items table in form */
.devis-items-table { width: 100%; border-collapse: collapse; }
.devis-items-table th {
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}
.devis-items-table td {
    padding: 0.4rem 0.25rem;
    vertical-align: middle;
}
.devis-items-table input, .devis-items-table select, .devis-items-table textarea {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.8rem;
    transition: border-color 0.2s;
}
.devis-items-table input:focus, .devis-items-table select:focus, .devis-items-table textarea:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}
.devis-items-table .item-remove {
    width: 28px;
    height: 28px;
    border: none;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}
.devis-items-table .item-remove:hover { background: #fee2e2; }

/* Devis detail actions bar */
.devis-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.devis-actions button, .devis-actions a {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid #e2e8f0;
    background: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
}
.devis-actions button:hover, .devis-actions a:hover { background: #f8fafc; }
.devis-actions .btn-primary { background: #4F46E5; color: white; border-color: #4F46E5; }
.devis-actions .btn-primary:hover { background: #4338CA; }
.devis-actions .btn-danger { color: #dc2626; border-color: #fecaca; }
.devis-actions .btn-danger:hover { background: #fef2f2; }

/* Events timeline */
.devis-timeline {
    border-left: 2px solid #e2e8f0;
    padding-left: 1.25rem;
    margin-left: 0.5rem;
}
.devis-timeline-item {
    position: relative;
    padding-bottom: 1rem;
}
.devis-timeline-item::before {
    content: '';
    position: absolute;
    left: -1.55rem;
    top: 0.25rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #cbd5e1;
    border: 2px solid white;
}
.devis-timeline-item.event-signed::before { background: #10b981; }
.devis-timeline-item.event-sent::before { background: #3b82f6; }
.devis-timeline-item.event-viewed::before { background: #f59e0b; }

/* Expiration preset buttons */
.expiry-presets {
    display: flex;
    gap: 0.5rem;
}
.expiry-presets button {
    padding: 0.4rem 0.8rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 500;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}
.expiry-presets button:hover { border-color: #3b82f6; color: #3b82f6; }
.expiry-presets button.active { background: #4F46E5; color: white; border-color: #4F46E5; }

/* Paiements badges */
.badge-en_attente { background: #fff7ed; color: #ea580c; }
.badge-paye { background: #ecfdf5; color: #059669; }
.badge-annule { background: #f1f5f9; color: #94a3b8; }

/* Print styles */
@media print {
    #sidebar, #app-shell > .flex > aside, header, #ai-fab, #ai-panel, #toast-container,
    #modal-overlay, .devis-actions, .devis-form-panel { display: none !important; }
    #main-content { padding: 0 !important; overflow: visible !important; }
    #app-shell, #app-shell > .flex, #app-shell > .flex > .flex-1 { height: auto !important; overflow: visible !important; }
    .devis-preview-inner { transform: none !important; width: 100% !important; }
    .devis-preview-scale { width: 100% !important; height: auto !important; overflow: visible !important; }
    .devis-preview-wrapper { border: none !important; box-shadow: none !important; }
}
