:root {
  --bg: #0a0a0a;
  --bg-2: #111;
  --bg-3: #1a1a1a;
  --line: #222;
  --text: #e6e6e6;
  --muted: #888;
  --accent: #c85a14;
  --accent-2: #ff8833;
  --grid-min: #1a1a1a;
  --grid-maj: #2a2a2a;
  --ink: #e0e8f0;
  --sel: #ff6600;
}
* { box-sizing: border-box; }
#archcad-workspace {
  display: grid;
  grid-template-rows: auto 1fr 22px;
  height: 100%;
  min-height: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 "Segoe UI", system-ui, sans-serif;
}
#archcad-workspace button,
#archcad-workspace select,
#archcad-workspace input { font: inherit; color: var(--text); background: var(--bg-3);
  border: 1px solid #333; border-radius: 3px; }
#archcad-workspace button { cursor: pointer; padding: 4px 10px; }
#archcad-workspace button:hover { border-color: var(--accent); color: var(--accent-2); }
#archcad-workspace button.active { background: #2a1a0e; border-color: var(--accent); color: var(--accent-2); font-weight: 700; }
#archcad-workspace button:disabled,
#archcad-workspace button:disabled:hover {
  opacity: 0.35;
  cursor: default;
  border-color: #333;
  color: #666;
}
#archcad-workspace input,
#archcad-workspace select { padding: 3px 6px; background: #141414; }
#archcad-workspace label { color: var(--muted); }

#app { display: grid; grid-template-rows: 48px 56px 1fr 22px; height: 100%; }
#topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: #050505; border-bottom: 1px solid var(--line); }
#topbar img { width: 28px; height: 28px; }
#topbar h1 { font-size: 14px; margin: 0; color: var(--accent-2); font-weight: 700; letter-spacing: .04em; }
#topbar .spacer { flex: 1; }
#ribbon { display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: var(--bg-2); border-bottom: 2px solid #000; overflow-x: auto;
  flex-wrap: wrap; min-height: 56px; }
#ribbon .grp { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#ribbon .grp > div { display: flex; gap: 3px; }
#ribbon .grp span { font-size: 10px; color: #666; }
#ribbon .sep { width: 1px; height: 40px; background: #333; margin: 0 6px; }
#ribbon a.ac-howto {
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: var(--bg-3);
  border: 1px solid rgba(255,136,51,0.55);
  border-radius: 3px;
  color: #ffb06a;
  font-size: 13px;
  font-weight: 700;
  min-height: 26px;
}
#ribbon a.ac-howto:hover {
  border-color: var(--accent);
  color: var(--accent-2);
}

#workspace { display: grid; grid-template-columns: 56px 1fr minmax(280px, 340px);
  min-height: 0; height: 100%; }
#tools { background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; padding: 6px; }
#tools button { padding: 8px 2px; font-size: 16px; }
#stage { position: relative; min-width: 0; min-height: 0; background: var(--bg); }
#cad { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
#sel-readout {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  min-width: 9.5rem;
  max-width: min(70vw, 16rem);
  padding: 10px 14px;
  border: 1px solid #ff8833;
  border-radius: 10px;
  background: rgba(8, 8, 8, 0.94);
  color: #fff;
  text-align: right;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
#sel-readout .sel-kind {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffb06a;
  margin-bottom: 2px;
}
#sel-readout .sel-size {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
#sel-readout .sel-angle-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #ffb06a;
  pointer-events: auto;
}
#sel-readout #sel-angle {
  width: 5.2rem;
  min-height: 36px;
  padding: 4px 6px;
  font-size: 18px;
  font-weight: 800;
  text-align: right;
  color: #fff;
  background: #141414;
  border: 1px solid #ff8833;
  border-radius: 6px;
}
#hint { position: absolute; left: 62px; bottom: 12px; color: var(--muted); font-size: 11px;
  pointer-events: none; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 3px;
  max-width: calc(100% - 160px); }
#zoom-controls,
#edit-controls {
  position: absolute;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 4;
}
#zoom-controls { right: 10px; }
#edit-controls { left: 10px; }
#zoom-controls button,
#edit-controls button {
  width: 44px;
  height: 44px;
  font-size: 20px;
  font-weight: 700;
  background: rgba(18, 18, 18, 0.92);
  border: 1px solid #444;
  border-radius: 8px;
  color: #ffd0a8;
}
#archcad-workspace button:disabled {
  opacity: 0.35;
  cursor: default;
  border-color: #333;
  color: #666;
}

#dock-home { position: relative; min-width: 0; background: #0d0d0d;
  border-left: 1px solid var(--line); }
#estimator {
  display: flex; flex-direction: column; height: 100%; background: #0d0d0d;
  min-height: 0;
}
#estimator.floating {
  position: fixed; z-index: 50; width: min(440px, 96vw); height: min(86vh, 820px);
  box-shadow: 0 12px 40px rgba(0,0,0,.7); border: 1px solid #333; border-radius: 4px;
}
.dock-chrome {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: #111; border-bottom: 1px solid var(--line); cursor: default; user-select: none;
}
.dock-chrome h2 { margin: 0; font-size: 13px; color: var(--accent-2); flex: 1; }
.dock-chrome button { padding: 3px 10px; }
#estimator .body { flex: 1; overflow: auto; padding: 8px; min-height: 0; -webkit-overflow-scrolling: touch; }

.sec { font-weight: 700; font-size: 11px; color: var(--accent-2); margin: 10px 0 4px; }
.row { display: grid; grid-template-columns: 132px 1fr; gap: 6px; align-items: center; margin: 3px 0; }
.row label { font-size: 12px; }
.checks { display: flex; flex-direction: column; gap: 3px; margin: 4px 0 8px; }
.checks label { display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 12px; }
.primary { width: 100%; font-weight: 700; padding: 7px; margin: 4px 0; background: #2a1a0e; border-color: var(--accent); }

.est-results { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 12px; }
.est-empty { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 8px 2px; }
.est-hint { color: #8b97a8; font-size: 11px; line-height: 1.4; margin: 0 0 8px; }
.wall-runs { display: flex; flex-direction: column; gap: 4px; margin: 4px 0; }
.wall-run {
  display: grid;
  grid-template-columns: 64px 1fr 36px 36px;
  gap: 6px;
  align-items: center;
}
.wall-run label { font-size: 12px; color: var(--muted); }
.wall-run .wall-add,
.wall-run .wall-del {
  min-width: 36px;
  padding: 4px 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.wall-run .wall-add { border-color: var(--accent); color: var(--accent-2); }
.wall-add-btn {
  width: 100%;
  margin: 4px 0 8px;
  font-weight: 700;
  border-color: var(--accent);
  color: var(--accent-2);
}
.trade {
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  overflow: hidden;
  background: #101010;
}
.trade-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #1a140e;
  border-bottom: 1px solid #3a2a1a;
  position: sticky;
  top: 0;
  z-index: 1;
}
.trade-icon { font-size: 14px; }
.trade-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-2);
  letter-spacing: 0.02em;
}
.trade-count { font-size: 10px; color: #8a7a6a; white-space: nowrap; }
.trade-lines { list-style: none; margin: 0; padding: 4px 0 6px; }
.trade-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 7px 10px;
  border-bottom: 1px solid #1c1c1c;
}
.trade-line:last-of-type { border-bottom: 0; }
.trade-desc {
  color: #e8e8e8;
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.trade-qty {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #ffd0a8;
  font-size: 12px;
  white-space: nowrap;
  text-align: right;
}
.trade-qty small { color: #9a8a7a; font-weight: 600; font-size: 10px; }
.trade-note {
  list-style: none;
  padding: 0 10px 8px 22px;
  color: #8b97a8;
  font-size: 11px;
  line-height: 1.35;
}

.code-results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.code-row { border: 1px solid #2a2a2a; border-radius: 6px; padding: 8px 10px; }
.code-top { display: flex; align-items: center; gap: 8px; }
.code-top strong { flex: 1; font-size: 12px; }
.code-badge { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; }
.code-loc, .code-req { font-size: 11px; color: #9aa6b4; margin-top: 4px; line-height: 1.4; }
.status-ERROR { background: #3a1518; }
.status-WARN { background: #3a3210; }
.status-OK { background: #1a3a1a; }

#status { display: flex; align-items: center; gap: 16px; padding: 0 10px;
  background: #050505; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
#status .grow { flex: 1; }
.save-note { color: #8b97a8; }
.paid-badge {
  background: #2a1a0e;
  border: 1px solid var(--accent);
  color: var(--accent-2);
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 700;
}
.paywall {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.paywall[hidden] { display: none !important; }
.paywall-card {
  position: relative;
  width: min(460px, 100%);
  background: #111;
  border: 1px solid #ff8833;
  border-radius: 12px;
  padding: 22px 22px 18px;
  color: #eee;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}
.paywall-card h2 { margin: 0 0 10px; font-size: 1.25rem; color: #ffb06a; }
.paywall-card p, .paywall-card li { font-size: 14px; line-height: 1.45; color: #c8c8c8; }
.paywall-card ul { margin: 10px 0 16px; padding-left: 1.1rem; }
.paywall-close {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
}
.paywall-actions { display: flex; flex-direction: column; gap: 8px; }
.paywall-buy {
  width: 100%;
  min-height: 44px;
  font-weight: 800;
  background: #2a1a0e;
  border-color: #ff8833;
  color: #ffd0a8;
}
.paywall-alt { color: #7ef4ff; text-align: center; font-size: 14px; }
@media print {
  .paywall, #edit-controls, #zoom-controls, #sel-readout { display: none !important; }
}

@media (max-width: 860px) {
  #archcad-workspace {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto auto auto;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #ribbon {
    position: sticky;
    top: 0;
    z-index: 8;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-top: max(6px, env(safe-area-inset-top));
    min-height: 0;
  }
  #ribbon .grp > div { flex-wrap: nowrap; }
  #ribbon button,
  #ribbon a {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 10px;
    font-size: 13px;
    touch-action: manipulation;
  }
  #workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(58dvh, 70dvh) 56px auto;
    grid-template-areas:
      "stage"
      "tools"
      "dock";
    height: auto;
    min-height: 0;
  }
  #stage { grid-area: stage; min-height: 58dvh; height: 58dvh; }
  #tools { grid-area: tools; }
  #dock-home { grid-area: dock; }
  #tools {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid var(--line);
    width: 100%;
    padding: 4px 6px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }
  #tools button {
    min-width: 48px;
    min-height: 48px;
    font-size: 20px;
    flex: 0 0 auto;
  }
  #dock-home {
    display: block;
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: 70vh;
  }
  #estimator {
    height: auto;
    min-height: 0;
  }
  #estimator .body {
    overflow: visible;
    flex: none;
    height: auto;
  }
  #estimator.floating {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    min-height: 0;
    box-shadow: none;
    border: 0;
    border-radius: 0;
  }
  #hint { display: none; }
  #status { flex-wrap: wrap; min-height: 28px; padding: 4px 10px 8px; }
  .row { grid-template-columns: 1fr; gap: 2px; }
  .row label { font-size: 13px; }
  #archcad-workspace input,
  #archcad-workspace select,
  #archcad-workspace button { min-height: 40px; font-size: 16px; }
  #zoom-controls button,
  #edit-controls button { width: 48px; height: 48px; }
  #sel-readout {
    top: 8px;
    right: 8px;
    min-width: 11rem;
    padding: 12px 16px;
  }
  #sel-readout .sel-kind { font-size: 15px; }
  #sel-readout .sel-size { font-size: 28px; }
  #sel-readout .sel-angle-row { font-size: 16px; }
  #sel-readout #sel-angle { min-height: 44px; font-size: 22px; width: 6rem; }
}
