:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17211f;
  --ink-2: #4a5a56;
  --muted: #7a8985;
  --line: #e2e8e6;
  --brand: #0d7a6f;
  --brand-ink: #075e55;
  --brand-soft: #e3f3f0;
  --side: #10302c;
  --side-2: #1a443f;
  --red: #c2352b; --red-soft: #fdeceb;
  --amber: #b86e00; --amber-soft: #fff4e0;
  --blue: #1f63b5; --blue-soft: #e7f0fb;
  --green: #1f7a3d; --green-soft: #e5f5ea;
  --violet: #6a42b8; --violet-soft: #efe9fb;
  --grey-soft: #eef1f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 48, 44, .06), 0 4px 16px rgba(16, 48, 44, .05);
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #10302c 0%, #0d7a6f 100%); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin-top: 6px; }
.login-card p { margin: -8px 0 6px; }

/* ---------- Structure ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 270px; flex-shrink: 0; background: var(--side); color: #cfe2de; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; color: #fff; }
.brand small { display: block; color: #9cc0b9; font-size: .78rem; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; flex-shrink: 0; }
.brand-mark.big { width: 52px; height: 52px; font-size: 32px; border-radius: 12px; }
nav { padding: 4px 10px 20px; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7fa59e; padding: 14px 10px 6px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #d6e7e3; font-size: .93rem; }
nav a:hover { background: var(--side-2); text-decoration: none; }
nav a.active { background: var(--brand); color: #fff; }
nav a .ico { width: 18px; text-align: center; opacity: .9; }
nav a .count { margin-left: auto; background: #c2352b; color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 58px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 22px; position: sticky; top: 0; z-index: 20; }
.crumb { color: var(--muted); flex: 1; }
.menu-toggle { display: none; }
.user-box { position: relative; }
.user-btn { display: flex; gap: 10px; align-items: center; background: none; border: 0; cursor: pointer; text-align: left; padding: 4px 8px; border-radius: 8px; font: inherit; color: inherit; }
.user-btn:hover { background: var(--grey-soft); }
.user-btn small { display: block; color: var(--muted); font-size: .78rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
.user-menu { position: absolute; right: 0; top: 46px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 190px; padding: 6px; display: flex; flex-direction: column; }
.user-menu a, .user-menu button { padding: 8px 10px; border-radius: 6px; text-align: left; background: none; border: 0; font: inherit; color: var(--ink); cursor: pointer; }
.user-menu a:hover, .user-menu button:hover { background: var(--grey-soft); text-decoration: none; }
.view { padding: 28px 32px; width: 100%; }

/* ---------- Composants ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5d0cd; background: #fafcfb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--red); border-color: #f0c6c2; }
.btn.danger:hover { background: var(--red-soft); }
.btn.warn { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 6px; color: var(--ink-2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 550; }
.kpi .value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--ink-2); font-size: .82rem; }
.kpi.alert .value { color: var(--red); }
.kpi.ok .value { color: var(--green); }
.kpi a.stretch::after { content: ""; position: absolute; inset: 0; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.toolbar select { max-width: 220px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: .85rem; }

input, select, textarea { font: inherit; color: var(--ink); border: 1px solid #cfd8d5; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(13,122,111,.25); border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: .88rem; color: var(--ink-2); }
label .req { color: var(--red); }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.error-msg { color: var(--red); font-size: .88rem; min-height: 1em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; background: #fafbfb; position: sticky; top: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f5faf9; }
tr.row-alert td { background: #fff8f7; }
td.empty { text-align: center; color: var(--muted); padding: 30px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: var(--ink-2); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-green { background: var(--green-soft); color: var(--green); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-grey { background: var(--grey-soft); color: var(--ink-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 10px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list-plain li:last-child { border-bottom: 0; }
.list-plain li.empty { color: var(--muted); justify-content: center; }

.dl { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .86rem; }
.dl dd { margin: 0; font-weight: 500; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { background: none; border: 0; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* Barres */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding: 10px 4px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-stack { width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.bar-stack span { display: block; }
.bar-col small { color: var(--muted); font-size: .72rem; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--ink-2); }
.hbar { display: grid; grid-template-columns: 170px 1fr 70px; gap: 10px; align-items: center; padding: 5px 0; font-size: .88rem; }
.hbar .track { background: var(--grey-soft); border-radius: 4px; height: 12px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--brand); border-radius: 4px; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.meter { height: 8px; background: var(--grey-soft); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--green); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 18px 10px; }
.timeline li { position: relative; padding: 10px 0 10px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline li.sys::before { background: #b9c6c3; }
.timeline .meta { color: var(--muted); font-size: .8rem; }

/* Calendrier */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { padding: 8px; font-size: .75rem; text-transform: uppercase; color: var(--muted); background: #fafbfb; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-weight: 650; }
.cal .day { min-height: 112px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; }
.cal .day.out { background: #fafbfb; color: #b5c0bd; }
.cal .day.today { background: #f0faf8; }
.cal .day .d { font-size: .8rem; font-weight: 650; }
.cal .ev { font-size: .74rem; padding: 2px 6px; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }

/* Modale */
.modal-back { position: fixed; inset: 0; background: rgba(16, 30, 28, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 760px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal.sm { max-width: 480px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfb; border-radius: 0 0 14px 14px; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--side); color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow); max-width: 380px; animation: pop .2s ease-out; }
.toast.err { background: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.notice { padding: 12px 16px; border-radius: 9px; background: var(--amber-soft); color: #7a4a00; margin-bottom: 16px; }
.notice.info { background: var(--blue-soft); color: #174a87; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.label-print { border: 2px solid var(--ink); border-radius: 8px; padding: 14px; width: 320px; font-family: Consolas, monospace; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-toggle { display: block; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .view { padding: 14px; }
  .dl { grid-template-columns: 1fr; }
  .user-btn span:last-child { display: none; }
}

@media print {
  .sidebar, .topbar, .actions, .toolbar, .tabs, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  .view { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
