/* TCS — interface v0. Clair le jour, sombre la nuit (préférence système) : l'outil sert aussi à 3 h du matin. */
:root {
  --navy: #0f2b46;
  --green: #5a9e2f;
  --green-strong: #3f7a1c;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17222c;
  --muted: #5b6873;
  --line: #d7ded6;
  --good: #2f8a3c;
  --warn: #b7791f;
  --bad: #c0362c;
  --info: #2563a8;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 43 70 / 6%), 0 2px 8px rgb(15 43 70 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1620;
    --surface: #15212d;
    --surface-2: #1c2b39;
    --text: #e6edf2;
    --muted: #9badbb;
    --line: #2a3b4b;
    --green: #7cc242;
    --green-strong: #8fd451;
    --good: #5cc36c;
    --warn: #e0a440;
    --bad: #f0675b;
    --info: #6aa8ea;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--info); }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* En-tête */
.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--navy); color: #fff; padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand small { font-weight: 400; opacity: .75; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #dfe8ef; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: .95rem;
}
.nav a:hover { background: rgb(255 255 255 / 8%); }
.nav a.on { background: color-mix(in srgb, var(--green) 26%, transparent); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: #dfe8ef; }
.who button { background: transparent; border: 1px solid rgb(255 255 255 / 35%); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.sub { color: var(--muted); margin-bottom: 20px; }

/* Cartes et grilles */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.grid .card + .card { margin-top: 0; }
.module { display: flex; flex-direction: column; gap: 6px; }
.module .tag { align-self: flex-start; }
.module.locked { opacity: .78; }
.module p { color: var(--muted); flex: 1; }

/* Formulaires */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select { margin-top: 4px; }
input, select, button { font: inherit; }
input, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--green); outline-offset: 2px;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
.check input { width: auto; margin: 0; }
button {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--green-strong);
  background: var(--green-strong); color: #fff; cursor: pointer; white-space: nowrap;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.small { padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; }

/* Connexion */
.login { max-width: 380px; margin: 9vh auto; padding: 0 20px; }
.login .card { padding: 28px; }
.login .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login .logo img { width: 44px; height: 44px; }
.login button { width: 100%; margin-top: 6px; padding: 10px; }

/* Messages */
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: .92rem; }
.notice.error { color: var(--bad); border-color: var(--bad); background: rgb(192 54 44 / 7%); }
.notice.ok { color: var(--good); border-color: var(--good); background: rgb(47 138 60 / 8%); }
.notice.info { color: var(--info); border-color: var(--info); background: rgb(37 99 168 / 7%); }
.notice code { font-size: 1rem; user-select: all; color: var(--text); }

.tag {
  display: inline-block; font-size: .78rem; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.tag.good { color: var(--good); border-color: currentColor; background: transparent; }
.tag.warn { color: var(--warn); border-color: currentColor; background: transparent; }
.tag.bad { color: var(--bad); border-color: currentColor; background: transparent; }
.tag.info { color: var(--info); border-color: currentColor; background: transparent; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td select, td input[type=text] { min-width: 110px; padding: 4px 6px; }
.empty { color: var(--muted); padding: 16px 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--green); }

/* Exploitations */
.parcelles { list-style: none; padding: 0; margin: 8px 0 12px; }
.parcelles li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.parcelles a { font-weight: 600; text-decoration: none; }

/* Parcelle */
.parcel { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; }
@media (max-width: 900px) { .parcel { grid-template-columns: 1fr; } }
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
@media (max-width: 900px) { #map { height: 380px; } }
#map.placing { cursor: crosshair; }
.side { display: flex; flex-direction: column; gap: 16px; }
.item { padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.vals { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: .9rem; }
.vals b { font-variant-numeric: tabular-nums; }
.when { color: var(--muted); font-size: .8rem; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.temp-bad { color: var(--bad); }
.temp-warn { color: var(--warn); }
.temp-good { color: var(--good); }
.leaflet-container { font: inherit; }

/* Visuels du matériel */
.thumb { object-fit: contain; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--line); flex: none; }
.thumb.sm { width: 40px; height: 40px; }
.thumb.md { width: 56px; height: 72px; }
.thumb.lg { width: 120px; height: 160px; }
.thumb.none { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; font-weight: 600; }
.with-thumb { display: flex; gap: 12px; align-items: flex-start; }
.with-thumb > div { flex: 1; min-width: 0; }
.kind-preview { display: flex; gap: 14px; align-items: center; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.kind-preview p { margin: 0; }
.catalogue { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.catalogue .card + .card { margin-top: 0; }
.catalogue .card { display: flex; gap: 12px; align-items: center; padding: 12px; }
.catalogue h3 { margin: 0 0 2px; }

/* Miniatures des appareils sur la carte */
.iot-pin-wrap { background: none; border: 0; }
.iot-pin {
  position: relative; width: 100%; height: 100%; border: 3px solid #8a96a0; border-radius: 12px;
  background: #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 40%); transition: transform .12s;
}
.iot-pin:hover { transform: scale(1.12); z-index: 1; }
.iot-pin.round { border-radius: 50%; }
.thumb.pin { width: 100%; height: 100%; border: 0; border-radius: 9px; object-fit: cover; object-position: center 30%; background: #fff; display: block; }
.iot-pin.round .thumb.pin { border-radius: 50%; }
.pin-wind_machine .thumb.pin { object-position: center; }
.thumb.pin.none { font-size: .75rem; color: var(--navy); }
.pin-chip {
  position: absolute; top: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  padding: 1px 7px; border-radius: 6px; background: #0f2b46; color: #fff;
  font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}
.pin-chip.temp-bad { background: #c0362c; color: #fff; }
.pin-chip.temp-warn { background: #d08a1e; color: #fff; }
.pin-chip.temp-good { background: #2f8a3c; color: #fff; }
@media (prefers-reduced-motion: reduce) { .iot-pin { transition: none; } }

/* Code couleur unique des températures (carte, légende, panneau) */
.fz-pos { background: #c0362c; color: #fff; }
.fz-zone { background: #2f8a3c; color: #fff; }
.fz-cold { background: #2563a8; color: #fff; }
.fz-none { background: #6b7680; color: #fff; }
.ft-pos { color: var(--bad); }
.ft-zone { color: var(--good); }
.ft-cold { color: var(--info); }
.legend-chip { padding: 1px 7px; border-radius: 5px; font-size: .78rem; }
.pin-chip.top { top: auto; bottom: calc(100% + 4px); }
.pin-state {
  position: absolute; top: calc(50% - 11px); right: -13px; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 13px; line-height: 1;
  color: #fff; border: 2px solid #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 40%);
}
.pin-state.on { background: #2f8a3c; }
.pin-state.off { background: #6b7680; font-size: 9px; }
.pin-state.fault { background: #c0362c; font-weight: 800; }
@media (prefers-reduced-motion: no-preference) {
  .pin-state.on { animation: tcs-spin 2.4s linear infinite; }
}
@keyframes tcs-spin { to { transform: rotate(360deg); } }

/* Températures de référence de la parcelle */
.thresholds { display: flex; flex-wrap: wrap; gap: 12px 28px; align-items: center; margin-bottom: 14px;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.thresholds.editing { display: block; }
.threshold { display: flex; flex-direction: column; }
.threshold strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

/* Alerte de réglage : démarrage automatique sous la préconisation (orange, distinct du code couleur du gel) */
.notice.alert { color: #3a2a06; background: #f6c453; border-color: #d08a1e; }
.notice.alert strong { display: block; }
.ft-alert { color: var(--warn); font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; }

/* Fiche machine */
.crumbs { margin-bottom: 8px; font-size: .9rem; }
.machine-head { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 16px; }
.machine-head h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.machine-head .sub { margin-bottom: 6px; }
.run-badge { font-size: .85rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid currentColor; }
.run-badge.on { color: var(--good); }
.run-badge.off { color: var(--muted); }
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }
.param-grid .card + .card { margin-top: 0; }
.params h2 { font-size: 1rem; margin-bottom: 8px; }
.params dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: .92rem; }
.params dt { color: var(--muted); }
.params dt small { display: block; font-size: .75rem; opacity: .85; }
.params dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.params dd.missing { font-weight: 400; color: var(--muted); font-style: italic; }
.params dd.st-warn { color: var(--warn); }
.params dd.st-alert { color: var(--bad); }
.params dd.st-warn::before, .params dd.st-alert::before { content: '● '; font-size: .7em; vertical-align: middle; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 2 3; opacity: .6; }
.chart .crit { stroke: var(--info); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .crit-txt { fill: var(--info); }
.chart .start { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .start-txt { fill: var(--good); }
.legend-line { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.oad { margin-top: 16px; border-left: 4px solid var(--navy); }
.oad h2 { margin-bottom: 4px; }
.oad-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.oad-list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.oad-list li div div { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.oad-ico { flex: none; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; color: #fff; }
.oad-alert { border-color: var(--bad) !important; }
.oad-alert .oad-ico { background: var(--bad); }
.oad-warn { border-color: var(--warn) !important; }
.oad-warn .oad-ico { background: var(--warn); }
.oad-info .oad-ico { background: var(--info); }
.oad-ok .oad-ico { background: var(--good); }
.item-link { color: inherit; text-decoration: none; }
.item-link:hover strong { text-decoration: underline; }
a.more { display: inline-block; margin-top: 6px; font-size: .88rem; font-weight: 600; }
.leaflet-marker-icon.iot-pin-wrap { cursor: pointer; }
@media (max-width: 600px) { .machine-head .thumb.lg { width: 72px; height: 96px; } }
.fault-line { color: var(--bad); font-weight: 600; font-size: .88rem; margin-top: 4px; }
.booster-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.module.soon { border-style: dashed; }
