:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --border: #dfe3ea;
  --primary: #0b5cad;
  --primary-hover: #094a8c;
  --primary-soft: #e7f0fb;
  --danger: #c0352b;
  --ok-bg: #e7f6ec;
  --ok-text: #1d6b37;
  --err-bg: #fdecea;
  --err-text: #9b2a20;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
.muted { color: var(--muted); font-weight: 400; font-size: .9em; }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: #0f1b2b; color: #fff;
  padding: 0 20px; height: 56px;
  position: sticky; top: 0; z-index: 20;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 800;
}
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a, .usermenu a {
  color: #c7d1de; padding: 8px 12px; border-radius: 8px; white-space: nowrap;
}
.mainnav a:hover, .usermenu a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.mainnav a.active, .usermenu a.active { background: rgba(255,255,255,.14); color: #fff; }
.usermenu { display: flex; align-items: center; gap: 4px; }
.usermenu form { margin: 0; }
.usermenu .linkbtn { color: #c7d1de; padding: 8px 12px; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 22px; margin-left: auto; cursor: pointer; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 80px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card.narrow { max-width: 720px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.card-head h2 { margin: 0; }
.empty { color: var(--muted); margin: 6px 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* ---------- Formulaires ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label, .stack label { font-size: 12.5px; font-weight: 600; color: #3a4553; }
.field.check { justify-content: flex-end; }
.field.check label, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; cursor: pointer; }
.req { color: var(--danger); }
.hint { font-size: 12px; }

input, select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
input[type=checkbox] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; }
input:disabled { background: #f2f4f7; color: var(--muted); }

.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 10;
  background: rgba(244, 246, 249, .94); backdrop-filter: blur(4px);
  padding: 12px 0; display: flex; gap: 10px; border-top: 1px solid var(--border);
}

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }
.filters input[type=date] { width: auto; }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #f0c4c0; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.danger-text { color: var(--danger); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--err-bg); color: var(--danger); }
.danger-zone { margin-top: 8px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.table tbody tr:hover { background: #fafbfd; }
.table .num { text-align: right; }
.table .sub { color: var(--muted); font-size: 12px; }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions > * { margin-left: 10px; }
.table .actions form { display: inline; }

.rows-table { margin-bottom: 10px; }
.rows-table td { padding: 4px; border-bottom: 0; }
.rows-table input, .rows-table select { padding: 6px 7px; font-size: 13px; }
.rows-table input[type=number] { width: 72px; }
.rows-table input[type=time] { width: 104px; }
.rows-table input[type=date] { width: 140px; }
.rows-table tr.group th { text-align: center; color: var(--primary); border-bottom: 0; padding-bottom: 0; }
.rows-table tr.totals td { font-weight: 700; padding: 8px 6px; border-top: 1px solid var(--border); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.off { background: #eef0f3; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); color: var(--ok-text); border: 1px solid #bfe5cb; }
.flash.err { background: var(--err-bg); color: var(--err-text); border-color: #f3c6c1; }

/* ---------- Signature ---------- */
.sig-grid { margin-top: 14px; }
.sigpad { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.sigpad canvas {
  width: 100%; max-width: 560px; aspect-ratio: 560 / 180; height: auto;
  border: 1px dashed #b7c0cc; border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair;
}

/* ---------- Connexion ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0f1b2b, #163a63); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 22px; }
.auth-card h1 { margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 5px; }
.stack label.check { flex-direction: row; }
.stack .btn { padding: 11px; }

/* ---------- Mobile ---------- */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 10px 16px; gap: 8px; }
  .menu-btn { display: block; }
  .mainnav, .usermenu { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .nav-open .mainnav, .nav-open .usermenu { display: flex; }
  .container { padding: 16px 16px 80px; }
  .card { padding: 16px; }
}

@media print {
  .no-print { display: none !important; }
}
