:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #e2e6ea;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #1f7a5c;
    --primary-dark: #165c45;
    --danger: #dc2626;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Topbar ---- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 56px;
    padding: 0 24px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand span { color: var(--primary); }
.topnav { display: flex; gap: 20px; flex: 1; }
.topnav a { color: var(--text-muted); font-weight: 500; padding: 6px 2px; border-bottom: 2px solid transparent; }
.topnav a.active, .topnav a:hover { color: var(--text); border-bottom-color: var(--primary); text-decoration: none; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-muted); }
.topbar-user small { color: var(--text-muted); }

/* ---- Layout ---- */
.page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.page-narrow { max-width: 420px; margin: 60px auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 22px; }

/* ---- Flash messages ---- */
.flash-stack { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef2f5; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e4e9ed; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.link-button { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.link-button.danger { color: var(--danger); }

/* ---- Login ---- */
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; text-align: center; }
.login-box h1 { margin-top: 0; }
.login-box .accent { color: var(--primary); }
.login-box form { text-align: left; display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---- Forms ---- */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="file"], select, textarea {
    font: inherit;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}
textarea { resize: vertical; }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-label input { width: 16px; height: 16px; }

.client-form fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px 20px; margin-bottom: 18px; background: var(--surface); }
.client-form legend { font-weight: 700; padding: 0 6px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid-3 { grid-template-columns: 1.5fr 1fr 0.1fr; align-items: center; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 12px; align-items: center; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

/* ---- Filter bar ---- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input[type="text"] { flex: 1; min-width: 200px; }

/* ---- Board : liste de clients + colonne de statuts à droite ---- */
.board-layout { display: flex; gap: 20px; align-items: flex-start; }
.board-main { flex: 1; min-width: 0; }

.board-sidebar {
    width: 250px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    position: sticky;
    top: 66px;
    z-index: 3;
    max-height: calc(100vh - 86px);
    overflow-y: auto;
}
.status-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border-left: 3px solid transparent;
}
.status-link:hover { background: #f4f6f8; text-decoration: none; }
.status-link.active { background: #eef2f5; border-left-color: var(--group-color, var(--primary)); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot-color, #999); flex-shrink: 0; }
.status-link-label { flex: 1; letter-spacing: 0.02em; }
.status-link-count { color: var(--text-muted); font-weight: 700; font-size: 12px; }

.active-status-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--group-color, #999);
    color: #fff;
    border-radius: 10px 10px 0 0;
    flex-shrink: 0;
}
.active-status-header + .table-wrap { border-radius: 0 0 10px 10px; border-top: none; }
.active-status-header .group-title { font-weight: 700; letter-spacing: 0.03em; font-size: 13px; }
.active-status-header .group-count {
    background: rgba(255,255,255,0.25);
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 12px;
    font-weight: 700;
}
.empty-group { padding: 14px 16px; margin: 0; color: var(--text-muted); font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

@media (max-width: 900px) {
    .board-layout { flex-direction: column; }
    .board-sidebar { width: 100%; position: static; flex-direction: row; flex-wrap: wrap; max-height: none; overflow-y: visible; }
}

/* ---- Table ----
   .table-wrap est lui-même la zone de défilement (bornée en hauteur) :
   c'est ce qui permet à l'en-tête du tableau de rester figé ("sticky")
   pendant qu'on fait défiler les lignes, sans dépendre du défilement de
   la page entière (qui casserait le calcul de position). */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto;
    max-height: calc(100vh - 210px);
}
.board-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.board-table th, .board-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.board-table th { background: #fafbfc; color: var(--text-muted); font-weight: 600; position: sticky; top: 0; z-index: 2; }
.board-table th a { color: var(--text-muted); }
.board-table tbody tr:hover { background: #f8fafc; cursor: pointer; }
.cell-name { font-weight: 600; }
.empty-row { text-align: center; color: var(--text-muted); padding: 40px; cursor: default; }
.empty-row:hover { background: none; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: var(--pill-color, #999);
}

/* ---- Documents ---- */
.documents-section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-top: 20px; }
.documents-section h2 { margin-top: 0; font-size: 16px; }
.upload-form { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.upload-form input[type="text"] { flex: 1; min-width: 200px; }
.document-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.document-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }

@media (max-width: 700px) {
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .topbar-inner { flex-wrap: wrap; gap: 12px; }
}
