/* ============ Hydro Easy — styles ============ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* leçon GMAO : toujours dans le reset */
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; color: #1a2733; background: #eef2f5;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; cursor: pointer; }

/* ---- Barre supérieure ---- */
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  background: linear-gradient(90deg, #0b5394, #0e6ba8); color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.25); z-index: 1200; flex-wrap: wrap;
}
#topbar .brand { font-size: 16px; white-space: nowrap; }
#topbar .logo { font-size: 18px; }
#projectName {
  flex: 0 1 220px; min-width: 120px; border: none; border-radius: 6px;
  padding: 5px 9px; font-size: 13px; background: rgba(255,255,255,.16); color: #fff;
}
#projectName::placeholder { color: #cfe3f5; }
#projectName:focus { background: #fff; color: #1a2733; outline: none; }
.topbtns { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-left: auto; }
.topbtns button, .topbtns .filebtn {
  border: none; border-radius: 6px; padding: 5px 9px; font-size: 12.5px;
  background: rgba(255,255,255,.14); color: #fff; white-space: nowrap;
}
.topbtns button:hover, .topbtns .filebtn:hover { background: rgba(255,255,255,.28); }
.topbtns button.primary { background: #2ecc71; font-weight: 600; }
.topbtns button.primary:hover { background: #29b765; }
.topbtns button.primary:disabled { background: #8fb8a2; cursor: wait; }
.topbtns .sep { width: 1px; height: 20px; background: rgba(255,255,255,.3); }
.filebtn { display: inline-block; cursor: pointer; }

/* ---- Corps ---- */
main { flex: 1; display: flex; min-height: 0; position: relative; }
#map { flex: 1; min-width: 0; background: #cfd8dc; }

/* ---- Boîte à outils ---- */
#toolbox {
  width: 68px; background: #fff; border-right: 1px solid #d5dde3;
  display: flex; flex-direction: column; align-items: stretch; padding: 6px 4px; gap: 3px;
  z-index: 1100; overflow-y: auto;
}
#toolbox hr { width: 80%; border: none; border-top: 1px solid #e0e6ea; margin: 4px auto; }
.tool {
  border: 1px solid transparent; background: none; border-radius: 8px;
  padding: 6px 2px; font-size: 17px; line-height: 1.1; color: #33475b;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tool span { font-size: 10px; }
.tool:hover { background: #eaf3fb; }
.tool.active { background: #0b5394; color: #fff; border-color: #0b5394; }

/* ---- Panneau latéral ---- */
#sidepanel {
  width: 300px; background: #fff; border-left: 1px solid #d5dde3;
  display: flex; flex-direction: column; z-index: 1100; min-height: 0;
}
#paneltabs { display: flex; border-bottom: 1px solid #e0e6ea; }
#paneltabs button {
  flex: 1; border: none; background: none; padding: 9px 4px; font-size: 12.5px;
  color: #607086; border-bottom: 2px solid transparent;
}
#paneltabs button.active { color: #0b5394; font-weight: 600; border-bottom-color: #0b5394; }
.badge {
  background: #e53935; color: #fff; border-radius: 9px; font-size: 10px;
  padding: 1px 6px; margin-left: 3px; vertical-align: 1px;
}
.tabpane { flex: 1; overflow-y: auto; padding: 10px 12px; min-height: 0; }
.hint { color: #7d8da0; font-size: 12.5px; }

/* Formulaire propriétés */
.propform h3 { margin: 0 0 2px; font-size: 14px; color: #0b5394; }
.propform .subtitle { color: #7d8da0; font-size: 11.5px; margin-bottom: 10px; }
.propform label { display: block; margin: 8px 0 2px; font-size: 12px; color: #4a5a6d; }
.propform input, .propform select {
  width: 100%; padding: 5px 7px; border: 1px solid #c9d3dc; border-radius: 5px; font-size: 13px;
}
.propform input:focus, .propform select:focus { outline: 2px solid #9cc3e5; border-color: #0b5394; }
.propform .row2 { display: flex; gap: 8px; }
.propform .row2 > div { flex: 1; }
.propform .inline { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: #4a5a6d; }
.propform .inline input[type=checkbox] { width: auto; }
.propform .danger {
  margin-top: 14px; width: 100%; background: #fdecea; color: #c62828;
  border: 1px solid #f5c6c2; border-radius: 6px; padding: 7px;
}
.propform .danger:hover { background: #fbd9d5; }
.resultbox {
  margin-top: 12px; background: #f2f7fb; border: 1px solid #d7e5f0;
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
}
.resultbox h4 { margin: 0 0 6px; font-size: 12px; color: #0b5394; }
.resultbox table { width: 100%; border-collapse: collapse; }
.resultbox td { padding: 2px 0; }
.resultbox td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.chartbox { margin-top: 8px; }
.chartbox svg { width: 100%; height: auto; display: block; }

/* Problèmes */
.issue { padding: 7px 9px; border-radius: 6px; margin-bottom: 6px; font-size: 12.5px; cursor: pointer; }
.issue.err { background: #fdecea; border: 1px solid #f5c6c2; color: #b3261e; }
.issue.warn { background: #fff8e1; border: 1px solid #f4e3ae; color: #8a6d00; }
.issue.okmsg { background: #e8f5e9; border: 1px solid #c6e6c8; color: #256d29; cursor: default; }

/* ---- Barre de résultats ---- */
#resultsbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: #fff; border-top: 1px solid #d5dde3; padding: 6px 12px; z-index: 1100;
}
.rb-group { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #4a5a6d; }
.rb-group select { padding: 3px 5px; border: 1px solid #c9d3dc; border-radius: 5px; font-size: 12.5px; }
.rb-time { flex: 1; min-width: 220px; }
#timeSlider { flex: 1; }
#timeLabel { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 46px; }
#btnPlay { border: 1px solid #c9d3dc; background: #fff; border-radius: 5px; padding: 2px 9px; }
#legend { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.legchip { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; color: #4a5a6d; margin-right: 6px; }
.legchip i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
#btnTables, #btnCloseResults { border: 1px solid #c9d3dc; background: #fff; border-radius: 5px; padding: 3px 9px; font-size: 12px; }

/* ---- Barre de statut ---- */
#statusbar {
  display: flex; justify-content: space-between; padding: 3px 12px;
  background: #1a2733; color: #b7c5d3; font-size: 11.5px; z-index: 1100;
}

/* ---- Marqueurs carte ---- */
.node-icon { display: block; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.node-icon.reservoir { border-radius: 3px; }
.node-icon.tank { border-radius: 3px 3px 8px 8px; }
.node-icon.selected { outline: 3px solid #ff9800; outline-offset: 1px; }
.node-label {
  background: rgba(255,255,255,.85); border: none; box-shadow: none;
  font-size: 10px; font-weight: 600; color: #33475b; padding: 0 3px; border-radius: 3px;
  pointer-events: none; white-space: nowrap;
}
.linkarrow { pointer-events: none; font-size: 14px; color: #123; text-shadow: 0 0 2px #fff, 0 0 2px #fff; }

/* ---- Modales ---- */
#modalRoot { position: fixed; inset: 0; z-index: 2000; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,25,40,.5); }
.modal {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: #fff; border-radius: 10px; width: min(720px, 94vw); max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.modal > header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid #e0e6ea; font-weight: 600; font-size: 15px; color: #0b5394;
}
.modal > header button { border: none; background: none; font-size: 16px; color: #7d8da0; }
#modalBody { padding: 14px 16px; overflow-y: auto; }
#modalBody h4 { margin: 14px 0 6px; font-size: 13px; color: #0b5394; }
#modalBody label { display: block; margin: 8px 0 2px; font-size: 12px; color: #4a5a6d; }
#modalBody input, #modalBody select, #modalBody textarea {
  width: 100%; padding: 5px 7px; border: 1px solid #c9d3dc; border-radius: 5px; font-size: 13px; font-family: inherit;
}
#modalBody textarea { font-family: Consolas, monospace; font-size: 12px; }
#modalBody .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
#modalBody .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { border-radius: 6px; padding: 7px 16px; border: 1px solid #c9d3dc; background: #fff; }
.modal-actions button.primary { background: #0b5394; color: #fff; border-color: #0b5394; font-weight: 600; }

/* Tables de résultats */
.restable-wrap { overflow: auto; max-height: 55vh; border: 1px solid #e0e6ea; border-radius: 6px; }
.restable { width: 100%; border-collapse: collapse; font-size: 12px; }
.restable th {
  position: sticky; top: 0; background: #f2f6f9; text-align: right; padding: 6px 8px;
  border-bottom: 1px solid #d5dde3; cursor: pointer; user-select: none; white-space: nowrap;
}
.restable th:first-child, .restable td:first-child { text-align: left; }
.restable td { padding: 4px 8px; border-bottom: 1px solid #eef2f5; text-align: right; font-variant-numeric: tabular-nums; }
.restable tr:hover td { background: #f2f7fb; }

/* Toast */
#toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: #1a2733; color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; z-index: 3000; box-shadow: 0 4px 16px rgba(0,0,0,.35); max-width: 80vw;
}
#toast.err { background: #b3261e; }
#toast.ok { background: #256d29; }

/* Spinner sur le bouton Calculer */
.spin::before { content: ''; display: inline-block; width: 11px; height: 11px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; margin-right: 6px; animation: sp 0.8s linear infinite; vertical-align: -1px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---- Mobile ---- */
@media (max-width: 820px) {
  #sidepanel {
    position: absolute; right: 0; top: 0; bottom: 0; width: min(320px, 88vw);
    box-shadow: -4px 0 16px rgba(0,0,0,.25); transform: translateX(100%); transition: transform .2s;
  }
  #sidepanel.open { transform: none; }
  #toolbox { width: 54px; }
  .tool span { display: none; }
  .tool { font-size: 19px; padding: 9px 2px; }
  #topbar .brand strong { display: none; }
}
@media print {
  #topbar, #toolbox, #sidepanel, #statusbar, #resultsbar { display: none !important; }
}

/* ---- SaaS : cloud, Pro, IA, calage ---- */
.cloudrow {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid #e0e6ea; border-radius: 8px; margin-bottom: 6px;
}
.cloudrow .cloudname { flex: 1; min-width: 0; }
.cloudrow button { border: 1px solid #c9d3dc; background: #fff; border-radius: 6px; padding: 5px 9px; font-size: 14px; }
.cloudrow button:hover { background: #eaf3fb; }

.protable th, .protable td { border: 1px solid #e0e6ea; padding: 6px 9px; text-align: center; }
.protable td:first-child { text-align: left; }
.protable th { background: #f2f6f9; }

#aiPanel {
  position: fixed; right: 14px; bottom: 64px; width: min(400px, 92vw); height: min(520px, 70vh);
  background: #fff; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column; z-index: 1500; overflow: hidden;
}
#aiPanel > header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: #0b5394; color: #fff; font-weight: 600; font-size: 14px;
}
#aiPanel > header .hint { color: #b8d4ec; font-weight: 400; font-size: 11px; margin-left: auto; }
#aiPanel > header button { border: none; background: none; color: #fff; font-size: 15px; }
#aiMessages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.aimsg { max-width: 88%; padding: 8px 11px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.aimsg.user { align-self: flex-end; background: #0b5394; color: #fff; border-bottom-right-radius: 3px; }
.aimsg.bot { align-self: flex-start; background: #eef3f7; color: #1a2733; border-bottom-left-radius: 3px; }
.aimsg code { background: rgba(0,0,0,.08); padding: 0 4px; border-radius: 3px; font-size: 12px; }
.aimsg .aiload {
  margin-top: 6px; background: #2ecc71; color: #fff; border: none;
  border-radius: 6px; padding: 6px 10px; font-size: 12.5px; font-weight: 600;
}
#aiInputRow { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e0e6ea; }
#aiInput { flex: 1; resize: none; border: 1px solid #c9d3dc; border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 13px; }
#aiSend { border: none; background: #0b5394; color: #fff; border-radius: 8px; padding: 0 14px; font-size: 16px; }

/* Tutoriel guidé */
.tuto-target { outline: 3px solid #ff9800 !important; outline-offset: 2px; position: relative; z-index: 1400 !important; }
#tutoTip {
  position: fixed; width: 360px; max-width: 92vw; background: #1a2733; color: #eef2f5;
  border-radius: 10px; padding: 13px 15px; z-index: 2600; box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 13px; line-height: 1.5;
}
#tutoTip .tuto-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
#tutoTip button { border: 1px solid #46586c; background: none; color: #cfe3f5; border-radius: 6px; padding: 5px 12px; font-size: 12px; }
#tutoTip button.primary { background: #2ecc71; border-color: #2ecc71; color: #fff; font-weight: 600; }

/* Poignées d'édition de tracé */
.vhandle {
  display: block; width: 11px; height: 11px; background: #fff;
  border: 2.5px solid #ff9800; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: move;
}
.vghost {
  display: block; width: 9px; height: 9px; background: rgba(255,152,0,.4);
  border: 1.5px solid #ff9800; border-radius: 50%; cursor: copy;
}

.calrow { display: flex; gap: 8px; margin-bottom: 6px; }
.calrow select { flex: 0 0 130px; }
.calrow input { flex: 1; }
#cal_add { border: 1px dashed #c9d3dc; background: none; border-radius: 6px; padding: 5px 10px; font-size: 12px; color: #4a5a6d; }
