:root {
  --navy: #123262;
  --navy-dark: #0c2347;
  --navy-light: #1d4380;
  --gold: #be822f;
  --gold-light: #d9a256;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2434;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #b3362c;
  --ok: #1e7d4f;
  --radius: 10px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
.hidden { display: none !important; }
a { color: var(--navy); }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--navy-dark), var(--navy) 60%, var(--navy-light));
  padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 40px 36px;
  width: 100%; max-width: 480px; box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-card .brand { text-align: center; margin-bottom: 28px; }
.login-card .brand img { width: 64px; height: 64px; }
.login-card h1 { font-size: 24px; color: var(--navy); margin-top: 10px; }
.login-card .brand p { color: var(--gold); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; font-size: 11px; margin-top: 4px; }
.demo-note {
  margin-top: 18px; background: #fdf6ec; border: 1px solid #f0dcbe; border-radius: 8px;
  padding: 10px 14px; font-size: 13px; color: #7a5a24;
}
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.demo-chip {
  text-align: left; background: #f4f6fa; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; font-family: inherit;
}
.demo-chip:hover { background: #eaf0fa; border-color: var(--navy); }
.demo-chip b { display: block; color: var(--navy); font-size: 13.5px; }
.demo-chip span { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; line-height: 1.35; }
@media (max-width: 480px) { .demo-grid { grid-template-columns: 1fr; } }

/* ---- Layout ---- */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 240px; background: var(--navy-dark); color: #cdd8ea; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; }
.side-brand img { width: 38px; height: 38px; }
.side-brand div b { color: #fff; font-size: 15px; display: block; }
.side-brand div span { color: var(--gold-light); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 600; }
.module-badge {
  margin: 4px 16px 14px; background: rgba(190,130,47,.18); color: var(--gold-light);
  border: 1px solid rgba(190,130,47,.4); border-radius: 20px; padding: 3px 12px;
  font-size: 11.5px; font-weight: 600; text-align: center;
}
#sidebar nav { flex: 1; padding: 4px 10px; }
#sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #cdd8ea; text-decoration: none; font-size: 14px; margin-bottom: 2px;
}
#sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
#sidebar nav a.active { background: var(--gold); color: #fff; font-weight: 600; }
#sidebar nav a .ic { width: 20px; text-align: center; }
.side-foot { padding: 14px 16px; font-size: 11px; color: #7d90ad; border-top: 1px solid rgba(255,255,255,.08); }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 26px; position: sticky; top: 0; z-index: 5;
}
#topbar h2 { font-size: 18px; color: var(--navy); }
.user-chip { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--muted); }
.user-chip b { color: var(--text); }
#main { padding: 26px; max-width: 1200px; width: 100%; }

/* ---- Composants ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--navy); margin-top: 6px; }
.stat-card .value.gold { color: var(--gold); }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px;
}
.panel h3 { font-size: 15px; color: var(--navy); margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.panel-head h3 { margin-bottom: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 2px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.ouvert, .badge.emise, .badge.a_faire { background: #e8effc; color: var(--navy); }
.badge.en_cours, .badge.projet { background: #fdf3e3; color: var(--gold); }
.badge.clos, .badge.fait, .badge.payee, .badge.signe, .badge.enregistre { background: #e3f3ea; color: var(--ok); }
.badge.retard { background: #fbe9e7; color: var(--danger); }
.badge.depot { background: #e3f3ea; color: var(--ok); }
.badge.retrait { background: #fbe9e7; color: var(--danger); }

button, .btn {
  background: var(--navy); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
button:hover, .btn:hover { background: var(--navy-light); }
button.gold { background: var(--gold); }
button.gold:hover { background: var(--gold-light); }
button.ghost { background: transparent; color: var(--navy); border: 1px solid var(--border); }
button.ghost:hover { background: #f1f5f9; }
button.small { padding: 5px 12px; font-size: 13px; }
button.danger { background: var(--danger); }
button:disabled { opacity: .55; cursor: default; }

input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(18,50,98,.25); border-color: var(--navy); }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
textarea.acte { font-family: "Courier New", monospace; font-size: 13.5px; line-height: 1.55; min-height: 420px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(12,35,71,.55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 640px;
  padding: 26px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal h3 { color: var(--navy); font-size: 17px; margin-bottom: 6px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.scan-zone {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #eef4fd; border: 1px dashed var(--navy-light); border-radius: 10px;
  padding: 12px 14px; margin: 10px 0 4px;
}
.scan-zone .scan-txt { flex: 1; min-width: 190px; }
.scan-zone .scan-txt b { color: var(--navy); font-size: 14px; }
.scan-zone .scan-txt p { font-size: 12px; margin-top: 2px; }
.scan-zone #scan-status { flex-basis: 100%; font-size: 12.5px; }
.scan-zone.compact { padding: 8px 10px; margin: 0 0 8px; gap: 8px; }
.scan-zone.compact .p-status { flex-basis: 100%; font-size: 12px; }

/* Intervenants d'un dossier */
.parties-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 16px 0 8px; }
.parties-head b { color: var(--navy); font-size: 15px; }
.parties-head p { font-size: 12px; margin-top: 2px; max-width: 420px; }
.party-slot { border: 1px solid var(--border); border-left: 3px solid var(--gold); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: #fbfcfe; }
.party-slot-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.party-slot-head .p-role { font-weight: 600; }
.party-slot-head .p-remove { flex-shrink: 0; padding: 5px 10px; }
.party-slot .p-client { margin-bottom: 8px; }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy-dark); color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 14px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .25s;
  max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }

/* ---- Assistant ---- */
.chat-box { display: flex; flex-direction: column; height: 60vh; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 8px 4px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 12px; margin-bottom: 10px; white-space: pre-wrap; line-height: 1.5; }
.msg.user { background: var(--navy); color: #fff; margin-left: auto; border-bottom-right-radius: 3px; }
.msg.ia { background: #eef2f8; border-bottom-left-radius: 3px; }
.chat-input { display: flex; gap: 10px; margin-top: 12px; }

/* ---- Divers ---- */
.muted { color: var(--muted); font-size: 13px; }
.warn-box {
  background: #fdf6ec; border: 1px solid #f0dcbe; border-radius: 8px;
  padding: 10px 14px; font-size: 13px; color: #7a5a24; margin-bottom: 14px;
}
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; }
  #sidebar nav { display: flex; flex-wrap: wrap; }
  #main { padding: 16px; }
}
