:root {
  /* Light drafting-paper palette, matched to the rest of the RetubeCo site */
  --bp-0: #eef1f5;
  --bp-1: #ffffff;
  --bp-2: #f5f7fa;
  --bp-3: #e7ecf2;
  --line: #ccd4de;
  --line-soft: #e3e8ee;
  --text: #1f2430;
  --text-dim: #5b6472;
  --text-faint: #86929f;
  --cad: #1f5fa8;
  --cad-dim: #e8f0fa;
  --cyan: #0e7c86;
  --dim: #b3541e;
  --metal-lt: #eef2f6;
  --metal: #c3ccd7;
  --metal-dk: #3d4c5d;
  --good: #2f9e6e;
  --warn: #c2703d;
  --bad: #c94f6d;
  --radius: 10px;
  --brand-yellow: #f4b400;
  --brand-black: #1a1a1a;
  --mono: "Consolas", "SF Mono", "Roboto Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  line-height: 1.45;
  background-color: var(--bp-0);
  /* Drafting grid: fine 10px mesh over a heavier 50px mesh. */
  background-image:
    linear-gradient(rgba(31, 95, 168, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 95, 168, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(31, 95, 168, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 95, 168, 0.09) 1px, transparent 1px);
  background-size: 10px 10px, 10px 10px, 50px 50px, 50px 50px;
}

/* ---------- Header ---------- */
.app-header {
  background: var(--brand-black);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 4px solid var(--brand-yellow);
}
.back-to-hub {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  font-family: var(--mono);
}
.back-to-hub:hover { color: white; }
.app-logo { height: 42px; background: white; padding: 5px 9px; border-radius: 4px; flex-shrink: 0; }
.app-header-text { flex: 1; min-width: 0; }
.app-header h1 { margin: 0 0 2px; font-size: 1.25rem; }
.app-header .subtitle { margin: 0; opacity: 0.85; font-size: 0.85rem; }
.powered-by { margin-left: auto; flex-shrink: 0; display: flex; align-items: center; gap: 8px; }
.powered-by-label {
  font-size: 0.68rem; color: rgba(255, 255, 255, 0.55); text-transform: uppercase;
  letter-spacing: 0.05em; white-space: nowrap; font-family: var(--mono);
}
.erogn-logo { height: 26px; width: auto; border-radius: 3px; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1280px;
  margin: 22px auto 40px;
  padding: 0 20px;
  gap: 22px;
  min-width: 0;
}
.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--bp-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  position: sticky;
  top: 14px;
}
.nav-group {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  padding: 13px 9px 6px;
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
}
.nav-group:first-child { padding-top: 5px; border-top: none; margin-top: 0; }
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  font: inherit;
  font-size: 0.87rem;
  color: var(--text-dim);
  padding: 7px 10px;
  border-radius: 0 7px 7px 0;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bp-2); color: var(--text); }
.nav-item.active {
  background: var(--cad-dim);
  color: var(--cad);
  font-weight: 600;
  border-left-color: var(--cad);
}

.content { flex: 1; min-width: 0; }

.tool-section h2 {
  margin: 0 0 6px;
  font-size: 1.32rem;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tool-section h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line) 0%, transparent 100%);
}
.tool-desc { margin: 0 0 18px; color: var(--text-dim); font-size: 0.92rem; max-width: 78ch; }

/* ---------- Cards ---------- */
.card {
  background: var(--bp-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  position: relative;
  box-shadow: 0 1px 3px rgba(31, 40, 55, 0.05);
}
/* Corner ticks — drafting-sheet detail */
.card::before, .card::after {
  content: "";
  position: absolute;
  width: 9px; height: 9px;
  border-color: var(--cad);
  opacity: 0.45;
}
.card::before { top: -1px; left: -1px; border-top: 2px solid; border-left: 2px solid; border-radius: var(--radius) 0 0 0; }
.card::after { bottom: -1px; right: -1px; border-bottom: 2px solid; border-right: 2px solid; border-radius: 0 0 var(--radius) 0; }
.card h3 { margin: 0 0 12px; font-size: 0.95rem; color: var(--cyan); font-family: var(--mono); letter-spacing: 0.02em; }

/* ---------- Diagram ---------- */
.diagram {
  background:
    linear-gradient(rgba(31, 95, 168, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 95, 168, 0.055) 1px, transparent 1px),
    var(--bp-1);
  background-size: 12px 12px, 12px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 18px;
  overflow-x: auto;
}
.diagram svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.diagram-caption {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  text-align: center;
  margin-top: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* CAD drawing element classes used inside the SVGs */
.part { fill: #dfe5ec; stroke: var(--metal-dk); stroke-width: 1.5; }
.part-lt { fill: #f0f4f8; stroke: var(--metal-dk); stroke-width: 1.5; }
.part-dk { fill: #c8d2dd; stroke: var(--metal-dk); stroke-width: 1.5; }
.tool-body { fill: #cfd8e2; stroke: #46566a; stroke-width: 1.5; }
.tool-accent { fill: var(--brand-yellow); stroke: #8a6800; stroke-width: 1; }
.dim-line { stroke: var(--dim); stroke-width: 1.2; fill: none; }
.ext-line { stroke: var(--dim); stroke-width: 0.9; opacity: 0.6; }
.center-line { stroke: var(--cyan); stroke-width: 1; stroke-dasharray: 14 4 3 4; opacity: 0.8; }
.dim-text { fill: var(--dim); font-family: var(--mono); font-size: 12px; font-weight: 700; }
.note-text { fill: var(--text-dim); font-family: var(--mono); font-size: 11px; }
.label-text { fill: var(--cyan); font-family: var(--mono); font-size: 11px; font-weight: 700; }
.flow-arrow { stroke: var(--cad); stroke-width: 2; fill: none; }
.hot { fill: #c0392b; }
.cold { fill: var(--cad); }

/* ---------- Fields ---------- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px 18px;
}
.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.field-grid input, .field-grid select {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  width: 100%;
}
.field-grid input:focus, .field-grid select:focus {
  outline: none;
  border-color: var(--cad);
  box-shadow: 0 0 0 3px var(--cad-dim);
}

/* ---------- Results ---------- */
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.result-tile {
  background: var(--bp-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--cad);
  border-radius: 8px;
  padding: 11px 14px;
}
.result-tile .rt-label {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.result-tile .rt-value { font-size: 1.3rem; font-weight: 700; font-family: var(--mono); color: var(--text); }
.result-tile .rt-sub { font-size: 0.76rem; color: var(--text-dim); margin-top: 3px; }
.result-tile.good { border-left-color: var(--good); }
.result-tile.good .rt-value { color: var(--good); }
.result-tile.warn { border-left-color: var(--warn); }
.result-tile.warn .rt-value { color: var(--warn); }
.result-tile.bad { border-left-color: var(--bad); }
.result-tile.bad .rt-value { color: var(--bad); }

.note {
  margin: 16px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--cad-dim);
  border-left: 3px solid var(--cad);
  border-radius: 0 7px 7px 0;
  padding: 10px 13px;
}

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table-card table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 340px; }
.table-card th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cyan);
  background: var(--bp-2);
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
.table-card td {
  padding: 7px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.table-card td:first-child { color: var(--text); font-weight: 600; }
.table-card tr:last-child td { border-bottom: none; }
.table-card tbody tr:hover td { background: var(--cad-dim); color: var(--text); }
.table-card .note { margin: 0; border-radius: 0; border-left: none; border-top: 1px solid var(--line); }

/* ---------- Converters ---------- */
.converter {
  background: var(--bp-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 18px;
  margin-bottom: 13px;
  box-shadow: 0 1px 3px rgba(31, 40, 55, 0.05);
}
.converter h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cyan);
}
.conv-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.conv-row input {
  font: inherit;
  font-family: var(--mono);
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  width: 150px;
  min-width: 0;
  flex: 1 1 110px;
}
.conv-row input:focus { outline: none; border-color: var(--cad); box-shadow: 0 0 0 3px var(--cad-dim); }
.conv-row select {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  flex: 0 1 auto;
  min-width: 0;
}
.conv-eq { font-size: 1.1rem; color: var(--dim); font-family: var(--mono); flex: 0 0 auto; }

footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.76rem;
  padding: 18px;
  font-family: var(--mono);
}

.hidden { display: none !important; }

@media (max-width: 860px) {
  /* align-items must switch to stretch here: with flex-start on a column
     container, children size to their content and overflow narrow screens. */
  .layout { flex-direction: column; align-items: stretch; }
  .sidebar { width: 100%; position: static; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 10px; }
  .nav-group { grid-column: 1 / -1; }
  .app-header { flex-wrap: wrap; }
  .powered-by { margin-left: 0; }
}

@media (max-width: 520px) {
  .layout { padding: 0 12px; gap: 16px; }
  .card { padding: 16px 14px; }
  .field-grid, .results { grid-template-columns: 1fr; }
  .sidebar { grid-template-columns: 1fr; }
  .conv-row { gap: 7px; }
  .conv-row input { flex: 1 1 80px; width: auto; }
  .conv-row select { flex: 1 1 70px; font-size: 0.78rem; padding: 8px 4px; }
}
