:root {
  --bg: #0f1826; --panel: #17223a; --panel2: #1e2b47; --line: #2a3a5c;
  --ink: #e8eef7; --muted: #93a4c2; --accent: #f5a623; --accent2: #3b82f6;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
input, select { font: inherit; }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 50% -10%, #1c2c4a 0%, var(--bg) 60%); }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px #0008; }
.brand { font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.brand-mark { color: var(--accent); }
.brand-sub { color: var(--muted); font-size: 13px; margin-top: -6px; }
.login-card label, .modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input, .modal input, .modal select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--ink); }
.btn-primary { background: var(--accent); color: #17223a; border: 0; border-radius: 8px; padding: 11px; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.btn-sm { padding: 5px 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--ink); }
.btn-sm:hover { border-color: var(--accent2); }
.error { color: var(--bad); font-size: 13px; min-height: 16px; }

/* App shell */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; }
.sidebar nav { margin-top: 22px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.sidebar nav a { color: var(--muted); text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.sidebar nav a:hover { background: var(--panel2); color: var(--ink); }
.sidebar nav a.active { background: var(--accent2); color: #fff; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.content { padding: 22px 26px; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.branch-filter { color: var(--muted); font-size: 13px; }
.branch-filter select { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--ink); }
.toast { margin-left: auto; color: var(--ok); font-size: 13px; }
.toast.bad { color: var(--bad); }

h2 { margin: 0 0 14px; font-size: 20px; }
.muted { color: var(--muted); }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.warn .value { color: var(--warn); }
.kpi.bad .value { color: var(--bad); }

/* Panels & tables */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tbody tr:hover { background: var(--panel2); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; border: 1px solid var(--line); }
.tag.ok { color: var(--ok); border-color: #14532d; background: #052e16; }
.tag.off { color: var(--muted); }
.tag.bad { color: var(--bad); border-color: #7f1d1d; background: #2a0a0a; }
.right { text-align: right; }
.search { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); min-width: 220px; }

/* Bar chart (trend) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bar { flex: 1; background: linear-gradient(var(--accent2), #1e40af); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--muted); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 440px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-head button { background: none; border: 0; color: var(--muted); font-size: 16px; }
#modalBody { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
#modalBody .form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* Aide (guide d'utilisation) */
.guide { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.guide-nav { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 3px; position: sticky; top: 16px; }
.guide-nav a { color: var(--muted); padding: 9px 11px; border-radius: 8px; font-size: 14px; cursor: pointer; display: flex; flex-direction: column; }
.guide-nav a small { font-size: 11px; opacity: .75; }
.guide-nav a:hover { background: var(--panel2); color: var(--ink); }
.guide-nav a.active { background: var(--accent2); color: #fff; }
.guide-topic { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.guide-topic-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.guide-topic h3 { margin: 0; font-size: 16px; }
.guide-topic p { line-height: 1.5; }
.guide-topic ol { padding-left: 22px; line-height: 1.6; }
.guide-topic ol li { margin-bottom: 4px; }
.guide-tips { background: #15223d; border: 1px solid #28457a; border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.guide-tips ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.5; }
.small { font-size: 12px; margin: 4px 0 8px; }
.tag.key { color: var(--accent); border-color: #7a5312; background: #2a1d05; white-space: nowrap; }
