:root {
  --ink: #061527;
  --muted: #607085;
  --line: #d9e2eb;
  --panel: #ffffff;
  --teal: #004f54;
  --teal-2: #006d70;
  --blue: #0d64b8;
  --orange: #ff7a00;
  --green: #3e9b43;
  --red: #d9272e;
  --yellow: #f3c400;
  --sky: #2d8de0;
  --soft: #f5f9fc;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: #fff;
  cursor: crosshair;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 32px;
  gap: 20px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
}

.brand-strip {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}
.partner-logo { object-fit: contain; display: block; }
.fmd-logo { width: 248px; height: 132px; }
.dna-logo { width: 240px; height: 132px; }
.kordelia-header-logo { width: min(333px, 28vw); height: auto; }
.brand-separator { width: 1px; height: 132px; background: #9aa7b4; }

.main-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(128px, 1fr));
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  min-width: 0;
}
.tab-button {
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: #043f48;
  min-height: 56px;
  padding: 0 12px;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.tab-button:last-child { border-right: 0; }
.tab-button.active,
.setting-link.active {
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
}

.top-actions, .inline-actions { display: flex; align-items: center; gap: 18px; justify-content: flex-end; }
.icon-label {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: 7px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}
.icon-label.ghost { background: #fff; color: var(--teal); text-transform: none; }
.icon-label.primary { background: linear-gradient(135deg, var(--teal), var(--teal-2)); color: #fff; box-shadow: 0 8px 18px rgba(0, 79, 84, .2); }
.icon-label.small { min-height: 44px; padding: 0 18px; }
.history-button { width: 52px; padding: 0; }
.history-button.hidden { display: none; }
.history-button[disabled] { opacity: .35; cursor: not-allowed; }
.icon { font-size: 24px; line-height: 1; }

main { flex: 1; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.view-head.compact { justify-content: flex-start; margin-bottom: 46px; }
h1 { margin: 0; color: var(--teal); font-size: 34px; letter-spacing: 0; }
h2 { margin: 0 0 22px; color: var(--teal); font-size: 28px; letter-spacing: 0; }

.home-layout {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(520px, 1fr);
  gap: 32px;
  align-items: start;
}
.import-card input { width: min(100%, 460px); }
.import-card p {
  margin: 18px 0 0;
  color: var(--muted);
  font-weight: 700;
}
.import-status {
  color: var(--teal);
  font-weight: 900;
}
.alerts-panel { padding: 24px 28px; }
.alerts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.alerts-head h2 { margin: 0; }
.alerts-head span {
  color: var(--teal);
  font-weight: 900;
  white-space: nowrap;
}
.alerts-list { display: grid; gap: 20px; }
.alert-section {
  display: grid;
  gap: 10px;
}
.alert-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.alert-section-head h3 {
  margin: 0;
  color: var(--teal);
  font-size: 18px;
  letter-spacing: 0;
}
.alert-section-head span {
  min-width: 34px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #eaf4fb;
  color: var(--blue);
  font-weight: 900;
}
.alert-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--line);
}
.alert-row:last-child { border-bottom: 0; }
.new-meter-alert {
  background: #f5fbff;
  margin: 0 -12px;
  padding: 14px 12px;
  border-radius: 7px;
}
.alert-row strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
}
.alert-row span:not(.dot) {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}
.text-link {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}
.empty-state {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.period-panel {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 28px;
  padding: 24px 18px 18px;
  margin: 0 0 24px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  min-width: min(760px, 100%);
}
.period-panel.narrow { min-width: 730px; margin-top: 12px; }
.panel-label {
  position: absolute;
  left: -1px;
  top: -36px;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  color: #fff;
  padding: 10px 26px;
  border-radius: 7px 7px 0 0;
  font-weight: 800;
}
label { display: inline-flex; align-items: center; gap: 12px; font-weight: 800; color: #073c45; }
.period-reset-link {
  border: 0;
  border-bottom: 2px solid #064fa8;
  background: transparent;
  color: #064fa8;
  font-weight: 900;
  cursor: pointer;
  padding: 3px 0;
}
.period-reset-link:hover { color: var(--teal); border-bottom-color: var(--teal); }
input, select {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  font: inherit;
  background: #fff;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 42px;
  align-items: start;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(10, 31, 68, .05);
}
.metric-table { overflow: hidden; align-self: start; }
.table-title {
  display: grid;
  grid-template-columns: 1fr 180px;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  color: #fff;
  font-weight: 800;
  padding: 14px 28px;
  font-size: 20px;
}
.metric-row {
  display: grid;
  grid-template-columns: 1fr 180px;
  align-items: center;
  padding: 13px 28px;
  border-bottom: 1px dashed var(--line);
  font-size: 17px;
}
.metric-row strong { color: #064fa8; font-size: 24px; }
.metric-row strong.danger { color: var(--orange); }
.correction-note {
  display: none;
  margin: 14px 28px 22px;
  padding: 12px 14px;
  border: 1px solid #f2c66d;
  border-radius: 6px;
  background: #fff8e8;
  color: #7a4b00;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}
.correction-note.visible { display: block; }
.total-consumption-row span,
.total-consumption-row strong {
  color: #111;
  font-weight: 900;
}
.total-consumption-row strong {
  font-size: 30px;
}
.total-consumption-row span {
  font-size: 20px;
}
.total-box {
  display: grid;
  grid-template-columns: 1fr 180px;
  align-items: center;
  margin: 8px 12px 12px;
  padding: 12px 16px;
  border: 1px solid var(--teal);
  border-radius: 6px;
  color: var(--teal);
  font-weight: 800;
  font-size: 22px;
}
.state-line { display: grid; grid-template-columns: 28px 1fr 90px; align-items: center; padding: 11px 28px; border-bottom: 1px dashed var(--line); font-size: 16px; }
.dot { width: 17px; height: 17px; border-radius: 50%; display: inline-block; }
.chart-panel { padding: 22px 28px; }
.chart-layout { display: grid; grid-template-columns: 270px 1fr; gap: 32px; align-items: center; }
.donut {
  width: 260px;
  height: 260px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--blue) 0 70%, var(--orange) 70% 100%);
  position: relative;
  color: #fff;
  font-size: 26px;
  font-weight: 800;
}
.donut::after {
  content: "";
  position: absolute;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: #fff;
}
.donut-label {
  position: absolute;
  z-index: 2;
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .28);
}
.donut-label.dark { color: #0b1b2d; text-shadow: none; }
.donut-label.center { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.donut-label.top { left: 50%; top: 18px; transform: translateX(-50%); }
.donut-label.right { right: 28px; top: 50%; transform: translateY(-50%); }
.donut-label.bottom { left: 50%; bottom: 18px; transform: translateX(-50%); }
.donut-label.left { left: 26px; top: 50%; transform: translateY(-50%); }
.donut-label.upper-left { left: 42px; top: 54px; }
.donut-label.lower-left { left: 40px; bottom: 54px; }
.donut-label.upper-right { right: 42px; top: 54px; }
.donut-label.lower-right { right: 38px; bottom: 54px; }
.legend { display: grid; gap: 18px; }
.legend-item { display: grid; grid-template-columns: 18px 1fr; gap: 16px; align-items: center; font-size: 16px; }
.legend-swatch { width: 18px; height: 18px; border-radius: 4px; }

.search-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 300px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 14px;
  background: #fff;
  color: var(--teal);
  font-size: 28px;
}
.search-box.wide { min-width: 440px; }
.search-box input { border: 0; outline: 0; flex: 1; height: 48px; font-size: 16px; }

.table-filters {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: -8px 0 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbfd;
}
.table-filters.open { display: grid; }
.filter-field {
  display: grid;
  gap: 6px;
}
.filter-field label {
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
}
.filter-field input,
.filter-field select {
  width: 100%;
}
.clear-filters {
  align-self: end;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--teal);
  font-weight: 900;
  cursor: pointer;
}

.table-shell {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: #073c45; font-weight: 800; background: #fbfdff; }
td { font-size: 15px; }
td:first-child { font-weight: 700; }
.cell-compteur { display: grid; grid-template-columns: 18px minmax(0, 1fr) 34px; gap: 12px; align-items: center; }
.subline { display: block; margin-top: 4px; font-weight: 700; }
.new-meter-row td { background: #f5fbff; }
.new-meter-label {
  color: var(--blue);
  font-size: 13px;
  font-weight: 900;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 5px;
  font-weight: 800;
}
.badge.normal { background: #d9f2d4; color: #111; }
.badge.operationnel, .badge.resolu { background: #58b957; color: #111; }
.badge.surveillance, .badge.travaux, .badge.fige { background: #ffd34d; color: #111; }
.badge.verifier, .badge.zero { background: #ff9f33; color: #111; }
.badge.intervention, .badge.aucune { background: #e50914; color: #fff; }
.badge.arret { background: #bfd4ed; color: #111; }
.badge.incoherent { background: #acd0f3; color: #111; }
.badge.supprime { background: #d8b8ff; color: #111; }
.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  color: #17324a;
}
.settings-layout { display: grid; grid-template-columns: 320px 1fr; gap: 70px; padding-top: 20px; }
.settings-menu {
  display: grid;
  align-content: start;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.setting-link {
  min-height: 74px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #f7fbfc, #eef7f7);
  color: var(--teal);
  font-weight: 800;
  text-align: left;
  padding: 0 26px;
  text-transform: uppercase;
  cursor: pointer;
}
.settings-content { max-width: 920px; }
.settings-card { border: 1px solid var(--line); border-radius: 7px; padding: 28px; background: #fff; }
.settings-card h2 { display: flex; align-items: center; gap: 12px; }
.setting-grid { display: grid; gap: 12px; }
.setting-row { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(260px, auto); align-items: center; gap: 18px; min-height: 58px; border-bottom: 1px solid var(--line); }
.setting-row strong { color: var(--teal); }
.setting-row input { width: 120px; }
.editable-field {
  width: 120px;
  text-align: center;
  font-weight: 800;
}
.editable-select {
  width: 100%;
  min-width: 150px;
  font-weight: 700;
}
.date-input {
  width: 145px;
  font-weight: 700;
}
.date-input.locked {
  background: #f1f4f7;
  color: #7a8794;
  cursor: not-allowed;
}
.prob-meter {
  display: grid;
  gap: 6px;
  min-width: 130px;
}
.prob-track {
  height: 10px;
  border-radius: 999px;
  background: transparent;
}
.prob-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3fb7b4, #ffcc4d, #e50914);
}
.prob-value {
  font-weight: 900;
  color: #073c45;
}
.list-editor {
  display: grid;
  gap: 12px;
}
.editor-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.editor-row input {
  width: 100%;
}
.meter-search {
  min-width: 0;
}
.meter-search input {
  width: 100%;
}
.danger-button,
.add-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}
.danger-button { background: #ffe6e8; color: #9b1016; }
.add-button { background: var(--teal); color: #fff; justify-self: start; }
.editable-select.normal { background: #d9f2d4; color: #111; }
.editable-select.operationnel,
.editable-select.resolu { background: #58b957; color: #111; }
.editable-select.surveillance,
.editable-select.travaux,
.editable-select.fige { background: #ffd34d; color: #111; }
.editable-select.verifier,
.editable-select.zero { background: #ff9f33; color: #111; }
.editable-select.intervention,
.editable-select.aucune { background: #e50914; color: #fff; }
.editable-select.arret { background: #bfd4ed; color: #111; }
.editable-select.incoherent { background: #acd0f3; color: #111; }
.editable-select.supprime { background: #d8b8ff; color: #111; }
.pill-list { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 16px; }
.pill-list.single { grid-template-columns: minmax(280px, 520px); }
.profile-pill, .state-pill {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  font-weight: 800;
  background: #fff;
}

.status-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f4f9ff;
  color: #063568;
}
.info-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #1685df;
  color: #fff;
  font-weight: 800;
}
.footer-brand { justify-self: end; }

.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 20;
  min-width: 220px;
  padding: 14px 18px;
  border-radius: 7px;
  background: var(--teal);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(0, 79, 84, .24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.about-page {
  max-width: 1120px;
  display: grid;
  gap: 22px;
  line-height: 1.55;
}
.about-page section,
.about-intro {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 24px 28px;
}
.about-page p,
.about-page li {
  color: #1b3042;
  font-size: 16px;
  font-weight: 600;
}
.about-summary {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbfd;
}
.about-summary a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 6px;
  background: #fff;
  color: var(--teal);
  font-weight: 900;
  text-decoration: none;
}

@media (max-width: 1350px) {
  .topbar { grid-template-columns: 1fr; }
  .kordelia-header-logo { width: min(333px, 48vw); }
  .main-tabs { grid-template-columns: repeat(3, minmax(110px, 1fr)); }
  .top-actions { justify-content: flex-start; }
}

@media (max-width: 1100px) {
  .brand-strip { flex-wrap: wrap; }
  .kordelia-header-logo { width: min(333px, 100%); }
  .main-tabs { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .home-layout, .settings-layout { grid-template-columns: 1fr; }
  .chart-layout { grid-template-columns: 1fr; }
  .table-shell { overflow-x: auto; }
  table { min-width: 980px; }
}

.sort-date-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--teal);
  border-radius: 4px;
  margin-left: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
}
.sort-date-button.active { background: var(--teal); color: #fff; }
.rule-editor-row {
  grid-template-columns: minmax(190px, 1.2fr) 48px repeat(4, minmax(150px, auto)) auto;
  align-items: center;
}
.rule-editor-row label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.color-input { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.danger-zone { margin-top: 24px; border-color: #f0b8b8; background: #fffafa; }
.danger-button.wide { min-height: 44px; padding: 0 18px; }
@media (max-width: 1200px) { .rule-editor-row { grid-template-columns: 1fr; } }

.settings-save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 0 4px;
  background: linear-gradient(to top, #fff 70%, rgba(255,255,255,.85));
  z-index: 5;
}

.settings-save-hint {
  color: var(--muted);
  font-weight: 700;
}

.settings-save-hint.dirty {
  color: var(--orange);
}

.copy-meter-button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--teal);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.copy-meter-button:hover {
  background: var(--soft);
  border-color: var(--teal);
}

.analysis-info-button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--teal);
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
}
.analysis-info-button:hover { background: var(--soft); border-color: var(--teal); }

.meter-modal.hidden { display: none; }
.meter-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}
.meter-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 21, 39, .48);
}
.meter-modal-card {
  position: relative;
  width: min(1280px, 96vw);
  max-height: 94vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
  padding: 22px;
}
.meter-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 14px;
}
.meter-modal-head h2 { margin: 0 0 8px; font-size: 26px; color: var(--ink); }
.meter-modal-head p { margin: 0; color: var(--muted); font-weight: 700; }
.meter-modal-close {
  border: 0;
  background: #fff;
  color: #000;
  font-weight: 900;
  cursor: pointer;
  font-size: 30px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.meter-modal-close span { font-size: 15px; }
#meterModalCanvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: crosshair;
}
.meter-modal-explanation {
  margin-top: 18px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
}
.meter-modal-explanation h3 { margin: 0 0 8px; color: var(--teal); }
.meter-modal-explanation p { margin: 0; line-height: 1.45; color: var(--ink); }
.meter-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
