/* Agentic CAD Studio
   The viewport is the page. Panels are glass laid over it. */

:root {
  --ink: #ECEAE4;
  --ink-2: #A9ACB2;
  --ink-3: #6E7278;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --panel: rgba(27, 30, 35, 0.80);
  --panel-solid: #1F2328;
  --well: rgba(0, 0, 0, 0.28);
  --brass: #D9A441;
  --brass-soft: rgba(217, 164, 65, 0.18);
  --brass-ink: #1A1610;
  --agent: #7FA7D9;
  --agent-soft: rgba(127, 167, 217, 0.16);
  --ok: #7CC383;
  --bad: #E06C5A;
  --bad-soft: rgba(224, 108, 90, 0.16);
  --vp-top: #3A3F47;
  --vp-bottom: #14171B;
  --radius: 12px;
  --radius-s: 7px;
  --font: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --gap: 10px;
  --bar-h: 46px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--vp-bottom);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
h2 { font-size: 13px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
h3 { font-size: 13.5px; font-weight: 600; margin: 14px 0 4px; }
code { font-family: var(--mono); font-size: 12px; background: var(--well); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.grow { flex: 1; }

/* Layout grid: the viewport sits behind everything; panels float in the cells. */
#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: 250px 1fr 272px;
  grid-template-rows: var(--bar-h) 1fr auto;
  gap: var(--gap);
  padding: var(--gap);
  pointer-events: none;
}
#app > * { pointer-events: auto; min-height: 0; }

#viewport {
  grid-area: 1 / 1 / -1 / -1;
  margin: calc(-1 * var(--gap));
  position: relative;
  background: radial-gradient(120% 90% at 50% 35%, var(--vp-top) 0%, var(--vp-bottom) 100%);
  z-index: 0;
}
#gl { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.viewport-empty {
  position: absolute; top: 0; bottom: 0; left: 270px; right: 292px;
  display: grid; place-content: center; text-align: center;
  pointer-events: none; padding: 0 24px;
}
.viewport-empty p { margin: 4px 0; font-size: 15px; }
.viewport-empty p.muted { font-size: 13px; }
.viewport-corner {
  position: absolute; left: 270px; bottom: 16px; font-size: 12px; color: var(--ink-3);
  pointer-events: none;
}

.panel {
  z-index: 2;
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.panel-body { overflow: auto; padding: 8px; flex: 1; min-height: 0; }
.count { color: var(--ink-3); font-size: 12px; }
.collapse { color: var(--ink-3); width: 22px; height: 22px; border-radius: 5px; font-size: 16px; line-height: 1; }
.collapse:hover { background: var(--line); color: var(--ink); }

/* Collapsed side panels shrink to a tab */
.panel.side.collapsed { width: 34px; justify-self: start; }
#inspector.collapsed { justify-self: end; }
.panel.side.collapsed .panel-body, .panel.side.collapsed h2, .panel.side.collapsed .count { display: none; }
.panel.side.collapsed .panel-head { border: 0; padding: 8px 5px; justify-content: center; }
.panel.bottom.collapsed .panel-body { display: none; }

/* Top bar */
.bar { grid-area: 1 / 1 / 2 / -1; flex-direction: row; align-items: center; gap: 12px; padding: 0 10px 0 12px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.scene-name {
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 4px 8px; font-weight: 600; font-size: 14px; width: 190px; min-width: 0;
}
.scene-name:hover, .scene-name:focus { border-color: var(--line-strong); background: var(--well); outline: none; }
.bar-group { display: flex; align-items: center; gap: 4px; }
.bar-group.right { margin-left: auto; }
.sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 6px; }
.icon-btn, .text-btn {
  height: 30px; padding: 0 10px; border-radius: var(--radius-s);
  color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.icon-btn { width: 30px; padding: 0; font-size: 17px; }
.icon-btn:hover, .text-btn:hover { background: var(--line); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.text-btn.is-on { color: var(--ink); background: var(--line); }
.text-btn.primary { background: var(--brass); color: var(--brass-ink); font-weight: 600; }
.text-btn.primary:hover { background: #E6B451; }
.text-btn.small { height: 24px; padding: 0 8px; font-size: 12px; }
.text-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

.status {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 10px 0 8px;
  border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); font-size: 12.5px;
}
.status:hover { background: var(--line); color: var(--ink); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.status.native .dot, .status.polyfill .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.jsonly .dot { background: var(--brass); }
.status.busy .dot { animation: pulse 0.9s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Menus */
.menu { position: relative; }
.menu-items {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 170px;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  padding: 4px; display: none; flex-direction: column; z-index: 20; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}
.menu.open .menu-items { display: flex; }
.menu-items button { text-align: left; padding: 7px 10px; border-radius: 5px; color: var(--ink); }
.menu-items button:hover { background: var(--line); }

/* Side panels */
#outliner { grid-area: 2 / 1 / 3 / 2; }
#inspector { grid-area: 2 / 3 / 3 / 4; }
.tree, .flat { list-style: none; margin: 0; padding: 0; }
.tree li { margin: 0; }
.tree .row, .flat .row {
  display: flex; align-items: center; gap: 7px; padding: 5px 7px; border-radius: 6px;
  cursor: pointer; user-select: none; color: var(--ink);
}
.tree .row:hover, .flat .row:hover { background: var(--line); }
.tree .row.selected { background: var(--brass-soft); color: var(--brass); }
.tree .row .glyph, .flat .row .glyph { width: 16px; text-align: center; color: var(--ink-3); font-size: 12px; flex: none; }
.tree .row.selected .glyph { color: var(--brass); }
.tree .row .name, .flat .row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flat .row .dim { color: var(--ink-3); font-size: 12px; }
.tree .row .eye { color: var(--ink-3); opacity: 0; width: 18px; height: 18px; border-radius: 4px; font-size: 12px; }
.tree .row:hover .eye, .tree .row.hidden-obj .eye { opacity: 1; }
.tree .row.hidden-obj { color: var(--ink-3); }
.tree ul { list-style: none; margin: 0; padding-left: 12px; border-left: 1px solid var(--line); margin-left: 14px; }
.tree .row.pulse { animation: rowpulse 1.2s ease-out; }
@keyframes rowpulse { 0% { background: var(--agent-soft); } 100% { background: transparent; } }
.swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line-strong); flex: none; }
.sub { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.sub summary { cursor: pointer; color: var(--ink-2); font-size: 12.5px; padding: 4px 7px; list-style: none; display: flex; gap: 6px; }
.sub summary::-webkit-details-marker { display: none; }
.sub summary::before { content: "\203A"; display: inline-block; width: 10px; transition: transform 0.15s; }
.sub[open] summary::before { transform: rotate(90deg); }
.empty-hint { color: var(--ink-3); padding: 6px 7px; font-size: 12.5px; }

/* Inspector */
.field { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 6px; padding: 4px 6px; }
.field label { color: var(--ink-2); font-size: 12.5px; }
.field input[type="text"], .field select, .field input[type="number"] {
  width: 100%; height: 26px; background: var(--well); border: 1px solid transparent; border-radius: 5px;
  padding: 0 7px; font-size: 12.5px; min-width: 0;
}
.field select option { background: var(--panel-solid); }
.field input:focus, .field select:focus { border-color: var(--line-strong); outline: none; }
.field .triple { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.field .triple input { font-family: var(--mono); font-size: 11.5px; padding: 0 5px; }
.field input[type="color"] { width: 26px; height: 26px; padding: 0; border: 0; background: none; }
.field input[type="range"] { width: 100%; accent-color: var(--brass); }
.field input[type="checkbox"] { accent-color: var(--brass); justify-self: start; }
.field .kv { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); white-space: pre-wrap; word-break: break-word; }
.field-group { padding: 6px 0; border-top: 1px solid var(--line); margin-top: 6px; }
.field-group:first-child { border-top: 0; margin-top: 0; }
.field-group h4 { margin: 2px 6px 4px; font-size: 12px; color: var(--ink-3); font-weight: 500; }
.inspector-actions { display: flex; gap: 4px; padding: 8px 6px 2px; flex-wrap: wrap; }

/* Activity bar */
#activity { grid-area: 3 / 1 / 4 / -1; max-height: 38vh; }
#activity .panel-body { display: flex; flex-direction: column; padding: 0; }
.activity-list {
  list-style: none; margin: 0; padding: 6px 8px; overflow: auto; flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.activity-list:empty::before {
  content: "Tool calls appear here as an agent works. Each entry shows what was called and what came back.";
  color: var(--ink-3); padding: 8px 6px; display: block; font-size: 12.5px;
}
.entry {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; align-items: start;
  padding: 6px 8px; border-radius: 8px; background: transparent;
  animation: entry-in 0.35s ease-out;
}
.entry.is-new { background: var(--agent-soft); }
@keyframes entry-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.entry .rail { width: 6px; height: 6px; border-radius: 50%; background: var(--agent); margin-top: 6px; }
.entry.error .rail { background: var(--bad); }
.entry.user .rail { background: var(--brass); }
.entry .body { min-width: 0; }
.entry .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.entry .tool { font-weight: 600; }
.entry .args { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.entry .result { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.entry.error .result { color: var(--bad); }
.entry .meta { color: var(--ink-3); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry .thumbs { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.entry .thumbs img { height: 72px; border-radius: 6px; border: 1px solid var(--line-strong); cursor: zoom-in; background: #000; }
.entry details { margin-top: 3px; }
.entry details summary { cursor: pointer; color: var(--ink-3); font-size: 12px; }
.entry details pre { margin: 4px 0 0; font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow: auto; background: var(--well); padding: 6px 8px; border-radius: 6px; }
.console { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 6px 8px 6px 12px; flex: none; }
.console .prompt { color: var(--brass); font-family: var(--mono); }
.console input { flex: 1; background: transparent; border: 0; font-family: var(--mono); font-size: 12.5px; min-width: 0; }
.console input:focus { outline: none; }
.console input::placeholder { color: var(--ink-3); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.78);
  display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 30px; gap: 10px;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  background: repeating-conic-gradient(#2a2d33 0% 25%, #202328 0% 50%) 0 0 / 20px 20px; }
.lightbox-bar { display: flex; gap: 10px; align-items: center; color: var(--ink-2); font-size: 12.5px; }
.lightbox-bar a { text-decoration: none; }

/* Help dialog */
.help { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--panel-solid); color: var(--ink); padding: 0; max-width: 560px; width: calc(100vw - 40px); }
.help::backdrop { background: rgba(0, 0, 0, 0.55); }
.help form { margin: 0; }
.help-body { padding: 4px 16px 16px; line-height: 1.5; }
.help-body ol { padding-left: 20px; }
.help-body li { margin: 6px 0; }

/* Toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); top: 60px; z-index: 60; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); animation: entry-in 0.25s ease-out; }
.toast.error { border-color: var(--bad); color: var(--bad); }

.only-narrow { display: none; }

/* Narrow screens: side panels become overlays, activity stays a strip. */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: var(--bar-h) 1fr auto; }
  .bar { grid-area: 1 / 1 / 2 / 2; gap: 6px; }
  .bar .sep, .bar .text-btn:not(.primary), #btn-view { display: none; }
  .scene-name { width: 120px; }
  .only-narrow { display: inline-flex; }
  #outliner, #inspector {
    grid-area: 2 / 1 / 3 / 2; display: none; width: min(300px, 80vw);
  }
  #app.panels-open #outliner { display: flex; justify-self: start; }
  #app.panels-open #inspector { display: flex; justify-self: end; }
  #activity { grid-area: 3 / 1 / 4 / 2; max-height: 42vh; }
  .viewport-corner { left: 16px; }
  .viewport-empty { left: 0; right: 0; }
  .entry .args { max-width: 50vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
