:root {
  --bg: #f3f5f9; --card: #fff; --text: #1d2433; --muted: #6b7489; --line: #e3e7ef;
  --brand: #0f4c81; --brand-2: #1767ad; --side: #0d2741; --side-text: #c6d3e3;
  --ok: #157f3b; --warn: #b36b00; --danger: #b42318; --info: #1d5fa8;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }

.layout { display: flex; min-height: 100vh; background: linear-gradient(to right, var(--side) 240px, var(--bg) 240px); }
.sidebar { width: 240px; background: var(--side); color: var(--side-text); flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 18px 18px 12px; color: #fff; font-weight: 700; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand small { display: block; font-weight: 400; color: var(--side-text); font-size: 12px; margin-top: 2px; }
.sidebar nav { padding: 8px 0; flex: 1; }
.sidebar .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f95ad; padding: 14px 18px 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 8px 18px; font-size: 14px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand-2); color: #fff; }
.sidebar .me { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar .me b { color: #fff; display: block; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: 12px; background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 28px; position: sticky; top: 0; z-index: 40; }
.topbar #nav-toggle, .topbar > b { display: none; }
.topbar .who { color: var(--text); font-weight: 600; font-size: 13.5px; }
.topbar .who small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.topbar .logout { color: var(--danger); border-color: #f1c4c0; font-weight: 600; }
.topbar .logout:hover { background: #fdf0ef; }
.sidebar .me-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sidebar .side-btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
.sidebar .side-btn:hover { background: rgba(255,255,255,.16); }
.sidebar-foot { padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.copyright { font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.copyright .cp-line { margin-bottom: 8px; }
.copyright .cp-line span { font-size: 11px; opacity: .85; }
.copyright .cp-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.copyright .cp-links a { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: #f7f9fc; color: var(--brand-2); font-size: 11.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.copyright .cp-links a:hover { background: #eef3fa; text-decoration: none; }
.copyright svg { width: 13px; height: 13px; flex-shrink: 0; }
.sidebar-foot .copyright { margin: 0; padding: 0; border: 0; color: #7f95ad; font-size: 11px; }
.sidebar-foot .copyright a { color: var(--side-text); }
.sidebar-foot .copyright .cp-links { flex-direction: column; align-items: stretch; gap: 4px; }
.sidebar-foot .copyright .cp-links a { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.1); font-size: 11px; justify-content: flex-start; }
.sidebar-foot .copyright .cp-links a:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-foot .copyright a { color: var(--side-text); }
.copyright { font-size: 11.5px; line-height: 1.6; color: var(--muted); text-align: center; margin-top: 18px; word-break: break-word; }
.content { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card.tight { padding: 0; overflow: hidden; }
.card.tight > h2 { padding: 14px 16px 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.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)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12.5px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f8f9fc; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
tbody tr:hover { background: #fafbfe; }
tfoot td { font-weight: 700; background: #f8f9fc; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit; white-space: nowrap; }
.btn:hover { background: #f4f6fa; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c4c0; }
.btn.danger:hover { background: #fdf0ef; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--brand-2); padding: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 600; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.nav-backdrop { display: none; }
#install-app { display: none; align-items: center; gap: 8px; margin: 0 12px 10px; padding: 9px 12px; border-radius: 8px; background: rgba(255,255,255,.08); color: #fff; font-size: 13.5px; }
.install-banner { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid #c4dbf3; border-left: 4px solid var(--brand-2); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; box-shadow: 0 4px 14px rgba(15, 76, 129, .08); }
.install-banner[hidden], .install-banner [hidden] { display: none !important; }
.install-banner img { border-radius: 10px; flex-shrink: 0; }
.install-banner .txt { flex: 1; min-width: 0; font-size: 13.5px; }
.install-banner .txt > b { display: block; font-size: 14.5px; margin-bottom: 2px; }
.install-banner .acts { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 640px) { .install-banner { flex-wrap: wrap; } .install-banner .acts { width: 100%; } .install-banner .acts .btn { flex: 1; justify-content: center; } }
#install-app:hover { background: rgba(255,255,255,.14); text-decoration: none; }

form.inline { display: inline; }
label { display: block; font-size: 13px; font-weight: 600; color: #3a4357; margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #cdd4e0; border-radius: 7px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8d4f1; border-color: var(--brand-2); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 6px 0 0; }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.check { display: flex; align-items: center; font-weight: 400; margin-bottom: 6px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 12px; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.search { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search input, .search select { width: auto; flex: 1; min-width: 160px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.success { background: #ecf8f0; border-color: #b7e2c4; color: #135c2d; }
.flash.error { background: #fdf0ef; border-color: #f3c4bf; color: #8c1d13; }
.flash.info { background: #eef5fd; border-color: #c4dbf3; color: #1d4d82; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f5; color: #3a4357; white-space: nowrap; }
.badge.gray { background: #eceff4; color: #4a5468; }
.badge.blue { background: #e3effc; color: #1b56a0; }
.badge.purple { background: #efe8fb; color: #5b33a6; }
.badge.teal { background: #def5f2; color: #0e6b62; }
.badge.amber { background: #fdf1d8; color: #8a5300; }
.badge.orange { background: #fde7da; color: #9a3d0a; }
.badge.green { background: #e1f5e7; color: #146c34; }
.badge.dark { background: #2b3446; color: #fff; }
.badge.red { background: #fde4e1; color: #a5221a; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; }
.mb0 { margin-bottom: 0; }
.big { font-size: 20px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.pre { white-space: pre-line; }

/* Circuit de l'ordre */
.steps { display: flex; flex-wrap: wrap; gap: 0; margin: 4px 0 6px; }
.steps .st { flex: 1; min-width: 92px; text-align: center; font-size: 12px; color: var(--muted); position: relative; padding-top: 22px; }
.steps .st::before { content: ""; position: absolute; top: 6px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #d5dbe6; z-index: 1; }
.steps .st::after { content: ""; position: absolute; top: 12px; left: -50%; width: 100%; height: 2px; background: #d5dbe6; }
.steps .st:first-child::after { display: none; }
.steps .st.done::before, .steps .st.done::after { background: var(--ok); }
.steps .st.current::before { background: var(--brand-2); box-shadow: 0 0 0 4px #cfe2f7; }
.steps .st.current { color: var(--text); font-weight: 700; }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board .col { background: #e9edf4; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board .col h3 { display: flex; justify-content: space-between; font-size: 13px; }
.board .ticket { display: block; background: #fff; border-radius: 8px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.board .ticket:hover { border-color: var(--brand-2); text-decoration: none; }

.bars { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bars .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .in { background: var(--brand-2); width: 40%; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .out { background: #e8a33c; width: 40%; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .lbl { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

.lines input, .lines select { padding: 6px 8px; font-size: 13.5px; }
.lines td { padding: 6px; }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #0d2741, #1767ad); }
.auth-card { background: #fff; border-radius: 14px; padding: 30px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; width: 250px; }
  body.nav-open .sidebar { left: 0; }
  .topbar { justify-content: flex-start; gap: 10px; background: var(--side); color: #fff; border-bottom: 0; padding: 10px 16px; }
  .topbar #nav-toggle, .topbar > b { display: block; }
  .topbar .who { display: none; }
  .topbar .logout { background: none; color: #fff; border: 1px solid rgba(255,255,255,.45); font-size: 13px; padding: 5px 10px; }
  .topbar .logout:hover { background: rgba(255,255,255,.1); }
  .topbar #nav-toggle { background: none; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 18px; }
  .content { padding: 16px; }
  .layout { background: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(13, 39, 65, .45); z-index: 45; }
  body.nav-open { overflow: hidden; }
  .board { grid-auto-flow: row; grid-template-columns: 1fr; overflow: visible; }
  .board .col { min-height: 0; }
  .board .col h3 { margin: 0; }
  .board .col .ticket:first-of-type { margin-top: 8px; }
  .topbar b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .v { font-size: 18px; }
  .kv { grid-template-columns: 120px 1fr; }
}

@media (max-width: 640px) {
  /* champs à 16px : évite le zoom automatique sur iPhone */
  input, select, textarea { font-size: 16px; }
  .steps { display: grid; grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
  .steps .st { min-width: 0; }
  .steps .st:nth-child(3n+1)::after { display: none; }
  .status-acts > form, .status-acts .status-change { width: 100%; margin-left: 0 !important; }
  .status-acts .btn { width: 100%; justify-content: center; }
  .status-change select, .status-change input { width: 100% !important; flex: 1 1 100%; }
  h1 { font-size: 19px; }
  .card { padding: 14px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; justify-content: center; }
  .search input, .search select { min-width: 0; flex: 1 1 140px; }
  .search input[type=date] { flex: 1 1 130px !important; }
  .search label { flex: 0 0 auto; }
  .kv { grid-template-columns: 1fr; gap: 0 12px; }
  .kv dd { margin-bottom: 6px; }
  .bars { gap: 6px; }
  /* tableaux en fiches empilées (classe ajoutée par app.js) */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot, table.stack tr { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { display: flow-root; border: 0; padding: 3px 14px; text-align: right; }
  table.stack td::before { content: attr(data-label); float: left; width: 40%; padding-right: 8px; padding-top: 2px; color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; text-align: left; }
  table.stack td.blank { display: none; }
  table.stack td:not([data-label]), table.stack td[data-label=""] { text-align: left; }
  table.stack td:not([data-label])::before, table.stack td[data-label=""]::before { content: none; }
  table.stack td form, table.stack td .btn { display: inline-flex; }
  table.stack td.nowrap { white-space: normal; }
  table.stack td form + form, table.stack td .btn + form { margin-left: 4px; }
  table.stack td:first-child { font-size: 15px; }
  table.stack td[colspan] { text-align: left; }
  table.stack tfoot tr { background: #f8f9fc; }
}
