/* QRme Measure — trade converter.
   Same palette and type as QRme Suite and QRme Kitchen (deep teal + warm parchment).
   Built for a phone on a job site: big inputs, big numbers, sticky section links. */

:root {
  --ink: #1a2b2a;
  --ink-soft: #3d5250;
  --muted: #6b7f7c;
  --line: #d5e0dd;
  --line-strong: #b8c9c5;
  --paper: #f7f4ef;
  --paper-raised: #fffcf7;
  --surface: #eef4f2;
  --teal: #0d5c56;
  --teal-deep: #084742;
  --teal-soft: #c4e8e2;
  --teal-mist: #e8f5f3;
  --accent: #c45c26;
  --accent-soft: #f5e6dc;
  --danger: #9b2c2c;
  --ok: #1f6b3a;
  --shadow: 0 1px 2px rgba(26, 43, 42, 0.06), 0 8px 24px rgba(26, 43, 42, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Figtree", system-ui, -apple-system, sans-serif;
  --serif: "Literata", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --topbar-h: 58px;
  --nav-h: 48px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + var(--nav-h) + 12px); scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
html, body { margin: 0; padding: 0; font-family: var(--font); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; font-size: 16px; line-height: 1.45; }

[hidden] { display: none !important; }

.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; }
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--teal); color: #fff; padding: 0.5rem 1rem; z-index: 100; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
em.muted { font-style: normal; font-weight: 500; }
.small { font-size: 0.84rem; }
a { color: var(--teal); }
code { font-family: var(--mono); font-size: 0.86em; background: var(--surface); padding: 0.05rem 0.32rem; border-radius: 4px; color: var(--teal-deep); white-space: nowrap; }

/* —— Top bar —— */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  height: var(--topbar-h); padding: 0 1.25rem;
  background: var(--paper-raised); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark img { display: block; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.08rem; font-weight: 700; letter-spacing: -0.02em; }
.brand-tag { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.quiet-link { color: var(--muted); font-size: 0.84rem; font-weight: 600; text-decoration: none; }
.quiet-link:hover { color: var(--teal); text-decoration: underline; }

/* —— Sticky section links —— */
.section-nav {
  position: sticky; top: var(--topbar-h); z-index: 25;
  background: rgba(247, 244, 239, 0.94); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.section-nav-inner {
  max-width: 1080px; margin: 0 auto; height: var(--nav-h);
  display: flex; align-items: center; gap: 0.35rem; padding: 0 1.25rem;
  overflow-x: auto; scrollbar-width: none;
}
.section-nav-inner::-webkit-scrollbar { display: none; }
.section-nav a {
  flex: 0 0 auto; text-decoration: none; color: var(--ink-soft); font-size: 0.88rem; font-weight: 600;
  padding: 0.38rem 0.85rem; border-radius: 999px; border: 1px solid var(--line); background: var(--paper-raised);
}
.section-nav a:hover { border-color: var(--teal); color: var(--teal); }
.section-nav a.on { background: var(--teal); border-color: var(--teal); color: #fff; }

/* —— Layout —— */
.main { max-width: 1080px; margin: 0 auto; padding: 1.25rem 1.25rem 2.5rem; outline: none; }
.panel {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.3rem 1.4rem 1.45rem; margin-bottom: 1.1rem;
}
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.8rem 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.step { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--accent); }
.panel h1, .panel h2 { margin: 0.1rem 0 0; font-family: var(--serif); font-weight: 600; font-size: 1.5rem; letter-spacing: -0.01em; line-height: 1.2; }
.hero h1 { font-size: 1.75rem; }
.sub-head { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 1.3rem 0 0.6rem; padding-top: 1rem; border-top: 1px dashed var(--line); font-weight: 700; }
.sub-head.first { margin-top: 0.2rem; padding-top: 0; border-top: none; }
.hint { color: var(--ink-soft); font-size: 0.92rem; margin: 0 0 0.9rem; }
.fine { color: var(--muted); font-size: 0.8rem; margin: 0.8rem 0 0; line-height: 1.5; }

/* —— Buttons —— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 1px solid transparent; border-radius: 999px; padding: 0.55rem 1rem; min-height: 40px;
  font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-secondary { background: var(--teal-mist); color: var(--teal-deep); border-color: var(--teal-soft); }
.btn-secondary:hover { background: var(--teal-soft); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface); color: var(--ink); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted); font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: #f6e3e3; color: var(--danger); border-color: #ecc9c9; }
.chip {
  font: inherit; font-size: 0.84rem; font-weight: 600; color: var(--teal-deep); cursor: pointer;
  background: var(--teal-mist); border: 1px solid var(--teal-soft); border-radius: 999px; padding: 0.3rem 0.75rem; min-height: 34px;
}
.chip:hover { background: var(--teal-soft); }
.row-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* —— Fields —— */
.field-grid { display: grid; gap: 0.8rem 0.9rem; }
.field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-grid.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 0.28rem; min-width: 0; }
.field > span { font-size: 0.78rem; font-weight: 600; color: var(--ink-soft); }
.field.grow { flex: 1 1 auto; }
input[type="text"], input[type="number"], input:not([type]), select {
  font: inherit; font-size: 1.05rem; color: var(--ink); width: 100%; min-width: 0; min-height: 46px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 9px; padding: 0.55rem 0.7rem;
  font-variant-numeric: tabular-nums; transition: border-color 0.15s, box-shadow 0.15s;
}
select { appearance: none; -webkit-appearance: none; padding-right: 1.8rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 92, 86, 0.15); }
input.bad { border-color: var(--danger); background: #fdf3f3; box-shadow: 0 0 0 2px rgba(155, 44, 44, 0.12); }
input::placeholder { color: #a3b2af; }
.inline-fields { display: flex; gap: 0.6rem; align-items: flex-end; }
.inline-fields .field:last-child { flex: 0 0 8.5rem; }

.unit-toggle { border: 1px solid var(--line); margin: 0; display: inline-flex; align-items: center; flex-wrap: wrap; background: var(--surface); border-radius: 999px; padding: 3px; }
.unit-toggle legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.unit-toggle label { position: relative; cursor: pointer; }
.unit-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.unit-toggle span { display: block; padding: 0.42rem 0.95rem; border-radius: 999px; font-size: 0.9rem; font-weight: 600; color: var(--ink-soft); }
.unit-toggle .toggle-label { font-size: 0.74rem; color: var(--muted); padding: 0 0.5rem 0 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }
.unit-toggle input:checked + span { background: var(--teal); color: #fff; }
.unit-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* —— Length hero —— */
.len-entry { position: relative; display: flex; gap: 0.5rem; align-items: stretch; }
.big-input {
  font-size: clamp(1.6rem, 6vw, 2.3rem) !important; font-weight: 700; letter-spacing: -0.01em;
  min-height: 68px !important; padding: 0.55rem 0.95rem !important; border-width: 2px !important; border-radius: 12px !important;
}
.clear-btn { flex: 0 0 auto; }
.len-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.6rem 1rem; margin-top: 0.75rem; }
.examples { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.read-as { margin: 0.75rem 0 0; min-height: 1.4em; font-size: 0.92rem; color: var(--teal-deep); font-weight: 600; }
.read-as.bad { color: var(--danger); }

.result-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; margin-top: 0.8rem; }
.result {
  position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem 0.8rem; min-height: 92px; display: flex; flex-direction: column; gap: 0.15rem;
}
.result-main { background: var(--teal-deep); border-color: var(--teal-deep); color: #fff; }
.result-main .r-label, .result-main .r-note { color: var(--teal-soft); }
.result-main .r-value { color: #fff; }
.r-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; padding-right: 4rem; }
.r-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--teal-deep); word-break: break-word; line-height: 1.2; }
.r-note { font-size: 0.8rem; color: var(--muted); }
.copy {
  position: absolute; top: 0.55rem; right: 0.55rem; font: inherit; font-size: 0.74rem; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper-raised); color: var(--ink-soft); border-radius: 999px; padding: 0.22rem 0.6rem;
}
.copy:hover { border-color: var(--teal); color: var(--teal); }
.result-main .copy { background: rgba(255, 255, 255, 0.1); border-color: rgba(196, 232, 226, 0.35); color: #e8f5f3; }
.copy:disabled { opacity: 0.4; cursor: default; }

/* —— Tables —— */
.table-wrap { position: relative; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow-x: auto; background: #fff; }
.table-wrap.scroll-x { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  background: var(--surface); color: var(--ink-soft); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); font-weight: 700; white-space: nowrap;
}
.data-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid #e8eeec; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; }
.data-table tfoot td { background: var(--teal-mist); border-top: 1px solid var(--line); padding: 0.65rem 0.6rem; }
.data-table tr.hl td { background: var(--teal-mist); font-weight: 700; }
.nearest-table td:nth-child(2) { font-weight: 700; color: var(--teal-deep); font-size: 1.05rem; }
.kitchen-table td input, .wire-rows td input, .wire-rows td select { min-height: 42px; font-size: 1rem; padding: 0.4rem 0.55rem; }
.kitchen-table td:first-child { color: var(--muted); font-weight: 700; width: 2.2rem; }
.c-qty { width: 5.2rem; }
.c-act { width: 2.8rem; text-align: center; }
.sqft { font-weight: 700; color: var(--teal-deep); }
.u-label { text-transform: none; letter-spacing: 0; color: var(--muted); }
.tfoot-label { text-align: right; color: var(--teal-deep); font-weight: 700; }
#k-total { font-size: 1.15rem; color: var(--teal-deep); }

/* —— Unit lists and stats —— */
.unit-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.45rem; }
.unit-list li { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 0.45rem 0.7rem; display: flex; flex-direction: column; }
.unit-list li.muted { background: transparent; border-style: dashed; grid-column: 1 / -1; }
.unit-list b { font-size: 1.12rem; color: var(--teal-deep); font-variant-numeric: tabular-nums; word-break: break-all; }
.unit-list small { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.unit-list li.src { border-color: var(--teal-soft); background: var(--teal-mist); }
.pair-results { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.9rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.4rem; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; margin-top: 0.9rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.6rem 0.85rem; display: flex; flex-direction: column; }
.stat output { font-size: 1.4rem; font-weight: 700; color: var(--teal-deep); font-variant-numeric: tabular-nums; }
.stat-main { background: var(--teal-deep); border-color: var(--teal-deep); }
.stat-main .r-label { color: var(--teal-soft); }
.stat-main output { color: #fff; }

/* —— Electrical —— */
.sub-nav { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.sub-nav a { font-size: 0.8rem; font-weight: 600; text-decoration: none; color: var(--teal-deep); padding: 0.25rem 0.6rem; border-radius: 999px; background: var(--teal-mist); border: 1px solid var(--teal-soft); }
.code-note {
  background: var(--accent-soft); border: 1px solid rgba(196, 92, 38, 0.38); color: #5d2a10;
  border-radius: var(--radius-sm); padding: 0.8rem 1rem; font-size: 0.9rem; line-height: 1.5;
}
.code-note strong { display: block; color: var(--accent); margin-bottom: 0.15rem; }
.tool { border-top: 1px dashed var(--line-strong); margin-top: 1.4rem; padding-top: 1.2rem; }
.tool-h { margin: 0 0 0.8rem; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.tag { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; padding: 0.18rem 0.55rem; border-radius: 999px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0.8rem 0 0; font-variant-numeric: tabular-nums; }
.facts dt { color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.facts dd { margin: 0; font-weight: 700; color: var(--teal-deep); }
.facts dd small { font-weight: 500; color: var(--muted); }
.facts-line { margin: 0.8rem 0 0; font-weight: 600; color: var(--teal-deep); }
.ref-table { margin-top: 0.9rem; }
.ref-table summary { cursor: pointer; font-weight: 700; color: var(--teal); font-size: 0.9rem; margin-bottom: 0.5rem; }
.flag { margin: 0.7rem 0 0; padding: 0.55rem 0.85rem; border-radius: 9px; font-weight: 600; font-size: 0.9rem; }
.flag.warn { background: #fbeee6; color: #8a3d16; border: 1px solid #ecc8b3; }
.flag.good { background: #e7f3ea; color: var(--ok); border: 1px solid #bcdcc5; }
.cond-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.6rem; margin-top: 0.9rem; padding: 0.75rem; background: var(--surface); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.cond-grid .field > span { font-size: 0.76rem; }
.meter { height: 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); margin-top: 1rem; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--teal); transition: width 0.2s; }
.meter-fill.over { background: var(--danger); }

.foot { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; justify-content: center; text-align: center; padding: 1.2rem 0 0.4rem; font-size: 0.84rem; color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 0.6rem 1.1rem; border-radius: 999px; font-size: 0.9rem; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); z-index: 50;
}

/* —— Phone —— */
@media (max-width: 820px) {
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col, .pair-results { grid-template-columns: 1fr; }
  .cond-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 540px) {
  :root { --topbar-h: 54px; }
  .topbar { padding: 0 0.9rem; }
  .topbar .quiet-link { display: none; }
  .section-nav-inner { padding: 0 0.9rem; }
  .main { padding: 0.8rem 0.6rem 2rem; }
  .panel { padding: 1rem 0.9rem 1.1rem; border-radius: 12px; }
  .hero h1 { font-size: 1.45rem; }
  .result-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .result-main { grid-column: 1 / -1; }
  .r-value { font-size: 1.35rem; }
  .result-main .r-value { font-size: 1.9rem; }
  .unit-toggle .toggle-label { display: none; }
  .unit-toggle span { padding: 0.45rem 0.8rem; }
  .data-table th, .data-table td { padding-left: 0.4rem; padding-right: 0.4rem; }
  .kitchen-table td input { padding: 0.4rem; }
  .cond-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table th { white-space: normal; font-size: 0.66rem; }
  .c-qty { width: 4.4rem; }
  .c-act { width: 2.4rem; }
  .wire-rows td:nth-child(3) { font-size: 0.85rem; }
  .inline-fields .field:last-child { flex-basis: 7rem; }
}

@media print {
  .topbar, .section-nav, .copy, .row-actions, .clear-btn, .examples, .toast { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; break-inside: avoid; }
}

@media (max-width: 380px) {
  .result-grid { grid-template-columns: 1fr; }
  .field-grid.four, .field-grid.five { grid-template-columns: 1fr; }
}
.result { min-width: 0; }
