/* IRS San Andreas : marine et or du sceau, contenu clair pour lire de longues listes. */
:root {
  --navy-900: #04283f;
  --navy-800: #063a5a;
  --navy-700: #054a72;
  --blue: #0a85c8;
  --gold: #e8c453;
  --gold-soft: #f6e7ad;
  --paper: #f3f5f8;
  --card: #ffffff;
  --ink: #16212c;
  --muted: #5d6b79;
  --line: #dbe1e8;
  --ok: #17803d;
  --ok-bg: #e2f5e9;
  --warn: #9a6200;
  --warn-bg: #fdf0d2;
  --bad: #b3261e;
  --bad-bg: #fbe3e1;
  --info-bg: #e1f0fa;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: 0.01em; }
a { color: var(--navy-700); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% 0%, var(--navy-700), var(--navy-900)); }
.login-card { width: min(420px, 100%); background: var(--card); border-radius: 16px; padding: 28px 28px 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); border-top: 6px solid var(--gold); }
.login-card img.banner { display: block; height: 64px; margin: 0 auto 14px; }
.login-card h1 { text-align: center; font-size: 22px; color: var(--navy-700); }
.login-card p.sub { text-align: center; margin: 4px 0 22px; color: var(--muted); }
.login-card .foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: linear-gradient(180deg, var(--navy-800), var(--navy-900)); color: #dbe7f1; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.12); margin-bottom: 10px; }
.brand img { width: 52px; height: 52px; }
.brand b { display: block; font: 700 17px var(--serif); color: #fff; line-height: 1.15; }
.brand span { font-size: 12px; color: var(--gold); letter-spacing: 0.08em; text-transform: uppercase; }
.nav-group { margin: 12px 10px 4px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #8aa7bd; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #dbe7f1; text-decoration: none; font-weight: 500; }
.side a.nav:hover { background: rgba(255, 255, 255, 0.08); }
.side a.nav[aria-current="page"] { background: var(--gold); color: var(--navy-900); font-weight: 700; }
.side .me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255, 255, 255, 0.12); font-size: 13px; }
.side .me b { display: block; color: #fff; }
.side .me button { margin-top: 8px; width: 100%; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .search { flex: 1; max-width: 520px; position: relative; }
.top .search input { width: 100%; }
.top .date { margin-left: auto; color: var(--muted); font-size: 13px; }
.results { position: absolute; left: 0; right: 0; top: 100%; margin-top: 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(4, 40, 63, 0.18); max-height: 60vh; overflow-y: auto; z-index: 20; }
.results h4 { margin: 0; padding: 8px 14px 4px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.results a { display: block; padding: 8px 14px; text-decoration: none; color: var(--ink); }
.results a:hover { background: var(--info-bg); }
.page { padding: 26px 28px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 28px; color: var(--navy-700); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- Composants ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 18px; color: var(--navy-700); margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.card h2 .tools { margin-left: auto; display: flex; gap: 8px; font-family: var(--sans); font-weight: 400; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--gold); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.kpi .value { font: 700 28px var(--serif); color: var(--navy-700); margin-top: 2px; }
.kpi.bad { border-left-color: var(--bad); }
.kpi.bad .value { color: var(--bad); }
.kpi.ok { border-left-color: var(--ok); }
.kpi small { color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-weight: 600; text-decoration: none; color: var(--ink); }
.btn:hover { background: #eef3f8; }
.btn.primary { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.btn.primary:hover { background: var(--navy-800); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy-900); }
.btn.danger { color: var(--bad); border-color: #e7b4b0; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.side .btn { background: transparent; border-color: rgba(255, 255, 255, 0.25); color: #fff; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid #b9c4d0; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(10, 133, 200, 0.18); }
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.error { color: var(--bad); font-size: 13px; margin: 6px 0; min-height: 1em; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #f8fafc; }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--info-bg); color: var(--navy-700); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.gold { background: var(--gold-soft); color: #6b5200; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 16px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs button[aria-selected="true"] { color: var(--navy-700); border-bottom-color: var(--gold); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 500; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; font-size: 11px; color: var(--muted); }
.bars .bar i { display: block; width: 100%; background: linear-gradient(180deg, var(--blue), var(--navy-700)); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar.now i { background: linear-gradient(180deg, var(--gold), #c79d1f); }
.callout { padding: 12px 14px; border-radius: 8px; background: var(--info-bg); border-left: 4px solid var(--blue); margin-bottom: 14px; }
.callout.warn { background: var(--warn-bg); border-left-color: var(--warn); }
.callout.bad { background: var(--bad-bg); border-left-color: var(--bad); }
.callout.ok { background: var(--ok-bg); border-left-color: var(--ok); }

/* ---------- Fenêtres et messages ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(4, 40, 63, 0.55); display: grid; place-items: center; padding: 20px; z-index: 50; overflow-y: auto; }
.modal { background: var(--card); border-radius: 14px; width: min(620px, 100%); padding: 22px 24px; border-top: 5px solid var(--gold); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4); }
.modal.wide { width: min(860px, 100%); }
.modal h2 { font-size: 20px; color: var(--navy-700); margin-bottom: 14px; }
.modal .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--navy-900); color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 80; border-left: 4px solid var(--gold); max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-left-color: #ff7b72; }

/* ---------- Documents imprimables ---------- */
.paper { background: #fff; border: 1px solid var(--line); max-width: 800px; margin: 0 auto; padding: 44px 52px; font-family: var(--serif); line-height: 1.55; }
.paper header { display: flex; align-items: center; gap: 18px; border-bottom: 3px double var(--navy-700); padding-bottom: 14px; margin-bottom: 20px; }
.paper header img { width: 78px; height: 78px; }
.paper header h1 { font-size: 22px; color: var(--navy-700); }
.paper header p { margin: 2px 0 0; color: var(--muted); font-family: var(--sans); font-size: 13px; }
.paper h2 { font-size: 17px; margin: 18px 0 6px; color: var(--navy-700); }
.paper table { font-family: var(--sans); font-size: 14px; }
.paper .sign { display: flex; justify-content: space-between; margin-top: 46px; font-family: var(--sans); font-size: 13px; }
.paper .sign div { width: 44%; border-top: 1px solid #000; padding-top: 6px; }
.paper .ref { text-align: right; font-family: var(--sans); font-size: 13px; color: var(--muted); }
.paper dl.facts { font-family: var(--sans); font-size: 15px; margin: 14px 0; }
.paper dd.big { font-size: 24px; font-weight: 800; color: var(--navy-700); }
.paper footer { margin-top: 30px; padding-top: 12px; border-top: 1px solid var(--line); font-family: var(--sans); font-size: 12px; color: var(--muted); }
.paper .body { white-space: pre-wrap; }
.stamp { display: inline-block; border: 3px solid var(--bad); color: var(--bad); padding: 0 10px; border-radius: 6px; font: 800 14px var(--sans); letter-spacing: 2px; transform: rotate(-4deg); vertical-align: middle; }

/* ---------- Petits éléments partagés ---------- */
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.row-between:last-child { border-bottom: 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
label.inline input { width: auto; min-width: 0; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
dl.totals dd { text-align: right; font-variant-numeric: tabular-nums; }
.pick-list { display: grid; gap: 6px; max-height: 320px; overflow-y: auto; margin: 4px 0 8px; }
.pick { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pick:hover, .pick:focus-visible { border-color: var(--blue); background: var(--info-bg); }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1180px) { .grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
ol.steps { margin: 0 0 14px; padding-left: 22px; display: grid; gap: 12px; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { box-shadow: 0 4px 14px rgba(5, 74, 114, 0.15); }
.kpi.sel { outline: 2px solid var(--gold); outline-offset: 1px; }
.bar-row { display: grid; grid-template-columns: minmax(130px, 1fr) 2fr max-content; align-items: center; gap: 12px; padding: 6px 0; font-size: 14px; }
.bar-row b { font-variant-numeric: tabular-nums; }
.grow2 { grid-column: span 2; }
.total-line { text-align: right; margin: 10px 0 0; }
.link-btn { border: 0; background: none; color: var(--bad); padding: 0 2px; font-size: 12px; }
.event-form { display: grid; grid-template-columns: 220px 1fr max-content; gap: 10px; align-items: start; margin-bottom: 16px; }
.event-form textarea { min-height: 44px; }
@media (max-width: 960px) { .grow2 { grid-column: auto; } .event-form { grid-template-columns: 1fr; } }
.law-row { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; }
.law-row:hover, .law-row:focus-visible { background: var(--info-bg); }
.law-row:last-child { border-bottom: 0; }
.law-text { white-space: pre-wrap; line-height: 1.6; max-height: 60vh; overflow-y: auto; padding-right: 8px; font-family: var(--serif); }
mark { background: var(--gold-soft); padding: 0 2px; border-radius: 2px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 46ch; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 3px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 14px; }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--gold); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.timeline .when { color: var(--muted); font-size: 12px; }
.gauge { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.gauge i { display: block; height: 100%; background: var(--ok); }
.gauge.warn i { background: #d9a200; }
.gauge.bad i { background: var(--bad); }

td input[type="number"], td input[type="text"] { max-width: 150px; }
@media (max-width: 1180px) {
  .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .me { margin-top: 0; width: 100%; }
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page { padding: 18px 14px 50px; }
}
@media print {
  .side, .top, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  body, .paper { background: #fff; }
  .page { padding: 0; max-width: none; }
  .paper { border: 0; padding: 0; max-width: none; }
}
