:root {
  --blue: #1178b7;
  --cyan: #10b3d8;
  --ink: #12263a;
  --muted: #5b6b7c;
  --line: #dbe4ec;
  --bg: #f3f7fa;
  --card: #ffffff;
  --ok: #1a9a52;
  --ok-bg: #e4f6ec;
  --bad: #c62f2f;
  --bad-bg: #fbe7e7;
  --warn: #b86e00;
  --warn-bg: #fff2d9;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--card); border-radius: var(--radius);
  padding: 28px 24px; box-shadow: 0 8px 30px rgba(17, 120, 183, .15); display: grid; gap: 10px; text-align: center;
}
.login-logo { width: 84px; margin: 0 auto; }
.login-card h1 { color: var(--blue); font-size: 2rem; }
.login-card label { text-align: left; font-weight: 600; margin-top: 8px; }
input[type=password], input[type=text], select {
  width: 100%; padding: 12px 14px; font-size: 1rem; border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.error { color: var(--bad); min-height: 1.3em; margin: 0; font-weight: 600; }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  min-height: 46px; transition: transform .05s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.small { min-height: 36px; padding: 6px 12px; font-weight: 600; }
.btn.open { background: var(--ok); color: #fff; }
.btn.close { background: var(--bad); color: #fff; }

/* ---------- En-tête ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 42px; height: 42px; object-fit: contain; }
.brand strong { display: block; font-size: 1.15rem; color: var(--blue); }
.brand .muted { font-size: .85rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill { padding: 4px 12px; border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.neutral { background: #e8eef4; color: var(--muted); }

/* ---------- Mise en page ---------- */
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; padding: 20px; max-width: 1280px; margin: 0 auto; }
.meters h2, .detail h2 { font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.meter-card {
  display: grid; gap: 6px; width: 100%; text-align: left; font: inherit; margin-bottom: 10px; cursor: pointer;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.meter-card.selected { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(17, 120, 183, .12); }
.meter-card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.meter-card .name { font-size: 1.25rem; font-weight: 800; }
.meter-card .sn { font-size: .8rem; color: var(--muted); }
.meter-card small { color: var(--muted); }

.detail { display: grid; gap: 16px; align-content: start; }
.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 16px; }
.detail-head h2 { font-size: 1.6rem; color: var(--ink); text-transform: none; letter-spacing: 0; margin: 0; }

/* ---------- Indicateurs ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.35rem; font-weight: 800; margin-top: 2px; }
.stat .sub { font-size: .8rem; color: var(--muted); }

/* ---------- Vanne ---------- */
.valve-panel { display: grid; gap: 14px; }
.valve-state { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.valve-badge { font-size: 1.5rem; font-weight: 800; padding: 10px 22px; border-radius: 14px; }
.valve-badge.open { background: var(--ok-bg); color: var(--ok); }
.valve-badge.closed { background: var(--bad-bg); color: var(--bad); }
.valve-badge.moving { background: var(--warn-bg); color: var(--warn); }
.valve-badge.unknown { background: #e8eef4; color: var(--muted); }
.valve-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.valve-buttons .btn { font-size: 1.15rem; min-height: 64px; }

/* ---------- Suivi d'une commande ---------- */
.tracker { display: grid; gap: 4px; }
.steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.steps li { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); }
.steps .dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center;
  font-size: .75rem; font-weight: 800; background: #fff;
}
.steps li.done { color: var(--ink); }
.steps li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.steps li.active { color: var(--ink); font-weight: 700; }
.steps li.active .dot { border-color: var(--blue); animation: pulse 1.2s infinite; }
.steps li.fail { color: var(--bad); }
.steps li.fail .dot { background: var(--bad); border-color: var(--bad); color: #fff; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(17,120,183,.5); } 100% { box-shadow: 0 0 0 10px rgba(17,120,183,0); } }
@media (prefers-reduced-motion: reduce) { .steps li.active .dot { animation: none; } }

/* ---------- Période ---------- */
.period { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.period .btn { min-height: 40px; padding: 8px 14px; }
.period .btn.current { border-color: var(--blue); color: var(--blue); background: #eaf4fb; }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }

/* ---------- Dialogue ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 25, 40, .55); }
.dialog-card { padding: 22px; display: grid; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.note { font-size: .88rem; color: var(--muted); }
.chart-box { height: 240px; position: relative; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .brand .muted { display: none; }
  .valve-buttons { grid-template-columns: 1fr; }
}
