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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #22252f;
    --border: #2a2d3a;
    --text: #e2e4ea;
    --text-dim: #8b8fa3;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ─── Navbar ──────────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
}

.nav-logo { font-size: 20px; }

.nav-links {
    display: flex;
    gap: 4px;
}

.nav-links a {
    color: var(--text-dim);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: var(--radius);
    transition: all .15s;
}

.nav-links a:hover { color: var(--text); background: var(--bg-hover); }
.nav-links a.active { color: var(--accent); background: rgba(99, 102, 241, .1); }

.nav-actions { display: flex; gap: 8px; }

/* ─── Container ───────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }
.section { margin-bottom: 32px; }
.section h2 { margin-bottom: 16px; font-size: 18px; font-weight: 600; }

/* ─── Stats Grid ──────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-skipped .stat-number {
    color: #6b7280;
}

.badge-status-skipped {
    background-color: #6b7280;
    color: white;
}

.stat-number { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }

.stat-pending .stat-number { color: var(--warning); }
.stat-sent .stat-number { color: var(--success); }
.stat-rejected .stat-number { color: var(--danger); }
.stat-error .stat-number { color: var(--danger); }

/* ─── Table ───────────────────────────────────────────── */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,.2);
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.table tbody tr:hover { background: var(--bg-hover); }
.table-sm td, .table-sm th { padding: 6px 10px; font-size: 12px; }

.clickable-row { cursor: pointer; }
.supplier-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Badges ──────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-before_due { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-first_reminder { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-second_reminder { background: rgba(249,115,22,.15); color: #fb923c; }
.badge-formal_notice { background: rgba(239,68,68,.15); color: #f87171; }
.badge-unknown { background: rgba(139,143,163,.15); color: var(--text-dim); }

.badge-scenario-not_due_found { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-scenario-not_due_not_found { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-scenario-overdue_found { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-scenario-overdue_not_found { background: rgba(249,115,22,.15); color: #fb923c; }
.badge-scenario-already_paid { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-scenario-blocked { background: rgba(239,68,68,.15); color: #f87171; }
.badge-scenario-unmatched { background: rgba(139,143,163,.15); color: var(--text-dim); }

.badge-status-pending { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-status-sent { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-status-modified { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-status-rejected { background: rgba(239,68,68,.15); color: #f87171; }
.badge-status-error { background: rgba(239,68,68,.3); color: #fca5a5; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}

.btn:hover { background: var(--bg-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }

.btn-warning { background: var(--warning); border-color: var(--warning); color: #000; }
.btn-warning:hover { opacity: .9; }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }

.btn-secondary { background: transparent; }

/* ─── Detail / Split View ─────────────────────────────── */
.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.detail-meta { display: flex; gap: 8px; }

.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,.2);
}

.panel-header h3 { font-size: 14px; font-weight: 600; }
.panel-body { padding: 16px; }

.email-meta { margin-bottom: 16px; font-size: 13px; }
.email-meta div { margin-bottom: 4px; }
.email-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-dim);
    max-height: 500px;
    overflow-y: auto;
}

.pj-badge {
    display: inline-block;
    background: rgba(99,102,241,.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    margin: 2px;
}

.extraction-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
    font-size: 13px;
}

.confidence {
    background: rgba(34,197,94,.15);
    color: #4ade80;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.response-subject {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.response-body {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    padding: 12px;
    background: rgba(0,0,0,.2);
    border-radius: var(--radius);
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.edit-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    margin-top: 8px;
}

.reject-reason {
    margin-top: 12px;
    padding: 10px;
    background: rgba(239,68,68,.1);
    border-radius: var(--radius);
    font-size: 13px;
}

/* ─── Empty state ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.empty-icon { font-size: 40px; display: block; margin-bottom: 12px; }

/* ─── Toast ───────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
    animation: slideIn .3s ease;
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--info); color: #fff; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── HTMX indicator ─────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 900px) {
    .split-view { grid-template-columns: 1fr; }
    .navbar { flex-wrap: wrap; gap: 8px; }
}

/* ─── Login ───────────────────────────────────────────── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo { font-size: 36px; display: block; margin-bottom: 12px; }
.login-header h1 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.login-header p { font-size: 13px; color: var(--text-dim); }

.login-error {
    background: rgba(239,68,68,.15);
    color: #f87171;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-full { width: 100%; justify-content: center; margin-top: 8px; }

/* ─── PDF Viewer ──────────────────────────────────────── */
.pdf-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.pdf-viewer-wrapper {
    margin-bottom: 12px;
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(0,0,0,.3);
    border-radius: var(--radius) var(--radius) 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
}

.pdf-filename {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 500;
}

.pdf-iframe {
    width: 100%;
    height: 600px;
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    background: #fff;
}


/* ─── Upload PJ réponse (outgoing) ────────────────────── */

.outgoing-upload {
    margin-top: 16px;
    padding: 12px;
    background: rgba(0,0,0,.2);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.outgoing-header {
    margin-bottom: 8px;
    font-size: 13px;
}

.outgoing-header .text-dim {
    color: var(--text-dim);
    font-size: 12px;
}

.outgoing-upload input[type="file"] {
    font-size: 12px;
    color: var(--text-dim);
}

.pj-outgoing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(99,102,241,.1);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    margin: 4px 4px 0 0;
}

.btn-remove-pj {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}

.btn-remove-pj:hover {
    opacity: .7;
}

.stat-skipped .stat-number {
    color: #6b7280;
}

.badge-status-skipped {
    background: rgba(107,114,128,.15);
    color: #9ca3af;
}


/* ─── Filtres gommettes ───────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-right: 4px;
}

.filter-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    transition: all .15s;
    cursor: pointer;
}

.filter-tag:hover { background: var(--bg-hover); color: var(--text); }
.filter-tag.active { color: #fff; border-color: transparent; }

.filter-tag.active:not(.filter-paid):not(.filter-not-due):not(.filter-overdue):not(.filter-not-found):not(.filter-unmatched):not(.filter-formal) {
    background: var(--accent);
}
.filter-paid.active { background: #22c55e; }
.filter-not-due.active { background: #3b82f6; }
.filter-overdue.active { background: #f59e0b; }
.filter-not-found.active { background: #f97316; }
.filter-unmatched.active { background: #6b7280; }
.filter-formal.active { background: #ef4444; }



.reliability-footer {
    text-align: right;
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0.4;
    padding: 20px 0 0;
    margin-top: 40px;
}

.reliability-footer:hover {
    opacity: 1;
}



/* ─── Bouton Bloquer ──────────────────────────────────── */
.btn-orange { background: #f97316; border-color: #f97316; color: #fff; }
.btn-orange:hover { opacity: .9; }

.dropdown-block {
    position: relative;
    display: inline-block;
}

.block-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    z-index: 10;
    min-width: 260px;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.block-dropdown button {
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.block-dropdown button:last-child { border-bottom: none; }
.block-dropdown button:hover { background: var(--bg-hover); }