:root {
  --bg: #eef1f6; --surface: #fff; --ink: #1b2333; --muted: #5d687e; --line: #d5dbe7;
  --head: #3f5b8f; --head-ink: #fff; --frame: #14267a; --accent: #1f3a7a; --accent-soft: #e4eaf7;
  --danger: #d94a4a; --danger-soft: #fdeaea; --warn-soft: #fff4d6; --ok: #0db36b;
  --radius: 6px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #5b82d6; outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- Barre supérieure ---- */
.topbar { background: var(--frame); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1500px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 14px; min-height: 54px; }
.brand { display: flex; flex-direction: column; line-height: 1.1; text-decoration: none; color: #fff; white-space: nowrap; }
.brand b { font-size: 1.05rem; } .brand span { font-size: .78rem; opacity: .75; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: #cfd8f3; text-decoration: none; padding: 16px 13px 13px; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 550; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: #f2c94c; }
.tools { display: flex; align-items: center; gap: 8px; }
.search { position: relative; }
.search input { width: 220px; padding: 7px 10px; border-radius: var(--radius); border: 0; background: #2a3c94; color: #fff; }
.search input::placeholder { color: #a9b6e6; }
.results { position: absolute; right: 0; top: 40px; width: 340px; max-height: 60vh; overflow: auto; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(10, 20, 60, .25); }
.results button { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; padding: 9px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.results button:hover { background: var(--accent-soft); }
.iconbtn { background: transparent; border: 1px solid #4a5cb4; color: #fff; border-radius: var(--radius); padding: 6px 10px; cursor: pointer; position: relative; }
.iconbtn:hover { background: #26398f; }
.badge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border-radius: 10px; font-size: .7rem; padding: 1px 6px; }
.usermenu { position: relative; }
.usermenu .menu { position: absolute; right: 0; top: 40px; min-width: 210px; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(10, 20, 60, .25); padding: 6px; z-index: 30; }
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 4px; cursor: pointer; text-decoration: none; color: inherit; }
.menu button:hover, .menu a:hover { background: var(--accent-soft); }

/* ---- Pages ---- */
main { max-width: 1500px; margin: 0 auto; padding: 20px 16px 60px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.pagehead p { margin: 4px 0 0; color: var(--muted); }
.banner { background: var(--warn-soft); border: 1px solid #ecd58a; padding: 8px 12px; border-radius: var(--radius); margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; }
.card > h2 { margin-bottom: 10px; }

/* ---- Boutons & champs ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; font-weight: 550; text-decoration: none; }
.btn:hover { background: #172d62; }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger.ghost { background: #fff; color: var(--danger); }
.btn.danger.ghost:hover { background: var(--danger-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.mini { padding: 2px 8px; font-size: .8rem; border-radius: 4px; border: 1px solid var(--ok); background: #fff; color: #07784a; cursor: pointer; white-space: nowrap; }
.mini:hover { background: #e2f8ee; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=url], input[type=search], select, textarea {
  padding: 7px 9px; border: 1px solid #b8c1d4; border-radius: var(--radius); background: #fff; max-width: 100%; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: .9rem; }
.field .hint { color: var(--muted); font-size: .82rem; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.error { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 10px; }

/* ---- Pastilles de statut ---- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 4px; font-size: .84rem; font-weight: 600; white-space: nowrap; text-align: center; min-width: 96px; }
select.pillsel { border: 0; font-weight: 600; font-size: .84rem; padding: 4px 6px; min-width: 120px; cursor: pointer; border-radius: 4px; }

/* ---- Tableaux (esprit tableur) ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.toolbar input[type=search] { width: 240px; }
.sheet-wrap { overflow-x: auto; border: 3px solid var(--frame); background: #fff; border-radius: 2px; }
table.sheet { border-collapse: collapse; width: 100%; min-width: 760px; }
.sheet th { background: var(--head); color: var(--head-ink); padding: 10px 8px; font-weight: 600; font-size: .88rem; border: 1px solid #2f4778; text-align: center; white-space: nowrap; position: sticky; top: 0; }
.sheet th button { background: none; border: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
.sheet td { padding: 5px 8px; border: 1px solid var(--line); text-align: center; height: 36px; font-size: .92rem; }
.sheet td.l { text-align: left; }
.sheet tbody tr:hover td { background-color: #f3f6fc; }
.sheet tr.late td { background-color: var(--danger-soft); }
.sheet tr.late:hover td { background-color: #fbdcdc; }
.sheet td .link { background: none; border: 0; color: var(--accent); cursor: pointer; font-weight: 600; padding: 0; text-align: left; }
.sheet td .link:hover { text-decoration: underline; }
.cellrem { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.sheet .demo { font-size: .72rem; background: #ece3ff; color: #4b2a6b; padding: 1px 5px; border-radius: 3px; margin-left: 4px; }

/* ---- Tableau de bord ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--head); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .84rem; }
.stat.ok { border-left-color: var(--ok); } .stat.bad { border-left-color: var(--danger); } .stat.warn { border-left-color: #f1a33a; }
.boardtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 18px; }
.boardtile { display: block; background: #fff; border: 3px solid var(--frame); padding: 12px 14px; text-decoration: none; color: inherit; border-radius: 2px; }
.boardtile:hover { background: var(--accent-soft); }
.boardtile h3 { font-size: 1.3rem; }
.remgroup { margin-bottom: 14px; }
.remgroup h3 { padding: 6px 10px; border-radius: 4px; margin-bottom: 6px; font-size: .95rem; }
.remgroup.late h3 { background: var(--danger); color: #fff; }
.remgroup.today h3 { background: #f1a33a; color: #3d2400; }
.remgroup.soon h3 { background: var(--accent-soft); color: var(--accent); }
.remitem { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.remitem .grow { flex: 1; min-width: 200px; }
.remitem .link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---- Fenêtres ---- */
dialog { border: 0; border-radius: 8px; padding: 0; width: min(560px, 94vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(10, 20, 60, .4); }
dialog.wide { width: min(900px, 96vw); }
dialog::backdrop { background: rgba(15, 25, 60, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.dlg-body { padding: 16px 18px 18px; overflow: auto; max-height: calc(92vh - 62px); }
.x { background: none; border: 0; font-size: 1.4rem; cursor: pointer; line-height: 1; color: var(--muted); }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin-bottom: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 2px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
table.plain { border-collapse: collapse; width: 100%; }
.plain th, .plain td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: .9rem; vertical-align: middle; }
.plain th { color: var(--muted); font-weight: 600; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 4px; border: 1px solid #0003; vertical-align: middle; }
.logline { font-size: .86rem; color: var(--muted); }
code.k { background: #eef1f6; padding: 1px 5px; border-radius: 3px; }

/* ---- Messages ---- */
#toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1b2333; color: #fff; padding: 10px 14px; border-radius: var(--radius); max-width: 360px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.toast.err { background: var(--danger); }
.toast.notif { background: var(--frame); border-left: 5px solid #f2c94c; }
.login-wrap { max-width: 420px; margin: 7vh auto; }

@media (max-width: 760px) {
  .topbar-in { flex-wrap: wrap; padding-top: 6px; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { padding: 10px 12px 8px; }
  .search input { width: 140px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: pop .14s ease-out; }
  @keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
}
