@font-face { font-family: "Open Sans"; font-weight: 400; font-display: swap; src: url(fonts/open-sans-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Open Sans"; font-weight: 600; font-display: swap; src: url(fonts/open-sans-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Open Sans"; font-weight: 700; font-display: swap; src: url(fonts/open-sans-latin-700-normal.woff2) format("woff2"); }

/* Charte InterFacilities : jaune #FFCA05, anthracite #1D1D1E / #333 */
:root {
  --if-yellow: #ffca05;
  --if-yellow-2: #f5bd00;
  --if-yellow-soft: #fff6cc;
  --if-dark: #1d1d1e;
  --if-dark-2: #333333;
  --bg: #f5f5f4;
  --surface: #ffffff;
  --ink: #1b1f24;
  --ink-2: #5c6570;
  --ink-3: #8a929b;
  --line: #e3e6ea;
  --line-2: #eef0f2;
  --brand: var(--if-dark);
  --brand-2: var(--if-dark-2);
  --accent: var(--if-dark);
  --accent-soft: var(--if-yellow-soft);
  --good: #0a8a1f;
  --good-soft: #e6f5e9;
  --warn: #a86a00;
  --warn-soft: #fff4dc;
  --bad: #c0262d;
  --bad-soft: #fdeaea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Open Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--if-dark); text-decoration-color: var(--if-yellow); text-decoration-thickness: 2px; text-underline-offset: 2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  height: 60px; padding: 0 20px;
  background: #fff; color: var(--ink);
  border-bottom: 3px solid var(--if-yellow);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
header.top .logo { display: flex; align-items: center; gap: 12px; white-space: nowrap; text-decoration: none; color: var(--ink); }
header.top .logo img { height: 34px; width: auto; display: block; }
header.top .logo span { font-weight: 600; font-size: 13px; color: var(--ink-2); padding-left: 12px; border-left: 1px solid var(--line); text-transform: uppercase; letter-spacing: .8px; }
header.top nav { display: flex; gap: 2px; flex: 1; height: 100%; }
header.top nav a {
  display: flex; align-items: center; color: var(--ink-2); text-decoration: none; padding: 0 14px; font-weight: 600;
  border-bottom: 3px solid transparent; margin-bottom: -3px;
}
header.top nav a:hover { color: var(--ink); background: #fafaf8; }
header.top nav a.active { color: var(--ink); border-bottom-color: var(--if-dark); }
header.top .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
header.top .user .badge { background: var(--if-yellow); color: var(--if-dark); font-weight: 600; }
header.top .user button { background: #fff; border: 1px solid var(--line); color: var(--ink); padding: 5px 10px; border-radius: 6px; cursor: pointer; }
header.top .user button:hover { border-color: var(--if-dark); }

main { padding: 16px 20px 40px; max-width: 1800px; margin: 0 auto; }

/* ---------- Period bar ---------- */
.periodbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.periodbar select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.months { display: flex; gap: 4px; flex-wrap: wrap; }
.months button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; min-width: 58px; line-height: 1.2;
}
.months button small { font-size: 11px; color: var(--ink-3); }
.months button.active { background: var(--if-dark); border-color: var(--if-dark); color: #fff; box-shadow: inset 0 -3px 0 var(--if-yellow); }
.months button.active small { color: var(--if-yellow); }
.months button .lock { font-size: 10px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .grow { flex: 1; }
.toolbar input[type=search], .toolbar select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0;
}
.toolbar input[type=search] { width: 260px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c8cdd3; background: #fafbfc; }
.btn.primary { background: var(--if-yellow); border-color: var(--if-yellow); color: var(--if-dark); font-weight: 600; }
.btn.primary:hover { background: var(--if-yellow-2); border-color: var(--if-yellow-2); }
.btn.danger { color: var(--bad); border-color: #f0c4c6; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.summary { display: flex; gap: 18px; color: var(--ink-2); font-size: 13px; margin: 0 0 8px 2px; flex-wrap: wrap; }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; }
.banner { padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; }
.banner.warn { background: var(--warn-soft); color: #6b4500; border: 1px solid #f3dca5; }

/* ---------- Table ---------- */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 250px); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.grid th {
  position: sticky; top: 0; z-index: 2; background: #f8f9fa; text-align: left; font-weight: 600; color: var(--ink-2);
  padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; font-size: 12px;
}
table.grid th.sorted { color: var(--ink); }
table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { background: #fffbea; }
table.grid tbody tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #ffe98a; } to { background: transparent; } }
td.desc { max-width: 380px; min-width: 220px; white-space: normal; }
td.client { min-width: 160px; font-weight: 500; }
td.clip { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.stat select { padding: 2px 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--ink-2); }

.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--if-yellow-soft); color: #6b5300; }
.tag-type { font-size: 12px; }
.calc { color: var(--ink-3); font-size: 10px; margin-left: 2px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 880px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.narrow { max-width: 460px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 16px; }
.modal .body { padding: 16px 20px; }
.modal footer { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 10px 10px; }
.modal footer .grow { flex: 1; }
.close { border: none; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-2); }

fieldset { border: none; padding: 0; margin: 0 0 14px; }
fieldset legend { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); margin-bottom: 8px; padding: 0; }
.fgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; }
.fgrid .s2 { grid-column: span 2; }
.fgrid .s3 { grid-column: span 3; }
.fgrid .s4 { grid-column: span 4; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 3px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #d5d9de; border-radius: 6px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--if-yellow); outline-offset: 0; border-color: var(--if-dark); }
:focus-visible { outline: 2px solid var(--if-yellow); outline-offset: 1px; }
.field input[readonly] { background: #f6f7f8; }
.field .hint { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.field.check label { display: flex; align-items: center; gap: 6px; margin-top: 22px; }
.field.check input { width: auto; }
textarea { resize: vertical; min-height: 60px; }
.error { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.conflict { background: var(--warn-soft); border: 1px solid #f3dca5; padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.conflict .actions { margin-top: 8px; display: flex; gap: 8px; }
.meta { font-size: 12px; color: var(--ink-3); }

/* ---------- Cards / report ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--if-yellow); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: 12px; color: var(--ink-2); }
.kpi .val { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card h3 { margin: 0; font-size: 14px; border-left: 3px solid var(--if-yellow); padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.card .inner { padding: 12px 14px; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 6px 14px; background: #f8f9fa; border-bottom: 1px solid var(--line); }
.card table td { padding: 6px 14px; border-bottom: 1px solid var(--line-2); }
.card table tr:last-child td { border-bottom: none; }
.card table tfoot td { font-weight: 600; border-top: 1px solid var(--line); background: #fafbfc; }
.card .scroll { max-height: 340px; overflow: auto; }
.bar-cell { position: relative; }
.minibar { height: 6px; background: var(--if-yellow); border-radius: 0 3px 3px 0; margin-top: 3px; opacity: .85; }
.card.wide { grid-column: 1 / -1; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .tip { position: absolute; pointer-events: none; background: #1b1f24; color: #fff; padding: 6px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; }
.chart .tip.on { opacity: 1; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--if-yellow); font-weight: 600; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.inline-form { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); background: #fafbfc; flex-wrap: wrap; }
.inline-form input, .inline-form select { padding: 6px 8px; border: 1px solid #d5d9de; border-radius: 6px; flex: 1; min-width: 100px; }
.card table td .btn { padding: 3px 8px; font-size: 12px; }
tr.inactive td { color: var(--ink-3); text-decoration: line-through; }
tr.inactive td:last-child { text-decoration: none; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--if-dark); position: relative; overflow: hidden; }
.login::before { content: ""; position: absolute; width: 720px; height: 720px; border-radius: 50%; background: var(--if-yellow); right: -260px; bottom: -320px; opacity: .95; }
.login form { position: relative; background: #fff; padding: 34px 32px 30px; border-radius: 12px; width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.35); border-top: 4px solid var(--if-yellow); }
.login .login-logo { display: block; width: 240px; height: auto; margin: 0 auto 18px; }
.login h1 { margin: 0 0 2px; font-size: 18px; text-align: center; }
.login p { margin: 0 0 22px; color: var(--ink-2); text-align: center; font-size: 13px; }
.login .field { margin-bottom: 12px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--if-dark); border-left: 4px solid var(--if-yellow); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.err { background: var(--bad); border-left-color: #fff; }

@media (max-width: 900px) {
  .fgrid { grid-template-columns: repeat(2, 1fr); }
  .fgrid .s3, .fgrid .s4 { grid-column: span 2; }
  .cards { grid-template-columns: 1fr; }
  header.top { gap: 10px; }
  header.top .logo span { display: none; }
  header.top .logo img { height: 26px; }
}

@media print {
  header.top, .periodbar, .toolbar, .noprint, #toasts { display: none !important; }
  body, :root { background: #fff; }
  main { padding: 0; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .card .scroll { max-height: none; }
  .cards { grid-template-columns: 1fr 1fr; }
}
.print-only { display: none; }
@media print { .print-only { display: flex; align-items: center; justify-content: space-between; font-size: 18px; margin: 0 0 14px; padding-bottom: 10px; border-bottom: 3px solid var(--if-yellow); } .print-only img { height: 36px; } }
.banner.bad-banner { background: var(--bad-soft); color: #8a1c21; border: 1px solid #f0c4c6; margin: 12px 20px 0; }
#alerte-admin:empty { display: none; }
