:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e3e7ef;
  --text: #1c2333;
  --muted: #687089;
  --primary: #2952cc;
  --primary-soft: #e8eefc;
  --side: #14213d;
  --side-text: #c9d2e8;
  --ok: #1a8a5a;
  --ok-soft: #e3f5ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad: #c53030;
  --bad-soft: #fde8e8;
  --info: #2b6cb0;
  --info-soft: #e6f0fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 2px 8px rgba(20, 33, 61, .05);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px; background: #f2b632; color: var(--side);
  display: grid; place-items: center; font-size: 24px; font-weight: 700; font-family: Georgia, serif;
}
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; opacity: .7; }
.nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; }
.nav a {
  color: var(--side-text); padding: 10px 12px; border-radius: 8px;
  display: flex; gap: 10px; align-items: center; font-size: 14px;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav .ico { width: 20px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; font-size: 12px; opacity: .65; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; flex: 1; }
.year-badge { background: var(--primary-soft); color: var(--primary); padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.menu-btn { display: none; }
.view { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

/* ---------- Generic ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.card-head .sub { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.ok-text { color: var(--ok); } .bad-text { color: var(--bad); } .warn-text { color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--primary); }
.kpi.ok { border-top-color: var(--ok); } .kpi.bad { border-top-color: var(--bad); } .kpi.warn { border-top-color: var(--warn); }
.kpi-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: #f1c5c5; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.icon-btn { border: none; background: transparent; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface);
  width: 100%;
}
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar input[type=search] { min-width: 240px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input.invalid, select.invalid { border-color: var(--bad); background: var(--bad-soft); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 14px; border: none; background: none; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover { background: #fafbfe; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.empty { text-align: center; color: var(--muted); padding: 28px; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: none; }

/* ---------- Progress & charts ---------- */
.progress { height: 8px; background: #edf0f6; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.ok > span { background: var(--ok); } .progress.warn > span { background: var(--warn); } .progress.bad > span { background: var(--bad); }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress { flex: 1; }
.progress-row .pct { font-size: 12.5px; color: var(--muted); width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 70%; max-width: 44px; background: var(--primary); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar-val { font-size: 10.5px; color: var(--muted); height: 16px; white-space: nowrap; overflow: hidden; max-width: 100%; }
.bar-lbl { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; max-width: 100%; }

.budget-line { margin-bottom: 14px; }
.budget-line .bl-head { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; gap: 10px; }
.dual { position: relative; height: 12px; background: #edf0f6; border-radius: 99px; overflow: hidden; }
.dual > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ok); border-radius: 99px; }
.dual.over > span { background: var(--bad); }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; }

.welcome { text-align: center; padding: 48px 20px; }
.welcome h2 { font-size: 22px; margin-bottom: 10px; }
.welcome p { color: var(--muted); max-width: 560px; margin: 0 auto 22px; }
.welcome .actions { justify-content: center; }

.project-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.project-card { cursor: pointer; margin: 0; transition: border-color .15s; }
.project-card:hover { border-color: var(--primary); }
.project-card h3 { font-size: 16px; margin-bottom: 6px; }
.project-card .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; font-size: 13px; }
.project-card .meta b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }
.alert.warn { background: var(--warn-soft); color: #7a5112; }
.alert.bad { background: var(--bad-soft); color: #8a1f1f; }
.alert.info { background: var(--info-soft); color: #1e4e80; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; align-content: start; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full, .form-grid .full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #3a4258; }
.field .req { color: var(--bad); }
.field .help { color: var(--muted); font-size: 12.5px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: auto; }
.form-section { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); padding-top: 4px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }

/* ---------- Relances ---------- */
.apercu { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 13.5px; margin: 6px 0; max-height: 320px; overflow-y: auto; }
.apercu.sms { background: var(--primary-soft); border-color: transparent; border-radius: 14px 14px 14px 4px; max-width: 380px; }
.sel { width: auto; }
.card-head .btn { margin-left: auto; }
.msg-section { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.msg-section .full { grid-column: 1 / -1; }
@media (max-width: 900px) { .msg-section { grid-template-columns: 1fr; } }

/* ---------- Comptes / connexion ---------- */
.user-box { display: flex; gap: 10px; align-items: center; opacity: 1; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.user-role { font-size: 12px; }
.user-actions { display: flex; gap: 6px; margin-top: 10px; }
.user-actions button { flex: 1; background: rgba(255,255,255,.08); color: var(--side-text); border: 1px solid rgba(255,255,255,.12); border-radius: 6px; padding: 5px 6px; font: inherit; font-size: 12px; cursor: pointer; }
.user-actions button:hover { background: rgba(255,255,255,.16); color: #fff; }
.sidebar-foot { opacity: .9; }
body.auth-mode .sidebar, body.auth-mode .topbar, body.auth-mode .overlay { display: none !important; }
body.auth-mode .view { max-width: none; padding: 16px; }
.auth-wrap { min-height: calc(100vh - 32px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; padding: 28px; margin: 0; }
.auth-card h2 { font-size: 20px; }
.auth-card p { margin: 0; }
.auth-card .alert { margin: 0; }
.auth-brand { display: flex; gap: 12px; align-items: center; }
.auth-submit { justify-content: center; padding: 10px; margin-top: 4px; }
[hidden] { display: none !important; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1c2333; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; animation: tin .2s ease-out; }
.toast-btn { margin-left: 12px; background: rgba(255,255,255,.2); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 6px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.toast.error { background: var(--bad); }
.toast.success { background: var(--ok); }
.toast.warn { background: var(--warn); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Print ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff; display: block; }
  #print-area { display: block; }
  @page { margin: 14mm; }
}
.print-doc { font-size: 12.5px; color: #000; }
.print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 16px; }
.print-head .r { text-align: right; }
.print-doc h1 { font-size: 18px; text-align: center; margin: 10px 0 18px; text-transform: uppercase; letter-spacing: .05em; }
.print-doc table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.print-doc th, .print-doc td { border: 1px solid #555; padding: 5px 7px; text-align: left; }
.print-doc th { background: #eee; }
.print-doc td.num, .print-doc th.num { text-align: right; }
.print-doc .sign { display: flex; justify-content: space-between; margin-top: 40px; }
.print-doc .sign div { width: 40%; text-align: center; border-top: 1px solid #000; padding-top: 6px; }
.print-doc .big { font-size: 16px; font-weight: 700; }
.print-doc .receipt { border: 2px solid #000; padding: 16px; max-width: 640px; margin: 0 auto 24px; }

/* ---------- Responsive ---------- */
.overlay { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .menu-btn { display: inline-block; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .toolbar input, .toolbar select, .toolbar input[type=search] { min-width: 0; width: 100%; }
  .toolbar .spacer { display: none; }
  .project-cards { grid-template-columns: 1fr; }
}
