:root {
  --bg: #efe8dc;
  --bg-2: #e4d9c8;
  --surface: #fffdf8;
  --surface-2: #f7f1e6;
  --ink: #1c1915;
  --ink-soft: #3d3830;
  --muted: #6e665b;
  --line: #d9cdb8;
  --accent: #d97706;
  --accent-ink: #1c1915;
  --accent-soft: #fde7c3;
  --good: #1f6b45;
  --good-soft: #d8f0e3;
  --warn: #b45309;
  --warn-soft: #fde8c8;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --navy: #1f3d33;
  --shadow: 0 8px 24px rgba(28, 25, 21, 0.08);
  --radius: 16px;
  --tap: 52px;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --mono: "ui-monospace", "SFMono-Regular", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #161310;
  --bg-2: #1e1a16;
  --surface: #221e19;
  --surface-2: #2b261f;
  --ink: #f4efe6;
  --ink-soft: #d8d0c2;
  --muted: #a39888;
  --line: #3a342b;
  --accent: #f0a430;
  --accent-ink: #1c1915;
  --accent-soft: #3a2c16;
  --good: #5dcaa0;
  --good-soft: #17352a;
  --warn: #f0a430;
  --warn-soft: #3a2c16;
  --bad: #f08880;
  --bad-soft: #3a1c18;
  --navy: #cfe0d6;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
img { max-width: 100%; }
a { color: var(--accent); }

.app-wrap { max-width: 920px; margin: 0 auto; padding: 12px 14px 24px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: #1c1915; color: #f4efe6; display: grid; place-items: center;
  font-weight: 800; letter-spacing: -0.04em; flex: none;
  border-bottom: 3px solid var(--accent);
}
:root[data-theme="dark"] .logo-mark { background: #0f0d0b; }
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: -0.03em; line-height: 1.1; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 1.15rem;
}

/* Search */
.search-wrap { position: relative; margin: 10px 0 16px; }
.search-wrap input {
  width: 100%; height: 52px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 0 44px 0 46px; font-size: 1rem;
}
.search-ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: 0.55; }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

/* Cards / grids */
.section-label {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 2px 8px; font-size: 0.78rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.trade-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
@media (min-width: 640px) {
  .trade-grid { grid-template-columns: repeat(4, 1fr); }
}
.trade-card, .tool-card, .calc-card, .list-card, .result-card, .panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.trade-card {
  min-height: 96px; padding: 14px 12px;
  display: flex; flex-direction: column; justify-content: space-between;
  text-align: left; gap: 8px;
}
.trade-card .emoji { font-size: 1.55rem; line-height: 1; }
.trade-card .name { font-weight: 700; font-size: 0.98rem; letter-spacing: -0.02em; }
.tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tool-card {
  padding: 14px; text-align: left; min-height: 72px;
  display: flex; flex-direction: column; gap: 4px;
}
.tool-card .emoji { font-size: 1.2rem; }
.tool-card strong { font-size: 0.92rem; }
.tool-card span { color: var(--muted); font-size: 0.75rem; }

.calc-list { display: flex; flex-direction: column; gap: 8px; }
.calc-card {
  padding: 14px 14px; display: flex; align-items: center; gap: 12px;
  text-align: left; min-height: var(--tap); width: 100%;
}
.calc-card .ico {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--accent-soft); font-size: 1.2rem;
}
.calc-card .meta { flex: 1; min-width: 0; }
.calc-card .meta b { display: block; font-size: 0.98rem; }
.calc-card .meta small { color: var(--muted); }
.star { font-size: 1.25rem; opacity: 0.45; }
.star.on { opacity: 1; color: var(--accent); }

/* Calculator screen */
.page-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.back-btn {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: var(--surface); border: 1px solid var(--line);
}
.page-head h2 { margin: 0; font-size: 1.2rem; letter-spacing: -0.03em; flex: 1; }
.unit-toggle {
  display: flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px;
}
.unit-toggle button {
  height: 32px; padding: 0 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700;
  color: var(--muted);
}
.unit-toggle button.on { background: var(--accent); color: var(--accent-ink); }

.form-grid { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); }
.field-row { display: flex; gap: 8px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 0 12px; font-size: 1.05rem;
}
textarea.input { min-height: 88px; padding: 12px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.input::placeholder { color: #b3a894; font-weight: 500; }
:root[data-theme="dark"] .input::placeholder { color: #6f675c; }
#calc-form { padding-bottom: 28px; }
.suffix {
  min-width: 72px; height: var(--tap); border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: var(--muted);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 38px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 700; font-size: 0.85rem;
}
.chip.on { background: var(--navy); color: #f4efe6; border-color: var(--navy); }
:root[data-theme="dark"] .chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.add-btn, .primary, .ghost, .danger {
  min-height: var(--tap); border-radius: 14px; font-weight: 800; padding: 0 16px;
}
.primary { background: var(--accent); color: var(--accent-ink); width: 100%; font-size: 1.02rem; }
.ghost { background: var(--surface); border: 1px solid var(--line); }
.add-btn { width: 100%; background: var(--surface-2); border: 1px dashed var(--line); color: var(--ink-soft); }
.danger { background: var(--bad-soft); color: var(--bad); }

.areas { display: flex; flex-direction: column; gap: 8px; }
.area-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.area-item .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.area-item input { min-height: 44px; }

.result-card {
  margin-top: 14px; padding: 16px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.result-kicker {
  font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 800;
}
.result-hero {
  font-size: 2.1rem; font-weight: 800; letter-spacing: -0.04em; margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.result-sub { color: var(--muted); margin-bottom: 10px; }
.result-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.result-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.95rem;
}
.result-row b { font-variant-numeric: tabular-nums; }
.warn-box, .info-box, .how-box {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px; font-size: 0.85rem; line-height: 1.4;
}
.warn-box { background: var(--warn-soft); color: var(--warn); }
.info-box { background: var(--good-soft); color: var(--good); }
.how-box { background: var(--surface-2); color: var(--ink-soft); display: none; }
.how-box.open { display: block; }
.info-mini {
  margin-left: 6px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); font-size: 0.75rem; font-weight: 800;
}

.cost-box { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); }

/* Lists */
.list-card {
  width: 100%; padding: 14px; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.empty {
  text-align: center; color: var(--muted); padding: 36px 16px;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}

/* Bottom nav */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  width: min(920px, 100%);
  bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 0 0 100vmax var(--surface);
  clip-path: inset(0 -100vmax 0 -100vmax);
  padding: 6px 8px calc(8px + var(--safe-b));
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottom-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 0.68rem; font-weight: 700; padding: 4px 0;
}
.bottom-nav button.on { color: var(--ink); }
.bottom-nav .nav-ico { font-size: 1.15rem; }

/* FAB calculator */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  z-index: 28; width: 58px; height: 58px; border-radius: 18px;
  background: var(--accent); color: var(--accent-ink); font-size: 1.5rem; font-weight: 800;
  box-shadow: 0 10px 24px rgba(217, 119, 6, 0.35);
}

/* Quick calc overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(20,16,12,0.55); z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
}
.overlay.open { display: flex; }
.sheet {
  width: min(480px, 100%); background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 12px 12px calc(16px + var(--safe-b));
  max-height: 92dvh; overflow: auto;
}
.grab { width: 42px; height: 4px; background: var(--line); border-radius: 4px; margin: 4px auto 10px; }
.qc-display {
  background: #1c1915; color: #f4efe6; border-radius: 14px; padding: 14px;
  text-align: right; min-height: 76px;
}
.qc-expr { color: #c4b8a4; font-size: 0.85rem; min-height: 1.1em; word-break: break-all; }
.qc-val { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.qc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.qc-grid button {
  min-height: 56px; border-radius: 14px; background: var(--surface-2);
  border: 1px solid var(--line); font-size: 1.2rem; font-weight: 800;
}
.qc-grid button.op { background: var(--accent-soft); }
.qc-grid button.eq { background: var(--accent); color: var(--accent-ink); }
.qc-grid button.wide { grid-column: span 2; }

/* Quote / project */
.line-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.line-table th { text-align: left; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; padding: 6px 4px; }
.line-table td { padding: 4px; }
.line-table input { min-height: 40px; width: 100%; }
.totals { margin-top: 12px; }
.quote-paper {
  background: white; color: #1c1915; border: 1px solid #ddd; border-radius: 8px; padding: 20px;
}
:root[data-theme="dark"] .quote-paper { background: #f7f3ea; }

/* Settings */
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.setting-row select, .setting-row input { min-height: 42px; max-width: 160px; }

.badge {
  display: inline-block; background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: 2px 8px; font-size: 0.72rem; font-weight: 800;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.hidden { display: none !important; }

@media print {
  body { background: white; padding: 0; color: #111; }
  .bottom-nav, .fab, .topbar, .no-print, .unit-toggle, .back-btn { display: none !important; }
  .app-wrap { max-width: none; padding: 0; }
}

/* Search results */
.search-hits { display: flex; flex-direction: column; gap: 8px; }

.soon {
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em;
  background: var(--accent-soft); padding: 2px 6px; border-radius: 6px;
}

.photo-stage {
  background: #1c1915;
  border-radius: 16px;
  overflow: hidden;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.photo-stage.empty-stage { border: 1px dashed var(--line); background: var(--surface-2); min-height: 120px; }
.photo-stage canvas { width: 100%; height: auto; display: block; }

.review-stars {
  display: flex; justify-content: center; gap: 6px; margin: 8px 0 12px;
}
.review-stars button {
  font-size: 2rem; line-height: 1; background: none; border: 0;
  color: var(--line); padding: 4px 6px;
}
.review-stars button.on { color: var(--accent); }

.sign-wrap {
  background: #fff;
  border: 2px dashed #c4b08a;
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 14px;
}
.sign-hint {
  font-size: 0.8rem;
  font-weight: 700;
  color: #8a7a66;
  margin-bottom: 6px;
}
.sign-wrap canvas {
  display: block;
  width: 100%;
  height: 160px;
  min-height: 160px;
  background: #fffdf6;
  border: 1px solid #e4d9c8;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
}
.swipe-row { position: relative; margin-bottom: 8px; overflow: hidden; border-radius: 14px; }
.swipe-under {
  position: absolute; inset: 0;
  background: var(--accent-soft); color: var(--ink);
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 16px; font-weight: 800;
}
.swipe-face {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  margin: 0;
}
.swipe-open {
  flex: 1; text-align: left; background: none; border: 0; color: inherit;
  padding: 4px 0;
}
.swipe-move { flex-shrink: 0; }
.viz-stage {
  margin-top: 10px;
  background: #1c1915;
  border-radius: 14px;
  overflow: hidden;
}
.viz-stage canvas { display: block; width: 100%; touch-action: none; }
