/* Suivi sous-traitance — feuille de style */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1b2533;
  --ink-2: #5b6778;
  --line: #dde3ea;
  --line-2: #eef1f5;
  --primary: #1f4e79;
  --primary-ink: #ffffff;
  --primary-soft: #e6eef7;
  --accent: #0f7b8a;
  --ok: #1e7a46;
  --ok-soft: #e3f4ea;
  --ko: #b42318;
  --ko-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --info: #1f4e79;
  --info-soft: #e6eef7;
  --ref: #fff7d6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; font-weight: 650; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h1 small { font-size: .85rem; font-weight: 400; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 650; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar { background: #16324f; color: #fff; display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; height: 56px; position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; }
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: .95rem; line-height: 1.1; }
.brand small { display: block; font-size: .75rem; opacity: .75; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .85rem; letter-spacing: .03em; }
.brand-lg { color: var(--ink); margin-bottom: 1.25rem; }
.brand-lg small { color: var(--ink-2); opacity: 1; }
.brand-lg .brand-mark { color: #fff; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a { color: #cfdbe8; padding: .45rem .75rem; border-radius: 6px; font-size: .92rem; }
.mainnav a:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.mainnav a.active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 1rem; font-size: .88rem; }
.usermenu a { color: #e5edf5; }
.usermenu small { opacity: .7; margin-left: .25rem; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

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

/* Cartes et grilles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.card.narrow { max-width: 760px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 > * { min-width: 0; }
.card { overflow-x: auto; }
.kpis > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .grid-2, .grid-2 + .form-actions { margin-top: 1rem; }

/* Boutons */
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .5rem .9rem; border-radius: 6px; font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f8fa; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-primary:hover { background: #193f62; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-danger-ghost { background: transparent; border-color: #f1c1bb; color: var(--ko); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; justify-content: center; margin-top: .5rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.linkbtn.danger { color: var(--ko); }
.icon-btn { background: none; border: 0; color: #9aa5b4; cursor: pointer; font-size: 1rem; padding: .25rem .4rem; border-radius: 4px; }
.icon-btn:hover { color: var(--ko); background: var(--ko-soft); }
form.inline { display: inline; }

/* Formulaires */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--ink-2); font-weight: 500; }
label > span { color: var(--ink-2); }
input, select, textarea { font: inherit; font-size: .95rem; color: var(--ink); background: #fff; border: 1px solid #c9d2dd; border-radius: 6px; padding: .45rem .6rem; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 78, 121, .25); border-color: var(--primary); }
input[readonly] { background: #f5f7f9; color: var(--ink-2); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.short { max-width: 140px; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); font-weight: 400; }
label.check input { width: auto; }
label.check.block { align-items: flex-start; padding: .6rem 0; border-bottom: 1px solid var(--line-2); }
label.check.block input { margin-top: .2rem; }
.req { color: var(--ko); font-weight: 600; }
.hint { color: var(--ink-2); font-weight: 400; font-size: .78rem; }
.has-error input, .has-error select { border-color: var(--ko); }
small.err { color: var(--ko); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.form-grid .full, .form-grid .span-4 { grid-column: 1 / -1; }
.span-2 { grid-column: span 2; }
.form-grid h3 { margin: 0; grid-column: 1 / -1; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .5rem; }
.form-inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.form-inline select { width: auto; }
.form-inline .motif-wrap { min-width: 220px; flex: 1; }

/* Filtres */
.filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.filters label { min-width: 150px; }
.filters label.grow { flex: 1; min-width: 260px; }
.filters label.check { min-width: 0; padding-bottom: .5rem; }
.filters-actions { display: flex; gap: .4rem; }
.table-filter { max-width: 320px; margin-bottom: .75rem; }

/* Onglets */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); font-weight: 600; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.grp { text-align: center; border-bottom: 1px solid var(--line); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table-click tbody tr[data-href] { cursor: pointer; }
.table.compact th, .table.compact td { padding: .35rem .5rem; }
.table.kv th { text-transform: none; font-size: .9rem; letter-spacing: 0; background: none; color: var(--ink); font-weight: 500; border-bottom: 1px solid var(--line-2); }
.table td.ref, .table input.q-ref { background: var(--ref); }
.table td.ok { color: var(--ok); font-weight: 600; }
.table td.ko { color: var(--ko); font-weight: 600; }
.table .empty, p.empty { color: var(--ink-2); text-align: center; padding: 1.5rem; font-style: italic; }
.row-late td:first-child { box-shadow: inset 3px 0 0 var(--ko); }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell form { display: inline; margin-left: .75rem; }
.late { color: var(--ko); font-weight: 600; }
.pager { display: flex; gap: .25rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.pager a { padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 4px; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Grille de saisie (BL) */
.table.grid td { padding: .3rem .3rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table.grid input { padding: .35rem .45rem; font-size: .9rem; }
.table.grid .col-art { min-width: 210px; }
.table.grid td:nth-child(2) { min-width: 170px; }
.table.grid td:nth-child(3), .table.grid td:nth-child(4) { min-width: 150px; }
.table.grid td:nth-child(5) { min-width: 110px; }
.table.grid td:nth-child(6) { width: 80px; }
.table.grid td:nth-child(7), .table.grid td:nth-child(8) { width: 110px; }
#rec-lines td input { min-width: 90px; }
.qte-input { display: flex; align-items: center; gap: .35rem; }
.qte-input span { color: var(--ink-2); font-size: .85rem; }
.table.grid input:disabled { background: #eef1f4; border-color: #e1e6ec; }
.l-unite { color: var(--ink-2); font-size: .85rem; text-align: center; }
.totaux { text-align: right; color: var(--ink-2); margin-top: .5rem; font-variant-numeric: tabular-nums; }
.bl-head { background: #fbfcfe; }

/* Autocomplétion */
.ac { position: relative; display: block; width: 100%; }
.ac-input { padding-right: 1.6rem; background-image: linear-gradient(45deg, transparent 50%, #8b97a6 50%), linear-gradient(135deg, #8b97a6 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.ac-invalid .ac-input { border-color: var(--ko); background-color: var(--ko-soft); }
.ac-list { position: absolute; z-index: 50; left: 0; top: calc(100% + 2px); min-width: 100%; width: max-content; max-width: 420px; max-height: 300px; overflow-y: auto; margin: 0; padding: .25rem 0; list-style: none; background: #fff; border: 1px solid #c9d2dd; border-radius: 6px; box-shadow: 0 8px 24px rgba(16, 24, 40, .15); }
.ac-list li { padding: .45rem .75rem; cursor: pointer; color: var(--ink); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-list li.active { background: var(--primary-soft); }
.ac-list li mark { background: none; color: var(--primary); font-weight: 700; }
.ac-list li.ac-create { color: var(--accent); border-top: 1px solid var(--line-2); font-weight: 500; }
.ac-list li.ac-create.active { background: #e2f3f5; }
.ac-list li.ac-empty { color: var(--ink-2); font-style: italic; cursor: default; }

/* Fenêtre (création rapide) */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 36, .45); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal-box { background: #fff; border-radius: 10px; width: 100%; max-width: 460px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--ink-2); }
.modal-body { padding: 1.1rem; }
.similaires { background: var(--warn-soft); border: 1px solid #f3d38c; border-radius: 6px; padding: .75rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.similaires p { margin: 0 0 .25rem; width: 100%; color: var(--warn); }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #16324f; color: #fff; padding: .6rem 1.1rem; border-radius: 6px; box-shadow: var(--shadow); z-index: 200; transition: opacity .4s; }
.toast.out { opacity: 0; }

/* Badges et classes */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-ko { background: var(--ko-soft); color: var(--ko); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef1f4; color: var(--ink-2); }
h1 .badge { font-size: .8rem; }
.classe { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; font-weight: 700; font-size: .9rem; }
.classe-a { background: var(--ok-soft); color: var(--ok); }
.classe-b { background: var(--warn-soft); color: var(--warn); }
.classe-c { background: var(--ko-soft); color: var(--ko); }
.classe-nc { background: #eef1f4; color: var(--ink-2); font-size: .7rem; }

/* Alertes */
.alert { padding: .7rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: .35rem 0 0 1.1rem; padding: 0; }
.alert-success { background: var(--ok-soft); color: #14532d; border-color: #b7e2c6; }
.alert-error { background: var(--ko-soft); color: #7a1a12; border-color: #f4c1bb; }
.alert-warn { background: var(--warn-soft); color: #6b4300; border-color: #f3d38c; }
.alert-info { background: var(--info-soft); color: #173a5c; border-color: #c4d6ea; }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 1rem 0 .5rem; }
.kpis-4 { margin-top: 0; }
.kpi { display: flex; flex-direction: column; gap: .15rem; color: var(--ink); }
a.kpi:hover { text-decoration: none; border-color: var(--primary); }
.kpi span { font-size: .8rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi strong { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi strong small { font-size: .9rem; color: var(--ink-2); font-weight: 500; }
.kpi small { color: var(--ink-2); font-size: .82rem; }
.st-head .kpis .kpi { background: #f8fafc; border: 1px solid var(--line-2); border-radius: 8px; padding: .75rem .9rem; }
.kpi-alert { border-color: #f4c1bb; }
.kpi-alert strong { color: var(--ko); }
.st-info { display: grid; grid-template-columns: repeat(6, 1fr); gap: .75rem 1rem; }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: .45rem 1rem; margin: 0; }
.dl dt { color: var(--ink-2); font-size: .88rem; }
.dl dd { margin: 0; }
.jug-line { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 1rem; padding: .75rem; background: #f8fafc; border-radius: 8px; margin-bottom: .75rem; }
details.change summary { cursor: pointer; color: var(--primary); font-size: .9rem; margin-bottom: .25rem; }
.jugement-card .btn-group { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line-2); }
.delai-info { background: #f8fafc; border-radius: 8px; padding: .75rem; margin: 0 0 .75rem; }
.qte-preview { margin-top: .75rem; }
.roles { margin-top: 1.5rem; }

/* Graphe */
.chart { margin: 0; }
.chart figcaption { display: flex; gap: 1.25rem; font-size: .85rem; color: var(--ink-2); margin-bottom: .5rem; }
.chart svg { width: 100%; height: auto; max-height: 320px; display: block; }
.legend { display: inline-flex; align-items: center; gap: .4rem; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.sw-delai { background: var(--primary); }
.sw-qte { background: #d97706; }
.grid-line { stroke: #e7ebf0; stroke-width: 1; }
.axis { font-size: 11px; fill: #6b7787; }
.axis-sm { font-size: 9.5px; }
.line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.line-delai { stroke: var(--primary); }
.line-qte { stroke: #d97706; }
.dot-delai { fill: var(--primary); }
.dot-qte { fill: #d97706; }

/* Connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #16324f, #1f4e79 60%, #0f7b8a); }
.login-box { background: #fff; border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); display: flex; flex-direction: column; gap: .85rem; }
.login-box h1 { font-size: 1.3rem; }

/* Écrans étroits (tablette, téléphone) */
@media (max-width: 1100px) {
  .form-grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .st-info { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: .6rem 1rem; gap: .5rem; }
  .nav-toggle { display: block; margin-left: auto; }
  .mainnav, .usermenu { display: none; width: 100%; flex-direction: column; }
  .nav-open .mainnav, .nav-open .usermenu { display: flex; }
  .usermenu { align-items: flex-start; padding-bottom: .5rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .jug-line { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: .1rem; }
  .dl dd { margin-bottom: .5rem; }
}
@media (max-width: 600px) {
  .page { padding: .75rem; }
  .form-grid, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .st-info, .kpis { grid-template-columns: 1fr; }
}

/* Impression des pages (fiche sous-traitant…) */
@media print {
  .topbar, .btn, .btn-group, .filters, .tabs, .form-actions, .table-filter { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .page { max-width: none; padding: 0; }
}
