/* Drafting-table look: paper background with a faint grid, blueprint blue,
   tabular numbers. Semantic colours for checks (ok / warn / fail). */
:root {
  --paper: #f3f5f8;
  --grid: rgba(0, 114, 161, 0.05);
  --card: #ffffff;
  --ink: #142033;
  --muted: #5d6a7e;
  --line: #dbe2ec;
  --line-strong: #c3cddb;
  --blue: #0072a1;
  --orange: #f68846;
  --brand-grey: #5c5c63;
  --blue-soft: #e3f1f8;
  --navy: #2b2c31;
  --navy-2: #3a3b41;
  --ok: #15803d;
  --ok-bg: #e7f6ec;
  --warn: #a16207;
  --warn-bg: #fdf4dc;
  --fail: #b91c1c;
  --fail-bg: #fde8e8;
  --key: #f5f7fb;
  --fn: #e8edf5;
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 27, 46, 0.06), 0 8px 24px rgba(15, 27, 46, 0.06);
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --fast: 140ms;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2 { margin: 0; }
a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: var(--navy); color: #eef3fa;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 250px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background:
    linear-gradient(135deg, transparent 50%, var(--orange) 50%),
    linear-gradient(135deg, #0a86b8, var(--blue));
}
.brand-title { display: block; font-size: 16px; font-weight: 650; letter-spacing: 0.1px; }
.sub { display: block; font-size: 12px; color: #93a4bd; }
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid #4a4b52;
  background: var(--navy-2); color: #fff; font: inherit; font-size: 14px; outline: none;
  transition: border-color var(--fast), background var(--fast);
}
.search input::placeholder { color: #8394ad; }
.search input:focus { border-color: var(--orange); background: #44454c; }
.status {
  margin-left: auto; font-size: 13px; color: #c9d4e3; white-space: nowrap;
  padding: 6px 12px; border: 1px solid #4a4b52; border-radius: 999px;
}
.install {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  border: 0; border-radius: 999px; padding: 7px 14px 7px 8px; cursor: pointer;
  background: var(--orange); color: #fff; font: inherit; font-size: 13px; font-weight: 600;
  transition: transform var(--fast), background var(--fast);
}
.install img { border-radius: 5px; background: #fff; }
.install:hover { background: #e67632; transform: translateY(-1px); }
@media (display-mode: standalone), (display-mode: window-controls-overlay) { .install { display: none; } }
.status::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e; margin-right: 8px; vertical-align: middle; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}
.status.off::before { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 56px); }
.sidebar {
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
  padding: 16px 12px 32px; background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line); backdrop-filter: blur(6px);
}
.nav-home, .nav-item {
  display: block; padding: 7px 10px; border-radius: var(--radius-sm); text-decoration: none;
  font-size: 14px; color: var(--ink); line-height: 1.3;
  transition: background var(--fast), color var(--fast);
}
.nav-home { font-weight: 600; margin-bottom: 6px; }
.nav-item:hover, .nav-home:hover { background: var(--blue-soft); }
.nav-item.active, .nav-home.active { background: var(--blue); color: #fff; }
.nav-item:focus-visible, .nav-home:focus-visible, .btn:focus-visible, .k:focus-visible, .tile:focus-visible {
  outline: 2px solid var(--orange); outline-offset: 2px;
}
.nav-group { margin-top: 14px; }
.nav-cat {
  font-size: 11px; font-weight: 700; letter-spacing: 0.9px; text-transform: uppercase;
  color: var(--muted); padding: 0 10px 6px;
}
main { padding: 28px 32px 48px; min-width: 0; }
.view { max-width: 1240px; margin: 0 auto; animation: rise 220ms ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

/* ---------- home ---------- */
.hero { padding: 6px 0 22px; max-width: 760px; }
.hero h1 { font-size: 30px; line-height: 1.15; letter-spacing: -0.4px; }
.hero p { color: var(--muted); font-size: 16px; line-height: 1.5; margin: 10px 0 0; }
.group-title {
  display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.9px; text-transform: uppercase; color: var(--blue);
}
.group-title .count { color: var(--muted); font-weight: 500; letter-spacing: 0; text-transform: none; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tile {
  display: block; text-decoration: none; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(15, 27, 46, 0.04);
  transition: transform var(--fast), box-shadow var(--fast), border-color var(--fast);
  border-left: 3px solid var(--blue);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-strong); border-left-color: var(--orange); }
.tile-title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.tile-sum { color: var(--muted); font-size: 13px; line-height: 1.4; margin-top: 6px; }
.empty { color: var(--muted); }

/* ---------- engineering view ---------- */
.eng-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.crumb { font-size: 12px; font-weight: 700; letter-spacing: 0.9px; text-transform: uppercase; color: var(--blue); }
.eng-head h1 { font-size: 26px; line-height: 1.2; margin-top: 4px; letter-spacing: -0.3px; }
.lead { color: var(--muted); margin: 6px 0 0; max-width: 680px; line-height: 1.45; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: var(--radius-sm); padding: 8px 12px; font: inherit; font-size: 13px; cursor: pointer;
  transition: background var(--fast), border-color var(--fast), transform var(--fast);
}
.btn:hover { background: var(--blue-soft); border-color: #9cc9de; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #005d85; }
.btn.on { background: #fff7d6; border-color: #e7c65a; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 20px;
}
.eng-body { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.1fr); gap: 20px; align-items: start; }
.eng-side { display: grid; gap: 20px; position: sticky; top: 76px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.f-label { font-weight: 600; color: var(--ink); font-size: 13px; }
.opt { font-weight: 400; color: var(--muted); }
.project { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px dashed var(--line-strong); }
.input-wrap { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; transition: border-color var(--fast), box-shadow var(--fast); }
.input-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 114, 161, 0.18); }
.input-wrap.bad { border-color: var(--fail); }
.input-wrap input, .input-wrap textarea {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent; padding: 9px 10px;
  font: inherit; font-size: 15px; color: var(--ink); font-family: var(--mono);
}
.input-wrap textarea { resize: vertical; min-height: 70px; }
.unit {
  display: flex; align-items: center; padding: 0 10px; font-size: 13px; color: var(--muted);
  background: #f6f8fb; border-left: 1px solid var(--line); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: nowrap;
}
.field select, .project input, .conv select, .conv input {
  font: inherit; font-size: 15px; padding: 9px 10px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: #fff; color: var(--ink); outline: none;
}
.field select:focus, .project input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 114, 161, 0.18); }
.help { font-size: 12px; line-height: 1.35; color: var(--muted); }
.wide { grid-column: 1 / -1; }
.link { border: 0; background: none; color: var(--blue); cursor: pointer; font: inherit; font-size: 13px; padding: 0; margin-top: 16px; }
.link:hover { text-decoration: underline; }

.results h2, .method h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--muted); margin-bottom: 12px; }
.main-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.metric { background: linear-gradient(180deg, #f6fafc, #eaf4f9); border: 1px solid #cfe3ee; border-radius: var(--radius); padding: 12px 14px; }
.metric-label { font-size: 12px; color: var(--muted); line-height: 1.3; }
.metric-value { font-family: var(--mono); font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.metric-unit { font-size: 13px; color: var(--muted); font-family: var(--sans); font-weight: 500; margin-left: 4px; }
.checks { display: grid; gap: 8px; margin-bottom: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.35; }
.check::before { font-weight: 800; flex: none; }
.check.ok { background: var(--ok-bg); color: var(--ok); }
.check.ok::before { content: "✓"; }
.check.warn { background: var(--warn-bg); color: var(--warn); }
.check.warn::before { content: "!"; }
.check.fail { background: var(--fail-bg); color: var(--fail); }
.check.fail::before { content: "✕"; }
.out-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.out-table td { padding: 7px 4px; border-top: 1px solid var(--line); }
.out-table td.v { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.out-table td.u { color: var(--muted); width: 1%; white-space: nowrap; padding-left: 8px; }
.notes { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.error { background: var(--fail-bg); color: var(--fail); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 12px; }
.formulas { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.formulas li { font-family: var(--mono); font-size: 14px; background: #f6f8fb; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 10px; }
.ref { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.print-meta { display: none; }

/* ---------- tools ---------- */
.tool-title { font-size: 26px; margin-bottom: 18px; letter-spacing: -0.3px; }
.panel { display: flex; gap: 20px; align-items: flex-start; }
.calc { flex: 1 1 640px; min-width: 0; }
.display { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; text-align: right; }
.line-prev { color: var(--muted); font-size: 14px; min-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expr { width: 100%; border: 0; background: transparent; text-align: right; font-size: 34px; font-weight: 500; color: var(--ink); outline: none; font-family: var(--mono); padding: 4px 0; }
.preview { color: var(--muted); font-size: 16px; min-height: 22px; }
.preview.err { color: var(--fail); }
.keys { display: grid; grid-template-columns: 3fr 4fr; gap: 14px; }
.sci { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-content: start; }
.num { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.num .eq { grid-column: span 2; }
.k { border: 1px solid var(--line); background: var(--key); color: var(--ink); border-radius: 9px; font-size: 18px; height: 52px; cursor: pointer; font-family: inherit; transition: background var(--fast); }
.k:hover { background: #e8edf5; }
.k:active { transform: translateY(1px); }
.k.fn { background: var(--fn); font-size: 15px; height: 46px; }
.k.op { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.k.eq { background: var(--blue); color: #fff; border-color: var(--blue); font-size: 22px; }
.k.danger { background: var(--fail-bg); color: var(--fail); font-weight: 600; }
.history { flex: 0 0 300px; max-height: calc(100vh - 180px); display: flex; flex-direction: column; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head .link { margin: 0; }
.history h2 { font-size: 15px; }
.hist-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.hist-list li { padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; text-align: right; border-radius: 6px; }
.hist-list li:hover { background: var(--key); }
.hist-expr { color: var(--muted); font-size: 13px; word-break: break-all; }
.hist-val { font-size: 17px; font-weight: 600; font-family: var(--mono); }
.hint { color: var(--muted); font-size: 13px; }
.conv { max-width: 820px; }
.conv .field { margin-bottom: 12px; }
.conv-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1; }
.swap { height: 42px; margin-bottom: 12px; }
.conv-result { font-size: 28px; font-weight: 650; padding: 10px 0 16px; text-align: right; font-family: var(--mono); }
.conv-result.err { color: var(--fail); font-size: 16px; }
.conv-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.conv-table td { padding: 7px 8px; border-top: 1px solid var(--line); }
.conv-table td:last-child { text-align: right; font-family: var(--mono); }
.conv-table .unit-name { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .eng-body { grid-template-columns: 1fr; }
  .eng-side { position: static; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { min-width: 0; }
  .sub, .status { display: none; }
  main { padding: 20px 16px 40px; }
  .panel { flex-direction: column; align-items: stretch; }
  .history { flex: none; max-height: 320px; }
}
@media (max-width: 560px) {
  .keys { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
}

/* ---------- print report (built by eng.js, one A4 page) ---------- */
.logo-img { height: 38px; max-width: 170px; object-fit: contain; background: #fff; border-radius: 7px; padding: 4px 8px; }
.print-report { display: none; }
@page { size: A4; margin: 12mm; }
@media print {
  body { background: #fff; }
  .topbar, .sidebar, .toast { display: none !important; }
  .layout { display: block; }
  .view { animation: none; }
  body.print-eng > *:not(.print-report) { display: none !important; }
  body.print-eng .print-report { display: block; }
}
.print-report { font-family: var(--sans); color: #111; font-size: 9.5pt; line-height: 1.3; }
.pr-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--blue); padding-bottom: 6px; }
.pr-brand { display: flex; align-items: center; gap: 10px; }
.pr-brand img { max-height: 34px; max-width: 160px; object-fit: contain; }
.pr-mark { width: 26px; height: 26px; border-radius: 6px; background: linear-gradient(135deg, #0a86b8, var(--blue)); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pr-org { font-weight: 700; font-size: 12pt; }
.pr-doc { color: #555; font-size: 8.5pt; }
.pr-meta { text-align: right; font-size: 8.5pt; color: #333; }
.pr-title { margin: 8px 0 2px; font-size: 14pt; font-weight: 700; }
.pr-cat { font-size: 8pt; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--blue); margin-top: 8px; }
.pr-sum { color: #444; margin: 0 0 8px; }
.pr-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pr-box { border: 1px solid #c9d1dc; border-radius: 6px; padding: 6px 8px; break-inside: avoid; }
.pr-box h3 { margin: 0 0 4px; font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.8px; color: #555; }
.pr-table { width: 100%; border-collapse: collapse; }
.pr-table td { padding: 2px 3px; border-top: 1px solid #e3e7ee; vertical-align: top; }
.pr-table tr:first-child td { border-top: 0; }
.pr-table td.v { text-align: right; font-family: var(--mono); white-space: nowrap; }
.pr-table td.u { color: #555; white-space: nowrap; width: 1%; }
.pr-table tr.main td { font-weight: 700; background: #e3f1f8; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pr-check { padding: 2px 6px; border-radius: 4px; margin-top: 3px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pr-check.ok { background: var(--ok-bg); color: var(--ok); }
.pr-check.warn { background: var(--warn-bg); color: var(--warn); }
.pr-check.fail { background: var(--fail-bg); color: var(--fail); }
.pr-method { margin-top: 10px; }
.pr-formulas { font-family: var(--mono); font-size: 8.5pt; }
.pr-formulas span { display: inline-block; margin: 2px 10px 2px 0; }
.pr-notes { margin: 4px 0 0; padding-left: 14px; color: #444; }
.pr-foot { margin-top: 10px; border-top: 1px solid #c9d1dc; padding-top: 4px; font-size: 7.5pt; color: #666; display: flex; justify-content: space-between; gap: 10px; }
.pr-sign { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; font-size: 8.5pt; color: #444; }
.pr-sign div { border-top: 1px solid #999; padding-top: 3px; }
.dim { opacity: 0.4; }
