:root {
  --ink: #131416;
  --charcoal: #25272b;
  --orange: #F7820F;
  --orange-dark: #EE5A00;
  --paper: #f5f3ee;
  --white: #ffffff;
  --line: #d8d4ca;
  --muted: #6b6e75;
  --danger: #b3261e;
  --font-cond: "Roboto Condensed", "Arial Narrow", "Helvetica Neue Condensed", "Liberation Sans Narrow", "Arial", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --bar-h: 92px; /* updated at runtime from the real bottom-bar height */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--ink); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--charcoal);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.35;
  min-height: 100svh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(247, 130, 15, 0.25);
}
h1, h2, h3, .cond { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; color: var(--ink); }
h3 { font-size: 15px; margin: 18px 0 10px; color: var(--ink); }
h3:first-child { margin-top: 0; }
small { font-weight: 400; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); color: var(--white);
  padding: calc(8px + var(--sat)) calc(16px + var(--sar)) 8px calc(16px + var(--sal));
  min-height: calc(60px + var(--sat));
  border-bottom: 3px solid var(--orange);
}
.logo { height: 44px; width: auto; flex: 0 0 auto; }
.header-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.eyebrow { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--orange); font-weight: 700; }
h1 { font-size: 20px; margin: 0; line-height: 1.1; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offline-badge { font: 700 11px/1 var(--font-cond); text-transform: uppercase; letter-spacing: .08em; background: var(--orange-dark); color: var(--white); padding: 6px 8px; border-radius: 999px; }
.offline-badge[hidden] { display: none; }

/* ---------- Layout ---------- */
main {
  display: grid; gap: 12px;
  padding: 12px calc(12px + var(--sar)) calc(var(--bar-h) + 20px + var(--sab)) calc(12px + var(--sal));
  max-width: 1100px; margin: 0 auto; width: 100%;
}
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 1px 2px rgba(19, 20, 22, 0.05);
  min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 420px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.grid-2 .field, .grid-3 .field { margin-bottom: 12px; }
.label { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: 0.06em; font-size: 13px; font-weight: 700; color: var(--muted); }
input, select, button, output { font-family: inherit; }
input[type="text"], select, .readout {
  width: 100%; min-height: 48px; font-size: 18px; color: var(--ink);
  padding: 0 12px; border: 2px solid var(--line); border-radius: 10px; background: var(--white);
  -webkit-appearance: none; appearance: none; margin: 0;
}
input[type="text"]:focus, select:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(247, 130, 15, 0.25); }
input[readonly] { background: var(--paper); color: var(--muted); font-size: 16px; text-overflow: ellipsis; }
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10'><path d='M1 1l7 7 7-7' fill='none' stroke='%2325272b' stroke-width='2.5'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px;
}
.readout { display: flex; align-items: center; background: var(--paper); font-weight: 700; font-family: var(--font-cond); font-size: 20px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1 1 auto; min-width: 0; }
.inline .btn { flex: 0 0 auto; }
.error { color: var(--danger); font-weight: 600; margin: 8px 0 0; }
.error[hidden] { display: none; }
.muted { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 10px; border: 2px solid transparent;
  font-family: var(--font-cond); font-weight: 700; font-size: 17px; text-transform: uppercase; letter-spacing: 0.04em;
  cursor: pointer; touch-action: manipulation; user-select: none; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.05s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.btn-primary { background: var(--orange); color: var(--ink); border-color: var(--orange); }
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.btn-secondary { background: var(--charcoal); color: var(--white); border-color: var(--charcoal); }
.btn-secondary:hover { background: var(--ink); }
.btn-ghost { background: var(--white); color: var(--charcoal); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--charcoal); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.actions .btn { min-height: 52px; }
@media (max-width: 379px) { .actions { grid-template-columns: 1fr; } }

/* ---------- Multiplier ---------- */
.mult-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.mult-auto { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mult-value { font-family: var(--font-cond); font-weight: 700; font-size: 36px; line-height: 1; color: var(--ink); display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.mult-unit { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }
.mult-why { font-size: 14px; color: var(--muted); }
.mult-why.rule { color: var(--orange-dark); font-weight: 700; }
.mult-why.override { color: var(--charcoal); font-weight: 700; }
.mult-override { margin: 0; }
.mult-override .btn { padding: 0 14px; }
@media (max-width: 379px) { .mult-row { grid-template-columns: 1fr; } }

/* ---------- Results table ---------- */
table.results { width: 100%; border-collapse: collapse; }
table.results th, table.results td { padding: 10px 0; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; }
table.results tr:last-child th, table.results tr:last-child td { border-bottom: 0; }
table.results th { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: 0.05em; font-size: 14px; color: var(--muted); width: 22%; }
table.results td.detail { font-size: 14px; color: var(--muted); padding-right: 8px; }
table.results td.value { text-align: right; white-space: nowrap; font-family: var(--font-cond); font-weight: 700; font-size: 22px; color: var(--ink); width: 22%; }
table.results td.value small { font-size: 13px; color: var(--muted); }
table.results tr.total th { color: var(--ink); }
table.results tr.total td.value { font-size: 30px; color: var(--orange-dark); }

/* ---------- Prices ---------- */
.prices { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.prices li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--paper); }
.prices .tier { display: flex; flex-direction: column; min-width: 0; }
.prices .tier b { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: .04em; font-size: 16px; color: var(--ink); }
.prices .tier span { font-size: 13px; color: var(--muted); }
.prices .amt { font-family: var(--font-cond); font-weight: 700; font-size: 24px; color: var(--ink); white-space: nowrap; }
.prices li.local { background: var(--ink); color: var(--white); }
.prices li.local .tier b, .prices li.local .amt { color: var(--white); }
.prices li.local .tier span { color: #c9c6bd; }
.prices li.local .amt { color: var(--orange); }

/* ---------- Settings ---------- */
details.card { padding: 0; }
details.card summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; padding: 0 16px; font-family: var(--font-cond); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 17px; color: var(--ink);
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary .chev { width: 12px; height: 12px; border-right: 2.5px solid var(--charcoal); border-bottom: 2.5px solid var(--charcoal); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
details.card[open] summary .chev { transform: rotate(-135deg); }
details.card .settings-body { padding: 4px 16px 16px; border-top: 1px solid var(--line); }
.settings-body .btn { width: 100%; margin-top: 8px; }

/* ---------- Bottom bar ---------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: var(--white);
  padding: 10px calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal));
  border-top: 3px solid var(--orange);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
}
.bb-total { display: flex; flex-direction: column; flex: 0 0 auto; }
.bb-label { font-family: var(--font-cond); text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; color: #c9c6bd; }
.bb-value { font-family: var(--font-cond); font-weight: 700; font-size: 34px; line-height: 1; color: var(--orange); display: flex; align-items: baseline; gap: 4px; }
.bb-value small { font-size: 14px; color: #c9c6bd; }
.bb-prices { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bb-local { display: flex; flex-direction: column; min-width: 0; }
.bb-local b { font-family: var(--font-cond); font-size: 20px; line-height: 1.1; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bb-others { display: flex; flex-direction: column; font-size: 11.5px; color: #c9c6bd; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bb-copy { flex: 0 0 auto; min-height: 52px; padding: 0 14px; font-size: 16px; }
@media (min-width: 480px) { .bb-others { flex-direction: row; gap: 10px; font-size: 13px; } .bb-copy { padding: 0 22px; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 16px + var(--sab)); transform: translate(-50%, 12px);
  background: var(--charcoal); color: var(--white); padding: 12px 18px; border-radius: 10px;
  font-family: var(--font-cond); font-weight: 700; font-size: 16px; letter-spacing: .03em;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 40; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  main {
    grid-template-columns: 1fr 1fr; gap: 16px; padding-top: 20px; align-items: start;
    grid-template-areas: "job results" "mult prices" "settings prices";
  }
  .area-job { grid-area: job; }
  .area-mult { grid-area: mult; }
  .area-results { grid-area: results; }
  .area-prices { grid-area: prices; }
  .area-settings { grid-area: settings; }
  h1 { font-size: 24px; }
  .bottom-bar { padding-left: calc((100vw - 1100px) / 2 + 12px); padding-right: calc((100vw - 1100px) / 2 + 12px); }
}
@media (min-width: 900px) and (max-width: 1123px) {
  .bottom-bar { padding-left: 12px; padding-right: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
