:root {
  --red: #FF2D55; --pink: #FF6B82; --bg: #0B0B09; --raised: #12100d;
  --panel: #17140f; --line: #2a2620; --cream: #F4F1EA; --muted: #b4aa9d;
  --gold: #d8b662; --blue: #2b6cff; --ok: #3fd08a;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --disp: "Syne", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--cream);
  font-family: var(--ui); font-size: 15px; -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility; overflow: hidden; }
#app { display: grid; grid-template-columns: 360px 1fr; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar { background: var(--raised); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; position: relative; z-index: 3; }
#brand { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.brand-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.brand-btns { display: flex; gap: 6px; flex-shrink: 0; margin-left: auto; }
.brand-btns button { background: #1c1811; border: 1px solid var(--line); color: var(--cream);
  font-family: var(--ui); font-weight: 500; font-size: 12px; padding: 6px 11px; border-radius: 7px; cursor: pointer; }
.brand-btns button:hover { border-color: var(--red); color: var(--pink); }
#designs-drawer { border-bottom: 1px solid var(--line); background: #0e0c08; max-height: 44vh; overflow-y: auto; }
#designs-drawer[hidden] { display: none; }
.dd-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px;
  font-family: var(--ui); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); position: sticky; top: 0; background: #0e0c08; }
.dd-head button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.dd-item { display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-top: 1px solid #17140f; cursor: pointer; }
.dd-item:hover { background: #14120d; }
.dd-item .di-main { flex: 1; min-width: 0; }
.dd-item .di-name { font-size: 13.5px; font-weight: 500; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-item .di-sub { font-family: var(--ui); font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.dd-item .di-del { background: none; border: none; color: #7a5560; cursor: pointer; font-size: 12px; padding: 4px; flex-shrink: 0; }
.dd-item .di-del:hover { color: var(--red); }
.dd-empty { padding: 14px 16px; color: var(--muted); font-size: 12px; font-family: var(--ui); }

.brand-btns #btn-key.set { border-color: var(--ok); color: var(--ok); }
#key-panel { border-bottom: 1px solid var(--line); background: #0e0c08; }
#key-panel[hidden] { display: none; }
.kp-body { padding: 4px 16px 16px; }
.kp-body p { font-size: 13px; color: var(--muted); line-height: 1.55; margin: 0 0 12px; }
.kp-body p b { color: var(--cream); }
#key-input, #model-input { width: 100%; background: #0e0c08; border: 1px solid var(--line); color: var(--cream);
  border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 13px; }
#model-input { margin-top: 8px; font-size: 12.5px; }
#key-input:focus, #model-input:focus { outline: none; border-color: var(--red); }
.kp-row { display: flex; gap: 8px; margin-top: 10px; }
#key-save { background: var(--red); color: #fff; border: none; font-family: var(--disp); font-weight: 700;
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; }
#key-save:hover { background: var(--pink); }
.kp-row .ghost { background: #1c1811; border: 1px solid var(--line); color: var(--muted);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-family: var(--ui); font-size: 12px; }
#key-status { font-family: var(--ui); font-size: 11.5px; color: var(--muted); margin: 10px 0 8px; min-height: 14px; }
.kp-body a { font-family: var(--ui); font-size: 12px; color: var(--red); text-decoration: none; }
.kp-body a:hover { color: var(--pink); text-decoration: underline; }
.kp-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.kp-links a { font-size: 12px; color: var(--muted); }
.kp-links a:hover { color: var(--red); }
#owner-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
#owner-box summary { font-family: var(--ui); font-size: 11.5px; color: var(--muted); cursor: pointer; }
#owner-box summary:hover { color: var(--cream); }
#owner-box p { font-size: 11.5px; color: var(--muted); line-height: 1.45; margin: 8px 0; }
#owner-box #owner-input { width: 100%; background: #0e0c08; border: 1px solid var(--line); color: var(--cream);
  border-radius: 8px; padding: 9px 12px; font-family: var(--mono); font-size: 12.5px; }
#owner-box #owner-input:focus { outline: none; border-color: var(--gold); }
#owner-save { background: var(--gold); color: #1a1409; border: none; font-family: var(--disp); font-weight: 700;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
#owner-status { font-family: var(--ui); font-size: 11px; color: var(--muted); margin-top: 8px; }
.logo { font-family: var(--disp); font-weight: 800; font-size: 26px; letter-spacing: 1px;
  background: linear-gradient(90deg, var(--red), var(--gold)); -webkit-background-clip: text;
  background-clip: text; color: transparent; }
.tag { font-family: var(--ui); font-size: 12px; color: var(--muted); margin-top: 4px; }
.tag span { color: var(--red); }

#chat { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex;
  flex-direction: column; gap: 10px; min-height: 0; }
.msg { padding: 11px 13px; border-radius: 10px; font-size: 14px; line-height: 1.55; max-width: 100%; }
.msg.user { background: #221016; border: 1px solid #3a1622; align-self: flex-end; }
.msg.bot { background: #14120d; border: 1px solid var(--line); }
.msg.bot .mname { font-family: var(--disp); font-weight: 700; color: var(--red); font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 3px; }
.msg.err { border-color: #5a2130; background: #23121a; color: #ffb3c0; }

#examples { padding: 8px 16px; border-top: 1px solid var(--line); display: flex;
  flex-wrap: wrap; gap: 6px; align-items: center; }
.ex-label { font-family: var(--ui); font-size: 12px; font-weight: 600; color: var(--muted); width: 100%; }
.ex { background: #1c1811; border: 1px solid var(--line); color: var(--cream); font-size: 12.5px;
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-family: var(--ui); }
.ex:hover { border-color: var(--red); color: var(--pink); }

#composer { padding: 12px 16px 16px; border-top: 1px solid var(--line); }
#prompt { width: 100%; resize: none; background: #0e0c08; border: 1px solid var(--line);
  color: var(--cream); border-radius: 10px; padding: 11px 13px; font-size: 15px; line-height: 1.45;
  font-family: inherit; }
#prompt::placeholder { color: #8a8177; }
#prompt:focus { outline: none; border-color: var(--red); }
.composer-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
#send { background: var(--red); color: #fff; border: none; font-family: var(--disp); font-weight: 700;
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-size: 14px; }
#send:hover { background: var(--pink); }
#send:disabled { opacity: .5; cursor: default; }
#mode-hint { font-family: var(--ui); font-size: 11px; color: var(--muted); }

/* ---------- Stage ---------- */
#stage { position: relative; min-width: 0; display: flex; flex-direction: column; }
#tabs { display: flex; align-items: center; gap: 4px; padding: 8px 12px; background: var(--raised);
  border-bottom: 1px solid var(--line); }
#tablist { display: contents; }        /* transparent on desktop; becomes a scroller on mobile */
#tools-toggle { display: none; }        /* mobile-only export menu trigger */
#mobile-nav { display: none; }          /* mobile-only bottom nav */
.tab { background: transparent; border: 1px solid transparent; color: var(--muted); font-family: var(--ui);
  font-weight: 500; font-size: 13.5px; padding: 8px 15px; border-radius: 8px; cursor: pointer; }
.tab:hover { color: var(--cream); }
.tab.active { color: var(--cream); background: #241d13; border-color: var(--line); }
#tabs .spacer { flex: 1; }
#toolbar { display: flex; align-items: center; gap: 6px; }
.chk { font-family: var(--ui); font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.tool { background: #1c1811; border: 1px solid var(--line); color: var(--cream); font-family: var(--ui);
  font-weight: 500; font-size: 12.5px; padding: 7px 12px; border-radius: 7px; cursor: pointer; }
.tool:hover { border-color: var(--gold); color: var(--gold); }

.view { position: absolute; inset: 49px 0 0 0; display: none; }
.view.active { display: block; }
#view-model.active { display: flex; flex-direction: column; }
#viewport { flex: 1; min-height: 0; }
#viewport canvas { display: block; }
#specbar { border-top: 1px solid var(--line); background: var(--raised); padding: 9px 16px;
  font-family: var(--ui); font-size: 12.5px; color: var(--muted); display: flex; gap: 8px 18px;
  flex-wrap: wrap; max-height: 84px; overflow-y: auto; }
#specbar b { color: var(--cream); font-weight: 600; }
#specbar .k { color: var(--red); font-weight: 500; }

.sheet-wrap { position: absolute; inset: 0; overflow: auto; background: #0e0d0b;
  display: flex; justify-content: center; padding: 22px; }
.sheet { background: #f7f5ef; border-radius: 4px; box-shadow: 0 10px 40px #000a; height: fit-content; }
#view-elevations .sheet + .sheet { margin-top: 22px; }
#elev-wrap { flex-direction: column; align-items: center; }

#bom-wrap { position: absolute; inset: 0; overflow: auto; padding: 22px 26px; }
#bom-wrap h2 { font-family: var(--disp); color: var(--cream); margin: 0 0 4px; }
#bom-wrap .sub { font-family: var(--ui); color: var(--muted); font-size: 12px; margin-bottom: 16px; }
table.bom { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.bom th { text-align: left; font-family: var(--ui); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--red); border-bottom: 1px solid var(--line); padding: 8px 10px; position: sticky; top: 0; background: var(--bg); }
table.bom td { padding: 8px 10px; border-bottom: 1px solid #1c1913; vertical-align: top; }
table.bom tr:hover td { background: #14120d; }
table.bom td.num { font-family: var(--ui); text-align: right; white-space: nowrap; }
.cat-row td { background: #191510 !important; font-family: var(--disp); font-weight: 700;
  color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.notes-block { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.notes-block .card { background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.notes-block h3 { font-family: var(--disp); margin: 0 0 8px; font-size: 14px; color: var(--cream); }
.notes-block li { font-size: 13px; color: var(--muted); margin-bottom: 7px; line-height: 1.5; }

#empty { position: absolute; inset: 49px 0 0 0; display: flex; align-items: center; justify-content: center; padding: 40px; }
#empty.hidden { display: none; }
.empty-inner { max-width: 460px; text-align: center; }
.empty-inner .big { font-family: var(--ui); font-weight: 700; font-size: 25px; margin-bottom: 12px;
  letter-spacing: -0.02em; line-height: 1.2; color: var(--cream); }
.empty-inner p { color: var(--muted); font-size: 15px; line-height: 1.65; max-width: 40ch; margin: 0 auto; }

#loading { position: absolute; inset: 49px 0 0 0; background: #0b0b09dd; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; z-index: 20; backdrop-filter: blur(2px); }
#loading[hidden] { display: none; }
.spinner { width: 44px; height: 44px; border: 3px solid var(--line); border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.9s linear infinite; }
#loading-msg { font-family: var(--ui); font-size: 14.5px; font-weight: 500; color: var(--cream); }
#loading-bar { width: 260px; max-width: 70vw; height: 6px; background: #241d13; border-radius: 999px; overflow: hidden; }
#loading-bar[hidden] { display: none; }
#loading-fill { height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--red), var(--gold)); transition: width 0.9s linear; }
#loading-sub { font-family: var(--ui); font-size: 12.5px; color: var(--muted); }
#loading-sub[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  /* Two full-screen surfaces (Design ⇄ View) switched by a bottom nav. */
  #app { display: block; height: 100dvh; }
  #sidebar, #stage {
    position: fixed; left: 0; right: 0; top: 0; bottom: 56px; z-index: 10;
    border: none; }
  #sidebar { z-index: 12; }
  body[data-screen="view"] #sidebar { display: none; }
  body[data-screen="design"] #stage { display: none; }

  #brand { padding: 12px 16px 10px; }
  .logo { font-size: 22px; }
  #chat { padding: 12px 14px; }
  #composer { padding-bottom: 14px; }
  #prompt { font-size: 16px; }               /* ≥16px stops iOS zoom-on-focus */
  #send { padding: 11px 20px; }

  /* Tabs: horizontal scroll strip; export folded into a menu button. */
  #tabs { padding: 6px 8px; gap: 6px; }
  #tablist { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; flex: 1; }
  #tablist::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 9px 14px; flex: 0 0 auto; }
  #tabs .spacer { display: none; }
  #tools-toggle { display: inline-block; flex: 0 0 auto; padding: 9px 12px; }
  #toolbar { position: absolute; top: 46px; right: 8px; z-index: 30;
    flex-direction: column; align-items: stretch; gap: 6px; padding: 10px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 10px 30px #000a; display: none; min-width: 150px; }
  #toolbar.open { display: flex; }
  #toolbar .tool, #toolbar .chk { padding: 11px 12px; font-size: 13px; justify-content: center; }

  .view { inset: 47px 0 0 0; }
  .sheet-wrap { padding: 10px; }
  #bom-wrap { padding: 14px; }
  #bom-wrap .notes-block { grid-template-columns: 1fr; }
  table.bom { font-size: 12px; }
  table.bom th, table.bom td { padding: 6px 6px; }
  table.bom th:nth-child(6), table.bom td:nth-child(6) { display: none; }  /* hide Notes col */
  #specbar { font-size: 11px; gap: 12px; max-height: 72px; }
  #empty { inset: 47px 0 0 0; padding: 24px; }
  .empty-inner .big { font-size: 22px; }
  #loading { inset: 47px 0 0 0; }

  /* Bottom navigation */
  #mobile-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 56px;
    z-index: 40; background: var(--raised); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  #mobile-nav button { flex: 1; background: none; border: none; color: var(--muted);
    font-family: var(--ui); font-size: 13px; cursor: pointer; display: flex;
    align-items: center; justify-content: center; gap: 6px; }
  #mobile-nav button.active { color: var(--cream); box-shadow: inset 0 2px 0 var(--red); }
}
