:root {
  --bg: #0e1013;
  --panel: #161a1f;
  --panel2: #1c2128;
  --line: #2a323c;
  --text: #dde3ea;
  --muted: #8b96a3;
  --accent: #B0121B;
  --accent-dim: #7E131B;
  --green: #1E9E55;
  --green-dim: #167A41;
  --good: #6fc07a;
  --danger: #e06c5c;
  --warn: #e0b25c;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --bar-h: 56px;
  --foot-h: 72px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { background: var(--bg); color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { cursor: pointer; }
img { display: block; max-width: 100%; height: auto; }

/* ----- chrome ----- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--bar-h);
  padding: calc(8px + var(--safe-t)) 12px 8px max(12px, var(--safe-l));
  padding-right: max(12px, var(--safe-r));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.appbar .logo { height: 24px; width: auto; }
.appbar .titles { flex: 1; min-width: 0; }
.appbar .titles h1 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar .titles p { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.btn-back {
  min-width: 52px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.btn-back:active { border-color: var(--accent); color: #fff; background: var(--accent); }
.btn-back[hidden] { display: none; }

.foot {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--foot-h);
  padding: 8px max(12px, var(--safe-r)) calc(8px + var(--safe-b)) max(12px, var(--safe-l));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.menu-cube {
  margin-left: auto;
  width: 56px;
  height: 56px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.menu-cube span { background: var(--accent); border-radius: 3px; }
.menu-cube[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-dim); }
.menu-cube[aria-expanded="true"] span { background: #fff; }

.menu-pop {
  display: none;
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--foot-h) + var(--safe-b) + 8px);
  z-index: 45;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.menu-pop.open { display: block; }
.menu-pop h2 { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }

/* ----- screens ----- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--foot-h) + var(--safe-b) + 120px);
}
.screen { display: none; }
.screen.on { display: block; }

h2.sec {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
  font-weight: 800;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: 12px; }
.kicker { font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }

/* ----- 4 square tiles ----- */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tile {
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 6px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  text-align: left;
}
.tile:active, .tile:focus-visible { border-color: var(--accent); outline: none; }
.tile .ic {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  margin-bottom: auto;
}
.tile .ic.green { background: var(--green); }
.tile strong { font-size: 16px; font-weight: 800; letter-spacing: 0.02em; line-height: 1.15; }
.tile span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.tile[aria-current="page"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); max-width: 720px; }
  .tile { aspect-ratio: 1 / 1; }
  .tile strong { font-size: 15px; }
}
@media (min-width: 1100px) {
  .tiles { max-width: 640px; }
  .tile { padding: 12px; }
  .tile strong { font-size: 14px; }
}
.tiles.compact { max-width: 520px; gap: 8px; }
.tiles.compact .tile { padding: 10px 12px; }
.tiles.compact .tile .ic { width: 24px; height: 24px; font-size: 12px; }
.tiles.compact .tile strong { font-size: 14px; }
.tiles.compact .tile span { font-size: 11px; }
@media (min-width: 700px) {
  .tiles.compact { grid-template-columns: repeat(4, 1fr); max-width: 640px; }
  .tiles.compact .tile { aspect-ratio: 1 / 1; }
}

/* ----- forms ----- */
label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
}
input, select, textarea {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 10px;
  font-size: 16px; /* prevent iOS zoom */
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
.fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.fields .span2 { grid-column: 1 / -1; }
@media (min-width: 800px) {
  .fields.wide { grid-template-columns: repeat(4, 1fr); }
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.btn:active { background: var(--accent-dim); }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:active { border-color: var(--accent); color: #fff; background: var(--accent); }
.btn.green { background: var(--green); }
.btn.green:active { background: var(--green-dim); }
.btn.sm { padding: 8px 12px; font-size: 11px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.result {
  margin-top: 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.stat { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 14px; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.result .stat { border-bottom: 1px solid var(--line); }
.result .stat:last-child { border-bottom: none; }
.result .stat.hi b { color: var(--green); font-size: 18px; }
.result .stat.warn b { color: var(--danger); }

.flag {
  display: none;
  border: 1px solid var(--danger);
  background: rgba(224,108,92,.12);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}
.flag.on { display: block; }
.flag.caution { border-color: var(--warn); background: rgba(224,178,92,.12); color: var(--warn); }

/* ----- estimator items ----- */
.item {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.item .rowa, .item .rowb {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, 1fr);
  align-items: end;
}
@media (min-width: 700px) {
  .item .rowa { grid-template-columns: 1.4fr 110px 80px 80px 80px 80px 40px; }
  .item .rowb { grid-template-columns: 1.5fr 90px 100px 1.4fr 110px 80px 70px 70px; }
}
.item { position: relative; }
@media (max-width: 699px) {
  .item .del { position: absolute; top: 10px; right: 10px; width: 42px; }
}
.item .del {
  background: none;
  border: 1px solid var(--line);
  color: var(--danger);
  border-radius: 8px;
  height: 42px;
  font-size: 16px;
}
.chip { display: block; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chip b { color: var(--accent); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
th, td { padding: 8px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
td.qty { color: var(--accent); font-weight: 800; white-space: nowrap; }
tr.section td { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; padding-top: 14px; border-bottom: none; text-align: left; }
td input { width: 84px; padding: 8px 6px; font-size: 16px; text-align: right; }
td input.wide { width: 100%; text-align: left; }
tr.totalrow td { font-weight: 800; border-top: 2px solid var(--line); }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1.2fr .8fr; align-items: start; } }

.totals { font-size: 14px; }
.totals .row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.totals .row.sub { font-weight: 800; }
.totals .row.grand { border-bottom: none; font-size: 20px; font-weight: 800; color: var(--accent); padding-top: 12px; }
.totals .row.internal { color: var(--muted); }
.totals .row.target { color: var(--green); font-weight: 800; }
.internal-box { border-style: dashed; }
.internal-box h2.sec { color: var(--green); }

.qcalc { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; align-items: end; }
@media (min-width: 700px) { .qcalc { grid-template-columns: repeat(4, 1fr) auto; } }
.qcalc .out { font-size: 16px; color: var(--green); font-weight: 800; align-self: center; padding-top: 8px; }

/* field calc subpanels */
.subpanel { display: none; }
.subpanel.on { display: block; }

/* type-above-keyboard mirror */
#typeMirror {
  display: none;
  position: fixed;
  left: 0; right: 0;
  z-index: 90;
  background: #12151a;
  border-top: 2px solid var(--accent);
  padding: 8px 14px;
  padding-left: max(14px, var(--safe-l));
  padding-right: max(14px, var(--safe-r));
}
#typeMirror.on { display: block; }
#typeMirror .lab { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
#typeMirror .val { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; word-break: break-word; }

.prophead { display: none; }
.home-hero { margin: 4px 0 16px; }
.home-hero h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.15;
}
.home-hero p { color: var(--muted); margin-top: 6px; font-size: 14px; }

.install-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* print: client-facing only — hide internal target, chrome, settings */
@media print {
  body { background: #fff; color: #111; }
  .appbar, .foot, .menu-pop, #typeMirror, .toolbar, .btn, .btn-back, .menu-cube, .qcard, .item .del, .internal-box, .flag, #pane-setup { display: none !important; }
  main { padding: 0; max-width: none; }
  .screen { display: none !important; }
  #screen-estimator.screen { display: block !important; }
  .tabpane { display: block !important; page-break-inside: avoid; }
  .card { border-color: #bbb; background: #fff; }
  input, select, textarea { background: #fff; color: #111; border: none; padding: 2px 4px; font-size: 12px; }
  h1, h2, h2.sec, td.qty, .totals .row.grand { color: #111; }
  th, td, .totals .row { border-color: #ccc; }
  .prophead { display: block; border-bottom: 2px solid #111; margin-bottom: 14px; padding-bottom: 8px; }
  .prophead .big { font-size: 20px; font-weight: 800; }
}
