:root {
  --bg: #f3f5f8; --card: #fff; --text: #1b2430; --muted: #6b7686; --line: #e2e7ee;
  --primary: #1f5fbf; --primary-d: #184c99; --nav: #14213d;
  --danger: #c62828; --ok: #1f8a4c; --warn: #b26a00;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { background: #eef1f5; padding: .1em .35em; border-radius: 4px; font-size: .9em; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.late { color: var(--danger); font-weight: 600; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar { background: var(--nav); color: #fff; display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1.25rem; min-height: 54px; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #dbe4f5; }
.brand { font-weight: 700; color: #fff !important; font-size: 1.05rem; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .45rem .8rem; border-radius: 7px; }
.topbar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.topbar nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.usermenu { display: flex; align-items: center; gap: .75rem; }
.usermenu form { margin: 0; }
.pill-alert { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; }

.container { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-actions, .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions { margin-top: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 2px rgba(20,33,61,.04); margin-bottom: 1rem; }
.narrow { max-width: 520px; }
.center-card { max-width: 520px; margin: 3rem auto; text-align: center; }

/* Boutons */
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text); padding: .5rem .95rem;
  border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdeeee; }
.btn-ghost { background: transparent; border-color: transparent; }
.topbar .btn-ghost { color: #dbe4f5; border-color: rgba(255,255,255,.25); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; color: #3a4658; }
input[type=text], input[type=tel], input[type=password], input[type=search], input[type=date],
input[type=datetime-local], select, textarea {
  font: inherit; padding: .55rem .65rem; border: 1px solid #c9d1dc; border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,95,191,.35); border-color: var(--primary); }
input[type=color] { width: 3.2rem; height: 2.2rem; padding: .1rem; border: 1px solid #c9d1dc; border-radius: 6px; background: #fff; }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: #f3f5f8; }
.row { display: flex; gap: .9rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }
.grow { flex: 2 1 240px !important; }
.grow2 { flex: 3 1 260px !important; }
.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .9rem; }
.field-error { color: var(--danger); font-size: .82rem; }
.section-title { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--line); }

.grid-form { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.side .card { margin-bottom: 1rem; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: .55rem 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.meta dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters .field { margin-bottom: 0; flex: 1 1 130px; max-width: 220px; }
.filters .field.grow2 { max-width: none; }
.filters .check { margin: 0 0 .55rem; }
.filters .actions { margin: 0 0 0 auto; }
.inline-add { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.inline-add .field { margin-bottom: 0; }

/* Messages */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; transition: opacity .6s; }
.flash.fade { opacity: 0; }
.flash-success { background: #e8f6ee; border-color: #b7e2c8; color: #14532d; }
.flash-error { background: #fdecec; border-color: #f4c2c2; color: #7f1d1d; }
.flash-warning, .flash-info { background: #eaf1fb; border-color: #c4d6f2; color: #1e3a6b; }

/* Tableaux */
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfd; }
tbody tr:hover { background: #fafcff; }
tr.inactive td { opacity: .55; }
table.compact td { padding: .45rem .6rem; }
td.reason { max-width: 320px; }
td.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
td input[type=text] { min-width: 180px; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* Badges */
.badge { white-space: nowrap; display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.st-new { background: #e3eefc; color: #17498f; }
.st-progress { background: #fff3d6; color: #8a5a00; }
.st-callback { background: #fde4d8; color: #a33b0a; }
.st-done { background: #e2f3e8; color: #17663a; }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 6px; font-size: .8rem; font-weight: 600;
  color: var(--tag, #4b5563); background: color-mix(in srgb, var(--tag, #4b5563) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--tag, #4b5563) 35%, #fff); }

/* Tableau de bord */
.segmented { display: inline-flex; background: #e6eaf0; border-radius: 9px; padding: 3px; }
.segmented a { padding: .35rem .8rem; border-radius: 7px; color: var(--text); font-size: .88rem; }
.segmented a:hover { text-decoration: none; background: rgba(255,255,255,.6); }
.segmented a.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; display: flex; flex-direction: column; }
.kpi-n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.kpi-l { color: var(--muted); font-size: .85rem; }
.kpi-alert { border-color: #f0b9a0; background: #fff6f1; }
.kpi-alert .kpi-n { color: #a33b0a; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.dash-grid .card { margin: 0; }
.span2 { grid-column: span 2; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
form.inline { display: inline; margin: .3rem 0 0; }
.hbar { display: grid; grid-template-columns: 12rem 1fr 2.2rem; gap: .6rem; align-items: center; margin: .35rem 0; font-size: .9rem; }
.hbar-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: #eef1f5; border-radius: 6px; height: .9rem; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--primary); border-radius: 6px; min-width: 3px; }
.hbar-n { text-align: right; font-weight: 600; }
.daychart { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 1.2rem; }
.daybar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; position: relative; }
.daybar-fill { display: block; width: 100%; max-width: 34px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .9; }
.daybar-n { font-size: .72rem; color: var(--muted); }
.daybar-l { font-size: .68rem; color: var(--muted); height: 1rem; white-space: nowrap; }

/* Connexion */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; padding: 1.75rem; }
.login-card h1 { margin-bottom: .25rem; }

@media (max-width: 900px) {
  .grid-form { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .filters .actions { margin-left: 0; }
  .hbar { grid-template-columns: 7rem 1fr 2rem; }
}
@media (max-width: 600px) {
  .container { padding: .8rem; }
  .topbar { padding: .5rem .8rem; gap: .5rem; }
}
