/* KSDE — charte : bleu roi #0070C0 et blanc (+ gris neutres) */
:root {
  --blue: #0070C0;
  --blue-dark: #00548F;
  --blue-deep: #003A63;
  --blue-50: #EEF5FB;
  --blue-100: #D9E9F6;
  --blue-200: #B3D3ED;
  --ink: #15212D;
  --ink-2: #4A5866;
  --ink-3: #7D8995;
  --line: #DFE6ED;
  --bg: #F5F8FB;
  --card: #FFFFFF;
  --danger: #B42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 40, 80, .06), 0 2px 8px rgba(0, 40, 80, .05);
  --sidebar: 232px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--blue); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 10px 40px rgba(0, 30, 60, .25); }
.login-card h1 { font-size: 20px; margin: 14px 0 18px; color: var(--blue-deep); }
.login-card label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
.login-card input { margin-top: 4px; }
.brand-mark { display: inline-grid; place-items: center; background: #fff; color: var(--blue); font-weight: 800; letter-spacing: .5px; border-radius: 8px; padding: 4px 8px; font-size: 13px; }
.brand-mark.big { background: var(--blue); color: #fff; font-size: 18px; padding: 8px 12px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--blue); color: #fff; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; padding: 18px 12px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-text { font-weight: 700; font-size: 16px; }
#nav a { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; padding: 10px 12px; border-radius: 8px; opacity: .88; font-size: 14.5px; }
#nav a:hover { background: rgba(255, 255, 255, .1); opacity: 1; }
#nav a.active { background: #fff; color: var(--blue); opacity: 1; font-weight: 600; }
#nav svg, .bottom-nav svg { width: 19px; height: 19px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .2); }
.user-box { font-size: 13px; margin-bottom: 8px; }
.user-box small { display: block; opacity: .75; }
.sidebar .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .45); }
.main { flex: 1; margin-left: var(--sidebar); padding: 24px 28px 48px; min-width: 0; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11px; color: var(--ink-3); text-decoration: none; }
  .bottom-nav a.active { color: var(--blue); font-weight: 600; }
}

/* ---------- page ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; color: var(--blue-deep); }
.page-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-block; font-size: 13px; text-decoration: none; margin-bottom: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h3 { font-size: 15px; margin-bottom: 12px; color: var(--ink); }
.card h3 small { font-weight: 400; color: var(--ink-3); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; } }
.mt { margin-top: 14px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: 12.5px; color: var(--ink-2); }
.kpi .val { font-size: 22px; font-weight: 700; color: var(--blue-deep); margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .val small { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.kpi .hint { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.accent { background: var(--blue); border-color: var(--blue); }
.kpi.accent .lbl, .kpi.accent .hint, .kpi.accent .val small { color: rgba(255, 255, 255, .85); }
.kpi.accent .val { color: #fff; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 16px; }
.filters label { font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 3px; }
.filters select, .filters input { min-width: 140px; }

/* forms */
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid #C9D5E1; border-radius: 8px; background: #fff; font-size: 15px; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-200); border-color: var(--blue); }
textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.form-grid label .req { color: var(--blue); }
.form-grid .check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid .check input { width: auto; min-height: 0; }
.form-help { font-size: 12px; color: var(--ink-3); }
.calc { background: var(--blue-50); border: 1px solid var(--blue-100); border-radius: 8px; padding: 8px 12px; font-size: 13.5px; color: var(--blue-deep); }
.form-error { color: var(--danger); font-size: 13.5px; min-height: 1em; margin: 6px 0; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; text-decoration: none; min-height: 40px; white-space: nowrap; }
.btn:hover { border-color: var(--blue-200); background: var(--blue-50); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 4px 8px; }

/* quick entry tiles */
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.quick button { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 14px; text-align: left; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.quick button:hover { border-color: var(--blue); }
.quick .qi { width: 38px; height: 38px; border-radius: 10px; background: var(--blue-50); color: var(--blue); display: grid; place-items: center; }
.quick .qi svg { width: 21px; height: 21px; }
.quick b { font-size: 15px; }
.quick span { font-size: 12.5px; color: var(--ink-3); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: #FAFCFE; white-space: nowrap; position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--blue-50); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.row-actions { white-space: nowrap; text-align: right; }
.muted { color: var(--ink-3); }
.empty { color: var(--ink-3); padding: 24px 8px; text-align: center; font-size: 14px; }

.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--blue-50); color: var(--blue-dark); font-weight: 600; white-space: nowrap; border: 1px solid var(--blue-100); }
.badge.solid { background: var(--blue); color: #fff; border-color: var(--blue); }
.badge.outline { background: #fff; color: var(--ink-2); border-color: var(--line); }
.badge.off { background: #F1F3F5; color: var(--ink-3); border-color: #E3E7EB; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button.active { color: var(--blue); border-color: var(--blue); }

/* alerts */
.alerts { display: grid; gap: 8px; margin-bottom: 14px; }
.alert { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.alert b { color: var(--blue-deep); }
.alert.warn { border-left-color: var(--blue-deep); background: var(--blue-50); }

/* charts */
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 220px; }
.bar-list { display: grid; gap: 10px; }
.bar-item .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; gap: 8px; }
.bar-item .top b { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bar-track { height: 10px; background: var(--blue-50); border-radius: 99px; position: relative; overflow: hidden; }
.bar-fill { height: 100%; background: var(--blue); border-radius: 99px; }
.bar-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }

/* site cards */
.site-card { margin-bottom: 14px; }
.site-card .site-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.site-card h3 { margin: 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(10, 25, 40, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0, 20, 40, .3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; color: var(--blue-deep); }
.modal-body { padding: 16px 18px 18px; }
@media (max-width: 560px) {
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 16px 16px 0 0; max-height: 94vh; overflow-y: auto; }
}

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 200; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
@media (max-width: 860px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

.loading { color: var(--ink-3); padding: 40px; text-align: center; }

/* impression (rapports) */
.print-only { display: none; }
@media print {
  .sidebar, .bottom-nav, .actions, .filters, .no-print, .toast, .modal { display: none !important; }
  .main { margin: 0; padding: 0; }
  body { background: #fff; font-size: 12px; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .print-only { display: block; }
  .chart-box { height: 220px; }
}

@media (max-width: 760px) {
  .filters label { flex: 1 1 140px; }
  .filters select, .filters input { min-width: 0; }
  .table-wrap table { min-width: 640px; }
  .kpi .val { font-size: 20px; }
}

/* ---------- site de démonstration (config 'demo' => true) ---------- */
html.demo {
  --blue: #2E7D32;
  --blue-dark: #1B5E20;
  --blue-deep: #1B4D20;
  --blue-50: #EEF7EE;
  --blue-100: #D5EDD6;
  --blue-200: #A9D8AB;
}
.demo-banner { position: sticky; top: 0; z-index: 60; background: #1B5E20; color: #fff; text-align: center; font-size: 12.5px; font-weight: 600; letter-spacing: .3px; padding: 6px 12px; }
html.demo .sidebar { top: 30px; }
html.demo .login { min-height: calc(100vh - 30px); }
@media print { .demo-banner { display: block !important; position: static; background: none; color: #1B5E20; border: 1px solid #1B5E20; } }
.demo-accounts { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; }
.demo-accounts p { width: 100%; margin: 0 0 4px; font-size: 13px; color: var(--ink-2); }
