/* ============================================================================
 * HydroCalc — Feuille de style
 * ==========================================================================*/
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --primary: #0e7490;
  --primary-dark: #155e75;
  --primary-soft: #ecfeff;
  --accent: #2563eb;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.05);
  --radius: 12px;
  --sidebar-w: 268px;
  --top-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

/* --- Barre supérieure ----------------------------------------------------- */
.topbar {
  height: var(--top-h);
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 19px; }
.brand-mark { font-size: 22px; opacity: .9; }
.brand-sub {
  font-weight: 400; font-size: 12.5px; opacity: .82; padding-left: 10px;
  margin-left: 6px; border-left: 1px solid rgba(255,255,255,.35);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.projet-input {
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
  color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 13.5px; width: 190px;
}
.projet-input::placeholder { color: rgba(255,255,255,.7); }
.btn {
  background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.28);
  border-radius: 8px; padding: 6px 11px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  transition: background .15s;
}
.btn:hover { background: rgba(255,255,255,.28); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 3px 8px; font-size: 12px; }

/* --- Mise en page --------------------------------------------------------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--top-h));
  position: sticky; top: var(--top-h);
  overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line);
  padding: 12px 10px 30px;
}
.nav-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; padding: 14px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-soft);
  font-size: 14px; font-family: inherit; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.content {
  flex: 1 1 auto; min-width: 0; padding: 26px 34px 60px;
  height: calc(100vh - var(--top-h)); overflow-y: auto;
}

/* --- En-tête de module ---------------------------------------------------- */
.module-header { margin-bottom: 18px; max-width: 1100px; }
.module-titleline { display: flex; align-items: center; gap: 11px; }
.module-icon { font-size: 26px; }
.module-header h2 { margin: 0; font-size: 23px; letter-spacing: -.01em; }
.module-intro { margin: 8px 0 0; color: var(--ink-soft); max-width: 760px; font-size: 14px; }

/* --- Grille module : entrées / résultats ---------------------------------- */
.module-grid {
  display: grid; grid-template-columns: minmax(340px, 1fr) minmax(340px, 1.05fr);
  gap: 22px; align-items: start; max-width: 1180px;
}
@media (max-width: 920px) { .module-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
  margin-bottom: 18px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--primary-dark); margin-bottom: 12px; padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
.panel-caption { font-weight: 700; color: var(--primary-dark); margin-bottom: 8px; }
.panel--result { background: linear-gradient(180deg, #fbfdff, #fff); }

/* --- Champs de saisie ----------------------------------------------------- */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field--wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .fields { grid-template-columns: 1fr; } }
.field-label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; font-weight: 500; }
.field-symbol { color: var(--primary); font-style: italic; font-weight: 600; }
.field-link { font-size: 11px; cursor: help; }
.field-control { display: flex; align-items: stretch; }
.field-input {
  flex: 1 1 auto; min-width: 0; font-family: inherit; font-size: 14px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); transition: border-color .12s, box-shadow .12s;
}
.field-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,116,144,.12); }
.field-unit {
  display: inline-flex; align-items: center; padding: 0 10px; margin-left: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px; color: var(--ink-soft); white-space: nowrap;
}
.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* --- Résultats ------------------------------------------------------------ */
.result {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 9px 4px; border-bottom: 1px dashed var(--line); flex-wrap: wrap;
}
.result:last-child { border-bottom: 0; }
.result--strong {
  background: var(--primary-soft); border-radius: 8px; padding: 11px 12px;
  margin: 4px 0; border-bottom: 0;
}
.result-label { color: var(--ink-soft); font-size: 13.5px; display: flex; align-items: baseline; gap: 7px; }
.result-symbol { color: var(--primary); font-style: italic; font-size: 12.5px; }
.result-value { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.result-num { font-weight: 700; font-size: 15.5px; font-variant-numeric: tabular-nums; }
.result--strong .result-num { color: var(--primary-dark); font-size: 17px; }
.result-formula { flex-basis: 100%; font-size: 11.5px; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }

/* --- Tableaux ------------------------------------------------------------- */
.table-wrap, .grid-wrap { overflow-x: auto; margin-top: 14px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table caption { text-align: left; font-weight: 700; color: var(--primary-dark); padding: 4px 0 9px; }
.data-table th, .data-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #f8fafc; }
.data-table td { font-variant-numeric: tabular-nums; }
.data-table tr:last-child td { border-bottom: 0; }
.row--hl td { background: var(--warn-bg); font-weight: 600; }
.cell--muted { color: var(--muted); }
.grid-table .grid-input {
  width: 90px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px;
  font-family: inherit; font-size: 13px;
}
.grid-table .grid-input:focus { outline: none; border-color: var(--primary); }

/* --- Graphique ------------------------------------------------------------ */
.chart { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 6px; background: #fff; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

/* --- Notes ---------------------------------------------------------------- */
.note {
  margin-top: 14px; padding: 11px 13px; background: var(--warn-bg);
  border-left: 3px solid var(--warn); border-radius: 6px; font-size: 13px; color: #7c2d12;
}

/* --- Références ----------------------------------------------------------- */
.dn-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.dn-chip {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 9px; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink-soft);
}

/* --- Récapitulatif -------------------------------------------------------- */
.recap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; max-width: 1100px; }
.recap-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.recap-card h3 { margin: 0 0 10px; font-size: 15px; color: var(--primary-dark); }
.recap-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; transition: opacity .25s, transform .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Thème sombre --------------------------------------------------------- */
[data-theme="sombre"] {
  --bg: #0b1220; --surface: #111a2b; --ink: #e5eef7; --ink-soft: #9fb3c8;
  --muted: #64748b; --line: #1e293b; --primary: #22d3ee; --primary-dark: #0e7490;
  --primary-soft: #0c2230; --accent: #60a5fa; --ok-bg: #052e1a; --warn-bg: #3a2a08;
  --bad-bg: #3a1212; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.4);
}
[data-theme="sombre"] .data-table th { background: #0c1626; }
[data-theme="sombre"] .field-input, [data-theme="sombre"] .grid-input,
[data-theme="sombre"] .search-input { background: #0c1626; color: var(--ink); }
[data-theme="sombre"] .topbar { background: linear-gradient(90deg, #06222b, #0a3543); }
[data-theme="sombre"] .panel--result { background: linear-gradient(180deg, #0e1828, #111a2b); }

/* --- Barre de recherche + sidebar ---------------------------------------- */
.sidebar-wrap {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--top-h)); position: sticky; top: var(--top-h);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sidebar-wrap .sidebar { width: 100%; flex: 1 1 auto; border-right: 0; position: static; height: auto; }
.search-box { padding: 12px 12px 6px; }
.search-input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; font-size: 13.5px; background: #fff; color: var(--ink);
}
.search-input:focus { outline: none; border-color: var(--primary); }

/* --- Sélecteur de langue -------------------------------------------------- */
.lang-select {
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
  color: #fff; border-radius: 8px; padding: 6px 8px; font-size: 13px; cursor: pointer;
}
.lang-select option { color: #0f172a; }

/* --- Menus déroulants ----------------------------------------------------- */
.dropdown { position: relative; display: inline-block; }
.menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); min-width: 210px; padding: 6px; overflow: hidden;
}
.dropdown.open .menu { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: none; border: 0; padding: 9px 11px; border-radius: 7px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; color: var(--ink);
}
.menu-item:hover { background: var(--bg); }

/* --- RTL (arabe) ---------------------------------------------------------- */
[dir="rtl"] .sidebar-wrap { border-right: 0; border-left: 1px solid var(--line); }
[dir="rtl"] .result-value { margin-left: 0; margin-right: auto; }
[dir="rtl"] .menu { right: auto; left: 0; }
[dir="rtl"] .field-unit { margin-left: 0; margin-right: 6px; }
[dir="rtl"] .brand-sub { border-left: 0; border-right: 1px solid rgba(255,255,255,.35); padding-left: 0; padding-right: 10px; }
[dir="rtl"] .nav-item, [dir="rtl"] .menu-item { text-align: right; }
[dir="rtl"] .data-table th, [dir="rtl"] .data-table td { text-align: right; }

/* --- Profil en long (canvas large) ---------------------------------------- */
.profil-chart { width: 100%; }

/* --- Impression ----------------------------------------------------------- */
@media print {
  :root { --top-h: 0px; }
  body { background: #fff; font-size: 11.5px; }
  .no-print, .sidebar, .topbar { display: none !important; }
  .layout { display: block; }
  .content { height: auto; overflow: visible; padding: 0; }
  .module-grid { display: block; max-width: none; }
  .panel, .recap-card { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
  .col-result { width: 100%; }
  .module-header h2 { font-size: 18px; }
  a[href]:after { content: ""; }
}

/* --- Note de calcul (rapport imprimable) ---------------------------------- */
.report { display: none; }
.report-cover { text-align: center; padding: 28mm 0; }
.report-logo { color: var(--primary-dark); font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.report h1 { font-size: 26px; margin: 18px 0 6px; }
.report-projet { font-size: 20px; color: var(--ink); }
.report-meta { margin-top: 26mm; font-size: 13px; color: var(--ink-soft); display: flex; gap: 40px; justify-content: center; }
.report-section { margin-bottom: 14px; }
.report-section h2 { font-size: 15px; border-bottom: 2px solid var(--primary); padding-bottom: 4px; margin: 16px 0 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table td { padding: 4px 8px; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.report-val { text-align: right; font-weight: 700; white-space: nowrap; }
.report-formula { color: #9ca3af; font-family: ui-monospace, Menlo, monospace; font-size: 10.5px; }

@media print {
  .report { display: block; color: #111; }
  body.printing-report > #app { display: none !important; }
  .report-cover { page-break-after: always; }
  .report-section { page-break-inside: avoid; }
}
