:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #667085;
  --line: #e3e7ee;
  --brand: #12355b;
  --brand-2: #1f5f99;
  --accent: #0e9f8e;
  --danger: #c2410c;
  --danger-bg: #fff1e8;
  --warn: #a16207;
  --warn-bg: #fef9e7;
  --ok: #15803d;
  --ok-bg: #eaf7ee;
  --info-bg: #eaf2fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ===== Mise en page ===== */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { font-weight: 700; font-size: 17px; padding: 4px 10px 18px; letter-spacing: .02em; }
.logo span { display: block; font-size: 11px; font-weight: 400; opacity: .7; letter-spacing: .08em; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 10px; color: #dbe6f3; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; }
.sidebar .bottom { margin-top: auto; font-size: 12px; opacity: .8; padding: 10px; }
.sidebar .bottom button { margin-top: 8px; width: 100%; }
.main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* ===== Composants ===== */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, 1fr); } .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi.alert .v { color: var(--danger); }
a.kpi:hover { text-decoration: none; border-color: var(--brand-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); color: var(--ink); transition: .15s; }
.tile:hover { border-color: var(--brand-2); transform: translateY(-1px); text-decoration: none; }
.tile .t-ico { font-size: 22px; }
.tile .t-name { font-weight: 600; margin-top: 8px; }
.tile .t-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c5ccd8; text-decoration: none; }
.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.primary:hover { background: var(--brand); border-color: var(--brand); }
.danger { color: var(--danger); }
.ghost { background: transparent; border-color: transparent; }
.sm { padding: 4px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--ink); width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd6ef; border-color: var(--brand-2); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form .check { display: flex; align-items: center; gap: 8px; }
.form .check input { width: auto; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #fafbfc; position: sticky; top: 0; cursor: default; }
th.sort { cursor: pointer; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: 70vh; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef1f5; color: #344054; white-space: nowrap; }
.b-red { background: var(--danger-bg); color: var(--danger); }
.b-orange { background: var(--warn-bg); color: var(--warn); }
.b-green { background: var(--ok-bg); color: var(--ok); }
.b-blue { background: var(--info-bg); color: var(--brand-2); }
.b-dark { background: #1f2937; color: #fff; }
.late { color: var(--danger); font-weight: 600; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand-2); font-weight: 600; }
.tabs .count { background: #eef1f5; border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 4px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; word-break: break-word; }

/* ===== Journal ===== */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.evt { position: relative; padding: 0 0 14px 10px; }
.evt::before { content: ""; position: absolute; left: -17px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.evt.t-rejet_prelevement::before, .evt.t-injonction::before, .evt.t-tribunal::before, .evt.t-mise_en_demeure::before { background: var(--danger); }
.evt.t-virement::before { background: var(--ok); }
.evt.t-legalcity::before { background: #7c3aed; }
.evt.t-systeme::before { background: #98a2b3; }
.evt .h { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.evt .d { color: var(--muted); font-size: 12px; }
.evt .titre { font-weight: 600; }
.evt .det { white-space: pre-wrap; color: #344054; margin-top: 3px; font-size: 13px; }

/* ===== Fil de mails ===== */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; }
.msg.sortant { align-self: flex-end; background: #eef5fc; border-color: #d4e4f5; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .sujet { font-weight: 600; margin-bottom: 4px; }
.msg .corps { white-space: pre-wrap; font-size: 13px; }

/* ===== Modale & notifications ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--danger); }

/* ===== Connexion ===== */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--brand) 0%, #0b2440 100%); }
.login .card { width: 360px; padding: 28px; }
.login h1 { color: var(--brand); }
.login form { display: grid; gap: 12px; margin-top: 16px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.alert-box { border-left: 4px solid var(--danger); background: var(--danger-bg); padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.info-box { border-left: 4px solid var(--brand-2); background: var(--info-bg); padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.dropzone { border: 2px dashed #c5ccd8; border-radius: 12px; padding: 30px; text-align: center; background: #fafbfc; cursor: pointer; }
.dropzone.over { border-color: var(--brand-2); background: var(--info-bg); }

/* ===== Impression (dossier tribunal) ===== */
@media print {
  .sidebar, .no-print, .tabs, .toolbar, .page-head .actions { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card, .table-wrap { box-shadow: none; border: none; max-height: none; overflow: visible; }
  body { background: #fff; }
}
