:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1f2933; --muted: #616e7c; --line: #d9dee3;
  --primary: #1f5f8b; --primary-dark: #174a6d; --primary-soft: #e3eef7;
  --ok: #1e7f4f; --ok-soft: #e0f3e8; --warn: #b7791f; --warn-soft: #fbf0d9; --bad: #b42323; --bad-soft: #fbe3e3;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---- Layout ---- */
.topbar { background: var(--primary); color: #fff; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar .brand { font-weight: 700; font-size: 1.05rem; color: #fff; text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { color: #fff; text-decoration: none; padding: .3rem .6rem; border-radius: 6px; opacity: .9; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.18); opacity: 1; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .9; }
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.container.narrow { max-width: 520px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card.compact { padding: .75rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

/* ---- Tuiles d'accueil ---- */
.tile { display: block; text-decoration: none; color: inherit; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; position: relative; border: 1px solid transparent; }
.tile:hover { border-color: var(--primary); }
.tile .big { font-size: 2rem; font-weight: 700; color: var(--primary); }
.tile .badge { position: absolute; top: .75rem; right: .75rem; }

/* ---- Boutons ---- */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .8rem; border-radius: 6px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.sm { padding: .25rem .5rem; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; padding: .7rem; font-size: 1.05rem; }
.btn.icon { padding: .25rem .45rem; }

/* ---- Formulaires ---- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { font: inherit; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
input.sm { padding: .25rem .4rem; font-size: .9rem; }
input.w-num { width: 6.5rem; }
input.w-date { width: 10rem; }
textarea { min-height: 4.5rem; resize: vertical; }
.field { margin-bottom: .75rem; }
.field.inline { display: flex; align-items: center; gap: .5rem; }
.field.inline label { margin: 0; }
.form-grid { display: grid; gap: .5rem .75rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .75rem; margin: 0 0 .75rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; flex-wrap: wrap; }
.error { color: var(--bad); background: var(--bad-soft); padding: .5rem .75rem; border-radius: 6px; margin-bottom: .75rem; }
.success { color: var(--ok); background: var(--ok-soft); padding: .5rem .75rem; border-radius: 6px; margin-bottom: .75rem; }
.hint { font-size: .8rem; color: var(--muted); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--primary-soft); }
tr.archived td { color: var(--muted); text-decoration: line-through; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: .25rem; }
tr.locked { background: #fafbfc; }

/* ---- Badges, états ---- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--line); color: var(--text); }
.badge.critique, .badge.bad { background: var(--bad); color: #fff; }
.badge.attention, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.salarie { background: #ede9fe; color: #5b21b6; }
.pos { color: var(--ok); } .neg { color: var(--bad); } .warn-text { color: var(--warn); }
.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-list li { padding: .45rem .6rem; border-radius: 6px; margin-bottom: .35rem; border-left: 4px solid var(--warn); background: var(--warn-soft); }
.alert-list li.critique { border-left-color: var(--bad); background: var(--bad-soft); }

/* ---- Onglets ---- */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .8rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---- Métriques ---- */
.metrics { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; }
.metric .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.metric .value { font-size: 1.35rem; font-weight: 700; margin-top: .15rem; }
.metric .sub { font-size: .8rem; color: var(--muted); }

/* ---- Étapes clés ---- */
.etape { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; }
.etape-head { display: grid; grid-template-columns: 1.4fr repeat(3, minmax(120px, 1fr)) 100px auto; gap: .5rem; align-items: center; padding: .6rem .75rem; }
.etape-head strong { font-size: .95rem; }
.etape-body { border-top: 1px solid var(--line); padding: .6rem .75rem; background: #fafbfc; }
.pers-grid { display: grid; gap: .35rem .75rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.pers-row { display: flex; align-items: center; gap: .5rem; }
.pers-row label { margin: 0; flex: 1; color: var(--text); font-size: .9rem; }
.pers-row input[type=number] { width: 5.5rem; }

/* ---- Modal ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; z-index: 50; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 100%; max-width: 720px; padding: 1.2rem; }
.modal h2 { margin-bottom: 1rem; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: .6rem 1rem; border-radius: 6px; box-shadow: var(--shadow); z-index: 60; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* ---- Chronologie ---- */
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { padding: .3rem 0 .3rem 1rem; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: .75rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline li.etape::before { background: var(--warn); }
.timeline li.intervention_salarie::before { background: #5b21b6; }
.timeline .date { font-weight: 600; margin-right: .5rem; font-variant-numeric: tabular-nums; }

/* ---- Barres (trésorerie) ---- */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 140px; margin-top: .5rem; }
.bars .bar { background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar.histo { background: #9fb8cc; }
.bars-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; font-size: .75rem; color: var(--muted); text-align: center; }

/* ---- Page salarié (mobile) ---- */
.salarie-page { max-width: 560px; margin: 0 auto; padding: .75rem; }
.salarie-page input, .salarie-page select, .salarie-page textarea { font-size: 1.05rem; padding: .65rem .7rem; }
.salarie-page .field { margin-bottom: 1rem; }
.pause-row { display: grid; grid-template-columns: auto 1fr auto 1fr auto; gap: .4rem; align-items: center; margin-bottom: .5rem; }
.pause-row span { color: var(--muted); font-size: .9rem; }
.heures-net { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.saisie-item { border-top: 1px solid var(--line); padding: .6rem 0; }
.saisie-item .titre { font-weight: 600; }

@media (max-width: 700px) {
  html { font-size: 15px; }
  .container { padding: .6rem; }
  .card { padding: .75rem; }
  .etape-head { grid-template-columns: 1fr 1fr; }
  .topbar { padding: .5rem .7rem; }
  th, td { padding: .4rem .35rem; }
}
