:root {
  --bg: #F5F6F3;
  --surface: #FFFFFF;
  --text: #14171C;
  --muted: #5B616B;
  --border: #E3E5E0;
  --line: #EEF0EC;
  --field: #D7DAD3;
  --accent: #0E6B66;
  --accent-hover: #0A4F4B;
  --accent-ink: #FFFFFF;
  --accent-soft: #E4F1EF;
  --dark: #14171C;
  --dark-2: #23272E;
  --dark-muted: #A9AEA6;
  --ok-bg: #E4F1EF; --ok-ink: #0A4F4B;
  --warn-bg: #FBF0E1; --warn-ink: #8A4B0E;
  --err-bg: #F9E3E1; --err-ink: #8A2A22;
  --mine: #FFF6E0;
  --radius: 16px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 1.5rem; }
h2 { font-size: 1.125rem; font-weight: 700; margin: 0 0 1rem; }
h3 { font-size: 1rem; font-weight: 700; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; margin-top: 0; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: var(--mono); font-size: .9em; }
.mono { font-family: var(--mono); }

/* mise en page : barre latérale sombre + contenu */
body.app { display: flex; flex-wrap: wrap; align-items: stretch; min-height: 100vh; }
.sidebar {
  position: relative; overflow: hidden; flex: 1 1 240px; max-width: 100%;
  background: var(--dark); color: #E9EBE6; padding: 28px 20px;
  display: flex; flex-direction: column; gap: 28px;
  position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto;
}
.sidebar-pattern { position: absolute; left: 0; top: 0; width: 100%; height: 170px; pointer-events: none; }
.sidebar-photo {
  position: absolute; left: 0; right: 0; bottom: 0; height: 340px; pointer-events: none;
  background: linear-gradient(to bottom, var(--dark) 0%, rgba(20,23,28,.55) 45%, rgba(20,23,28,.15) 100%),
              url("../img/flammes.jpg") center / cover no-repeat;
  opacity: .8;
}
.sidebar > * { position: relative; }
.sidebar > .sidebar-pattern, .sidebar > .sidebar-photo { position: absolute; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; color: #FFFFFF; text-decoration: none; }
.brand:hover { color: #FFFFFF; }
.brand-logo { width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-text small { font-size: 12px; color: var(--dark-muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 44px; border-radius: 10px;
  color: #C9CDC5; text-decoration: none; font-weight: 500; font-size: 14px;
}
.sidebar nav a svg { flex: none; }
.sidebar nav a:hover { color: #FFFFFF; background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: var(--dark-2); color: #FFFFFF; font-weight: 600; }
.sidebar-user {
  margin-top: auto; padding: 16px; border-radius: 12px;
  background: rgba(20,23,28,.72); border: 1px solid rgba(255,255,255,.12);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar-user a { color: #FFFFFF; font-weight: 700; font-size: 15px; text-decoration: none; }
.sidebar-user a:hover { text-decoration: underline; color: #FFFFFF; }
.sidebar-user button.link { color: var(--dark-muted); font-size: 13px; padding: 0; min-height: 0; }
.sidebar-user button.link:hover { color: #FFFFFF; }
.muted-dark { font-size: 12px; color: var(--dark-muted); }

.container { flex: 999 1 640px; min-width: 0; max-width: 100%; margin: 0; padding: 40px clamp(16px, 4vw, 56px) 64px; }
body:not(.app) .container { max-width: 900px; margin: 0 auto; }
.container > :last-child { margin-bottom: 0; }

/* bandeau sombre en tête de page */
.hero {
  position: relative; overflow: hidden; background: var(--dark); color: #FFFFFF;
  border-radius: 20px; padding: 32px; min-height: 180px; margin-bottom: 24px;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px;
}
.hero > * { position: relative; }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background: linear-gradient(90deg, var(--dark) 35%, rgba(20,23,28,0) 100%), url("../img/flammes.jpg") right center / cover no-repeat;
}
.hero h1 { margin: 0; font-size: 2.3rem; }
.hero .eyebrow { font-size: 13px; font-weight: 600; color: #C9CDC5; letter-spacing: .06em; text-transform: uppercase; }
.hero .sub { font-size: 15px; color: #C9CDC5; }
.hero-text { display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.hero .actions { margin-top: 0; }
.hero .button.secondary { background: #1D2127; color: #FFFFFF; border-color: #3A3F47; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px; overflow-x: auto;
}
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 20px; }
.grid > .card { margin-bottom: 0; }
.row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.row > label { flex: 1 1 160px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-bottom: 1.5rem; }
.pagehead h1 { margin: 0; }
.pagehead h2 { margin: 0; }

/* formulaires */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); }
label.check { display: flex; gap: .5rem; align-items: center; color: var(--text); font-weight: 500; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; min-height: 44px;
  font: inherit; font-weight: 500; color: var(--text); background: #FFFFFF;
  border: 1px solid var(--field); border-radius: 10px;
}
textarea { min-height: 88px; }
input[type=checkbox] { display: inline; width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
input[type=file] { min-height: 0; padding: 8px; }
input.num { text-align: right; max-width: 9rem; margin-left: auto; font-family: var(--mono); }
input.short { max-width: 5.5rem; }
input.photo { font-size: .8rem; max-width: 13rem; border: 0; padding: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.stack > * + * { margin-top: 14px; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; font: inherit; font-size: 14px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: 10px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { background: var(--accent-hover); color: var(--accent-ink); }
button.secondary, .button.secondary { background: #FFFFFF; color: var(--text); border-color: var(--field); }
button.secondary:hover, .button.secondary:hover { background: var(--bg); color: var(--text); }
button.danger { background: var(--err-bg); color: var(--err-ink); }
button.danger:hover { background: #F2CFCB; color: var(--err-ink); }
button.small, .button.small { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
button.link, button.link:hover { background: none; min-height: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; border: 0; }
form.inline { display: inline; }

/* tableaux */
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; border-bottom-color: var(--border); }
tbody tr:hover td { background: #FAFBF9; }
tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--text); }
tr.mine td, tbody tr.mine:hover td { background: var(--mine); }
tr.inactive td { color: var(--muted); }
tr[data-radiateur] td { border-bottom: 0; padding-bottom: 4px; }
tr.coef-row td { padding-top: 0; font-size: 12px; color: var(--muted); }
tr.coef-row td.coef-info:empty { padding: 0; }
tbody tr.coef-row:hover td, tbody tr[data-radiateur]:hover td { background: transparent; }
tr.sub td { font-size: .88em; color: var(--muted); border-bottom-style: dashed; }
tr.sub td:first-child { padding-left: 28px; }
td input, td select { margin-top: 0; }

/* messages */
.flash { padding: 12px 16px; border-radius: 12px; margin: 0 0 20px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.warn { background: var(--warn-bg); color: var(--warn-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }
ul.warnings { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 12px 16px 12px 2rem; margin: .5rem 0 1rem; font-size: .9rem; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.closed { background: #ECEDEA; color: #4A4F57; }
.badge.off { background: var(--err-bg); color: var(--err-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* infobulles (i) */
.tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 800; font-style: italic;
  text-transform: none; letter-spacing: 0; cursor: help; vertical-align: middle; }
.tip:hover::after, .tip:focus::after {
  content: attr(data-tip); position: absolute; z-index: 10; top: calc(100% + 8px); right: -8px; width: 240px;
  padding: 10px 12px; border-radius: 10px; background: var(--dark); color: #FFFFFF; font: 500 13px/1.4 Manrope, system-ui, sans-serif;
  font-style: normal; text-align: left; white-space: normal; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.tip:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* bandeau « décompte incomplet » */
.alert { background: var(--warn-bg); color: var(--warn-ink); border: 2px solid #D9A15B; border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; }
.alert-head { display: flex; gap: 14px; align-items: flex-start; }
.alert-head svg { flex: none; margin-top: 2px; }
.alert h2 { margin: 0 0 4px; color: inherit; }
.alert p { margin: 0; }
.alert ul { margin: 14px 0 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: 4px; font-size: .92rem; }
.alert a { color: inherit; font-weight: 700; }
.alert-foot { margin-top: 12px !important; font-size: .9rem; }
.alert.info { background: var(--accent-soft); color: var(--ok-ink); border-color: #9CCBC5; }

/* chiffres clés */
.kpis { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.kpi { background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.kpis.big .kpi { background: var(--surface); border-radius: var(--radius); padding: 20px; gap: 10px; }
.kpis.big .kpi .value { font-size: 2rem; font-weight: 800; }
details { margin-top: .5rem; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.big-total { font-size: 1.8rem; font-weight: 800; font-family: var(--mono); letter-spacing: -0.02em; }

/* jauges de cuve */
.tanks { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tank { display: flex; gap: 16px; align-items: flex-end; }
.tank-gauge { width: 56px; height: 150px; flex: none; position: relative; overflow: hidden; border-radius: 14px; background: var(--line); border: 1px solid var(--border); }
.tank-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); }
.tank-fill.low { background: #A35A12; }
.tank-alert { position: absolute; left: 0; right: 0; bottom: 20%; border-top: 1px dashed var(--text); opacity: .35; }
.tank-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tank-info .name { font-size: 13px; color: var(--muted); font-weight: 600; }
.tank-info .pct { font-size: 1.75rem; font-weight: 800; font-family: var(--mono); letter-spacing: -0.02em; line-height: 1.1; }
.tank-info .low { color: #A35A12; font-weight: 700; font-size: 12px; }

/* barres de répartition */
.bars { display: flex; flex-direction: column; gap: 18px; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 8px; }
.bar-head .mono { font-weight: 600; white-space: nowrap; }
.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 10px; border-radius: 999px; background: var(--accent); }

/* saisie des relevés : une carte par compteur */
.meters { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); margin-top: 16px; }
.meter { border: 1px solid var(--border); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 14px; background: var(--surface); }
.meter:focus-within { border: 2px solid var(--accent); padding: 19px; }
.meter-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.meter-title { display: flex; flex-direction: column; gap: 2px; }
.meter-title strong { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.meter-title span { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.meter-prev { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 14px; background: var(--bg); border-radius: 12px; font-size: 13px; color: var(--muted); }
.meter-prev strong { font-family: var(--mono); font-size: 1.1rem; color: var(--text); }
.meter-fields { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; }
.meter-fields input { font-family: var(--mono); font-weight: 700; font-size: 1.5rem; padding: 8px 12px; }
.meter-fields input::placeholder { font-size: .85rem; font-weight: 500; font-family: Manrope, system-ui, sans-serif; }
.photo-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px;
  border-radius: 14px; border: 1.5px dashed #B9BDB4; background: #FFFFFF; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text);
}
.photo-btn:hover { border-color: var(--accent); }
.photo-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.photo-btn.done { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* connexion */
.login-page {
  display: grid; place-items: center; min-height: 100vh; padding: 16px;
  background: linear-gradient(to bottom, rgba(20,23,28,.92), rgba(20,23,28,.6)), url("../img/flammes.jpg") center / cover no-repeat var(--dark);
}
.login-box { background: var(--surface); border-radius: 20px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-box .brand { padding: 0; color: var(--text); margin-bottom: 24px; }
.login-box .brand-text small { color: var(--muted); }
.login-box h1 { font-size: 1.6rem; margin-bottom: .25rem; }
.login-box button[type=submit] { width: 100%; min-height: 52px; font-size: 15px; }

@media (max-width: 880px) {
  .sidebar { padding: 16px; gap: 14px; position: relative; height: auto; overflow: hidden; align-self: stretch; }
  .sidebar-photo, .sidebar-pattern { display: none; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
  .sidebar nav a { white-space: nowrap; padding: 8px 12px; }
  .sidebar-user { margin-top: 0; padding: 0; background: none; border: 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
  .sidebar-user .muted-dark { display: none; }
  .brand { padding: 0; }
  .container { padding-top: 24px; }
  h1 { font-size: 1.6rem; }
  .hero { padding: 24px; min-height: 0; }
  .hero h1 { font-size: 1.8rem; }
}
@media (max-width: 640px) {
  .card { padding: 16px; border-radius: 14px; }
  th, td { padding: 10px 6px; }
}
@media print {
  .sidebar, .no-print, form { display: none !important; }
  body, body.app { background: #fff; display: block; }
  .container { padding: 0; }
  .card { border: 0; padding: 0; }
  .hero { background: none; color: var(--text); padding: 0; min-height: 0; }
  .hero::before { display: none; }
  details { display: block; }
}
.login-link { margin: 16px 0 0; text-align: center; font-size: 14px; }
