/* ═══════════════════════════════════════════════
   LCC Services — Reporting Commercial
   Design System & Styles
   ═══════════════════════════════════════════════ */

:root {
    --font-main: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --blue: #0062cc;
    --blue-light: #e8f0fe;
    --blue-dark: #004a9e;
    --green: #0d9f6e;
    --green-light: #def7ec;
    --orange: #e67e22;
    --orange-light: #fef3e2;
    --red: #dc2626;
    --red-light: #fee2e2;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e2e6ed;
    --text: #1a1d26;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    --sidebar-w: 250px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #e2e8f0;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}

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

html { font-size: 15px; }

body {
    font-family: var(--font-main);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    padding: 20px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.brand-icon {
    width: 40px; height: 40px;
    background: var(--blue);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 1px;
    flex-shrink: 0;
}

.brand-text strong { color: white; font-size: 0.88rem; display: block; }
.brand-text small { color: var(--sidebar-text); font-size: 0.72rem; }

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    background: none;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 500;
    font-family: var(--font-main);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.nav-item.active { background: rgba(255,255,255,0.1); color: white; }
.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-sync {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sync-indicator { display: flex; align-items: center; gap: 8px; color: var(--sidebar-text); font-size: 0.75rem; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
.sync-dot.connected { background: var(--green); }
.sync-dot.syncing { background: var(--orange); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.btn-sync {
    width: 32px; height: 32px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: var(--sidebar-text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all var(--transition);
}
.btn-sync:hover { background: rgba(255,255,255,0.15); color: white; }

/* ═══ MOBILE HEADER ═══ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--sidebar-bg);
    color: white;
    align-items: center;
    padding: 0 16px;
    z-index: 90;
    gap: 12px;
}
.hamburger {
    width: 40px; height: 40px;
    border: none; background: none;
    color: white; font-size: 1.3rem; cursor: pointer;
}
.mobile-title { flex: 1; font-weight: 600; font-size: 0.95rem; }
.btn-sync-mobile {
    width: 36px; height: 36px;
    border: none; background: rgba(255,255,255,0.1);
    color: white; border-radius: 8px; font-size: 1.1rem; cursor: pointer;
}

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

/* ═══ MAIN ═══ */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 28px 32px;
    min-height: 100vh;
}

.tab-content { display: none; animation: fadeIn 0.25s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ═══ PAGE HEADER ═══ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-header h1 { font-size: 1.65rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.page-subtitle { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ═══ KPI CARDS ═══ */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--blue);
}
.kpi-card.kpi-blue { border-left-color: var(--blue); }
.kpi-card.kpi-green { border-left-color: var(--green); }
.kpi-card.kpi-orange { border-left-color: var(--orange); }
.kpi-card.kpi-dark { border-left-color: var(--sidebar-bg); }

.kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.kpi-value { font-size: 1.8rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.78rem; color: var(--text-light); margin-top: 4px; }

/* ═══ CARDS ═══ */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    padding: 16px 22px;
    font-weight: 600;
    font-size: 0.92rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.card-body { padding: 22px; }
.table-card { padding: 0; }
.table-card .table-wrap { padding: 0; }

/* ═══ FORMS ═══ */
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }

.form-group { display: flex; flex-direction: column; }
.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.req { color: var(--red); }

.form-group input,
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-main);
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,98,204,0.12);
}
.form-group input[readonly] { background: var(--bg); color: var(--text-muted); }

.form-actions { display: flex; gap: 12px; margin-bottom: 20px; }

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { filter: brightness(0.9); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { filter: brightness(0.9); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 0.95rem; }

/* ═══ FILTER BAR ═══ */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* ═══ SUMMARY BAR ═══ */
.summary-bar {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    background: linear-gradient(135deg, var(--blue-light), #f0ecff);
    border-left: 4px solid var(--blue);
    padding: 16px 22px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}
.summary-item { display: flex; flex-direction: column; min-width: 100px; }
.summary-item span { font-size: 0.75rem; font-weight: 600; color: var(--blue-dark); text-transform: uppercase; letter-spacing: 0.04em; }
.summary-item strong { font-size: 1.35rem; font-weight: 700; color: var(--blue); margin-top: 2px; }

/* ═══ TABLE ═══ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead { background: var(--bg); }
th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }

/* ═══ BADGES ═══ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-gray { background: #f3f4f6; color: #6b7280; }

/* ═══ STATUS ═══ */
.status { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.status-active { background: var(--green-light); color: #065f46; }
.status-pending { background: var(--orange-light); color: #92400e; }
.status-blocked { background: var(--red-light); color: #991b1b; }
.status-neutral { background: #f3f4f6; color: #6b7280; }

/* ═══ PRODUCTS LIST (saisie) ═══ */
.product-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.product-row .prod-name { font-weight: 600; min-width: 120px; }
.product-row .prod-detail { font-size: 0.82rem; color: var(--text-muted); flex: 1; }
.product-row .prod-commission { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 80px; text-align: right; }
.product-row .prod-commission.negative { color: var(--red); }
.product-row .btn-remove {
    width: 28px; height: 28px; border: none; background: var(--red-light);
    color: var(--red); border-radius: 6px; cursor: pointer; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.product-row .btn-remove:hover { background: var(--red); color: white; }

.totals-bar {
    display: flex;
    gap: 32px;
    background: var(--blue);
    color: white;
    padding: 14px 22px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
}
.total-item { display: flex; gap: 10px; align-items: center; }
.total-item span { font-size: 0.85rem; opacity: 0.8; }
.total-item strong { font-size: 1.15rem; }

/* ═══ AGENT CARDS ═══ */
.agent-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}
.agent-info h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.agent-info p { font-size: 0.82rem; color: var(--text-muted); margin-top: 4px; }
.agent-stats { display: flex; gap: 20px; }
.agent-stat { text-align: center; }
.agent-stat .val { font-size: 1.1rem; font-weight: 700; color: var(--blue); display: block; }
.agent-stat .lbl { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; }

/* ═══ QUICK ACTIONS (home) ═══ */
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem; font-weight: 500;
    font-family: var(--font-main);
    cursor: pointer; transition: all var(--transition);
    color: var(--text);
}
.quick-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.quick-btn span { width: 28px; height: 28px; background: var(--blue-light); color: var(--blue); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; }

/* ═══ HOME GRID ═══ */
.home-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-bottom: 24px; }

/* ═══ CHART ═══ */
.chart-container { position: relative; min-height: 260px; }

/* ═══ INFO BOX ═══ */
.info-box {
    background: var(--blue-light);
    border-left: 4px solid var(--blue);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: #1e40af;
    line-height: 1.6;
}

/* ═══ EMPTY STATE ═══ */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state h3 { margin-bottom: 6px; }
.empty-small { text-align: center; padding: 30px; color: var(--text-light); font-size: 0.88rem; }

/* ═══ SYNC INDICATOR (table) ═══ */
.sync-icon { font-size: 0.85rem; }
.sync-ok { color: var(--green); }
.sync-pending { color: var(--orange); }

/* ═══ MODAL ═══ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal.modal-lg { max-width: 780px; }

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 700; }
.modal-close {
    width: 32px; height: 32px;
    border: none; background: var(--bg);
    border-radius: 8px; cursor: pointer;
    font-size: 1.2rem; color: var(--text-muted);
}
.modal-close:hover { background: var(--red-light); color: var(--red); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ═══ TOAST ═══ */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    min-width: 280px;
    max-width: 400px;
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.toast.show { transform: translateX(0); pointer-events: auto; }
.toast.success { background: var(--green-light); color: #065f46; border-left: 4px solid var(--green); }
.toast.error { background: var(--red-light); color: #991b1b; border-left: 4px solid var(--red); }
.toast.info { background: var(--blue-light); color: #1e40af; border-left: 4px solid var(--blue); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .home-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .mobile-header { display: flex; }
    .main-content { margin-left: 0; padding: 72px 16px 24px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-4, .form-grid-3, .form-grid-2 { grid-template-columns: 1fr; }
    .filter-bar { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; }
    .quick-actions { grid-template-columns: 1fr; }
    .totals-bar { flex-direction: column; gap: 12px; }
    .agent-card { flex-direction: column; align-items: stretch; }
    .summary-bar { flex-direction: column; gap: 12px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* ═══ PRINT ═══ */
@media print {
    .sidebar, .mobile-header, .filter-bar, .form-actions, .btn, .header-actions, .sidebar-overlay, .login-screen { display: none !important; }
    .main-content { margin-left: 0; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .kpi-card { border: 1px solid #ddd; box-shadow: none; }
}

/* ═══ LOGIN ═══ */
.login-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}
.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 44px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-brand {
    text-align: center;
    margin-bottom: 32px;
}
.login-brand .brand-icon {
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-brand h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.login-brand p {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.login-card .form-group {
    margin-bottom: 16px;
}
.login-error {
    background: var(--red-light);
    color: #991b1b;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    text-align: center;
}
.sidebar-logout {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

@media (max-width: 480px) {
    .login-card {
        margin: 16px;
        padding: 32px 24px;
    }
}
