* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
  margin: 0;
}

body {
  background: #101214;
  color: #d8dee9;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  height: 30px;
  border: 1px solid #3a4653;
  background: #1a2028;
  color: #d8dee9;
  cursor: pointer;
}

button:hover {
  background: #24303b;
}

button:disabled {
  color: #6c7683;
  cursor: default;
}

button.active {
  border-color: #3da5ff;
  background: #15314a;
}

button.current-cell {
  border-color: #ffcc66;
  background: #3a2f12;
  color: #ffe2a3;
}

input,
textarea,
select {
  height: 30px;
  border: 1px solid #3a4653;
  background: #111821;
  color: #d8dee9;
}

textarea {
  height: auto;
  min-height: 78px;
  padding: 8px;
  resize: vertical;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 300px;
  grid-template-rows: 48px minmax(0, 1fr);
  height: 100%;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 120px 64px;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid #2c3642;
  background: #151a21;
  padding: 8px 12px;
}

.brand {
  font-size: 15px;
  font-weight: 700;
}

.open-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 72px 72px;
  gap: 8px;
}

.open-form input,
.open-form select {
  width: 100%;
  padding: 0 10px;
}

.session-pill {
  justify-self: end;
  border: 1px solid #3a4653;
  padding: 4px 9px;
  color: #9fb1c2;
  font-size: 12px;
}

.session-close {
  width: 64px;
}

.left-pane,
.right-pane {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid #2c3642;
  background: #12171e;
}

.right-pane {
  display: flex;
  flex-direction: column;
  border-right: 0;
  border-left: 1px solid #2c3642;
  overflow: hidden;
}

.left-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel {
  border-bottom: 1px solid #2c3642;
  padding: 10px;
}

.panel h2 {
  margin: 0 0 8px;
  color: #9fb1c2;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tree-list,
.layer-list {
  display: grid;
  gap: 4px;
}

.right-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 0 0 auto;
  border-bottom: 1px solid #2c3642;
  background: #151a21;
  padding: 6px;
  gap: 6px;
}

.right-tabs button {
  width: 100%;
}

.left-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 0 0 auto;
  border-bottom: 1px solid #2c3642;
  background: #151a21;
  padding: 6px;
  gap: 6px;
}

.left-tabs button {
  width: 100%;
  min-width: 0;
}

.left-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border-bottom: 0;
}

.right-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  border-bottom: 0;
}

.cells-panel .tree-list {
  max-height: min(520px, calc(100vh - 150px));
  overflow: auto;
  padding-right: 2px;
}

.cell-layout-tree {
  min-height: 0;
  overflow: auto;
}

.cell-layout-node {
  margin-bottom: 10px;
}

.cell-layout-root {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  height: 30px;
  margin-bottom: 4px;
  padding: 0 8px;
  border-color: #26313d;
  color: #c7d2df;
  text-align: left;
}

.cell-layout-node.active .cell-layout-root {
  border-color: #3da5ff;
  color: #7fc4ff;
}

.layout-toggle {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  min-height: 30px;
  margin-bottom: 8px;
  color: #c7d2df;
  font-size: 13px;
}

.tree-list button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  text-align: left;
}

.cell-tree-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  min-height: 32px;
}

.cell-tree-row.active .cell-tree-select {
  border-color: #3da5ff;
  color: #d9efff;
}

.cell-tree-row .tree-expander {
  display: grid;
  place-items: center;
  width: 22px;
  height: 28px;
  padding: 0;
  color: #8b97a5;
  text-align: center;
}

.cell-tree-row .tree-expander:disabled {
  opacity: 0.6;
}

.cell-tree-row .cell-tree-select {
  grid-template-columns: minmax(0, 1fr) auto;
}

.tree-list span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-name {
  display: block;
}

.tree-list small {
  color: #8b97a5;
}

.layer-list label {
  display: grid;
  grid-template-columns: 18px 28px minmax(0, 1fr) 78px;
  gap: 7px;
  align-items: center;
  min-height: 32px;
}

.layer-tree {
  min-height: 0;
  overflow: auto;
}

.layout-root {
  border-bottom: 1px solid #26313d;
  padding-bottom: 8px;
}

.layout-root button {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.layout-node.active .layout-root button {
  color: #7fc4ff;
  font-weight: 700;
}

.layout-root span,
.layer-group-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-group {
  margin-top: 8px;
}

.layer-group-title {
  margin: 0 0 6px 24px;
  color: #9fb1c2;
  font-size: 12px;
  font-weight: 700;
}

.layer-group .layer-list {
  margin-left: 18px;
}

.layer-list span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swatch {
  width: 28px;
  padding: 0;
}

.chat-panel {
  gap: 10px;
  overflow: hidden;
}

.chat-messages {
  display: grid;
  align-content: start;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding-right: 2px;
}

.chat-empty {
  color: #6c7683;
  font-size: 13px;
}

.chat-message {
  border: 1px solid #2c3642;
  background: #151b23;
  padding: 8px;
  min-width: 0;
}

.chat-message strong {
  display: block;
  margin-bottom: 4px;
  color: #9fb1c2;
  font-size: 12px;
  text-transform: uppercase;
}

.chat-message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-message.user {
  border-color: #37526b;
  background: #152334;
}

.chat-message.pending {
  border-color: #3a4653;
  background: #111820;
}

.chat-message.queued {
  border-color: #354252;
  background: #121923;
}

.chat-message.stopped,
.chat-message.error {
  border-color: #5b3b3b;
  background: #201718;
}

.chat-results,
.chat-artifacts {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.chat-results details,
.chat-artifacts article {
  border: 1px solid #26313d;
  background: #0f141b;
  padding: 6px;
  min-width: 0;
}

.chat-results summary {
  cursor: pointer;
  color: #9fb1c2;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chat-results pre,
.chat-artifacts pre {
  margin: 6px 0 0;
  color: #d8dee9;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-artifacts a,
.chat-artifacts small {
  display: block;
  margin-top: 4px;
  color: #7fc4ff;
  word-break: break-all;
}

.chat-waiting {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 16px;
}

.chat-queued {
  color: #9fb1c2;
  font-size: 12px;
}

.chat-waiting em {
  margin-right: 3px;
  color: #9fb1c2;
  font-style: normal;
  font-size: 12px;
}

.chat-waiting .dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9fb1c2;
  animation: chat-wait 900ms ease-in-out infinite;
}

.chat-waiting .dot.two {
  animation-delay: 120ms;
}

.chat-waiting .dot.three {
  animation-delay: 240ms;
}

@keyframes chat-wait {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.chat-compose {
  display: grid;
  flex: 0 0 auto;
  gap: 8px;
}

.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.chat-actions button {
  width: 76px;
}

.chat-actions .secondary {
  border-color: #6a3f43;
  color: #ffd6d6;
}

.chat-error {
  color: #ffd0d0;
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid #2c3642;
  background: #151a21;
  padding: 6px 8px;
}

.toolbar label {
  display: inline-grid;
  grid-template-columns: auto 56px;
  gap: 5px;
  align-items: center;
  color: #9fb1c2;
  font-size: 12px;
}

.toolbar input {
  width: 56px;
  padding: 0 6px;
}

.canvas {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(#151b23 1px, transparent 1px),
    linear-gradient(90deg, #151b23 1px, transparent 1px),
    #101214;
  background-size: 32px 32px;
  user-select: none;
  touch-action: none;
}

.canvas img {
  position: absolute;
  right: auto;
  bottom: auto;
  display: block;
  object-fit: fill;
  max-width: none;
  max-height: none;
  will-change: left, top, width, height;
}

.empty-canvas {
  display: grid;
  place-items: center;
  height: 100%;
  color: #6c7683;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image: radial-gradient(circle, rgba(216, 222, 233, 0.34) 0 1px, transparent 1.5px);
  pointer-events: none;
}

.canvas-axis {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.canvas-axis::before,
.canvas-axis::after {
  content: "";
  position: absolute;
  background: rgba(255, 204, 102, 0.86);
  box-shadow: 0 0 0 1px rgba(16, 18, 20, 0.35);
}

.canvas-axis::before {
  display: var(--axis-x-display);
  left: 0;
  right: 0;
  top: var(--axis-y);
  height: 1px;
}

.canvas-axis::after {
  display: var(--axis-y-display);
  top: 0;
  bottom: 0;
  left: var(--axis-x);
  width: 1px;
}

.canvas-coordinate {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 4;
  max-width: calc(100% - 20px);
  border: 1px solid rgba(58, 70, 83, 0.9);
  background: rgba(16, 18, 20, 0.82);
  color: #d8dee9;
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
  white-space: nowrap;
}

.canvas-status-stack {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 4px;
  max-width: calc(100% - 20px);
  pointer-events: none;
}

.canvas-status {
  max-width: min(520px, 100%);
  overflow: hidden;
  border: 1px solid rgba(58, 70, 83, 0.9);
  background: rgba(16, 18, 20, 0.82);
  color: #d8dee9;
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ruler-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: visible;
  pointer-events: none;
}

.ruler-graphic line {
  stroke: #ffffff;
  stroke-width: 1;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 1px rgba(16, 18, 20, 0.75));
}

.ruler-graphic.preview line {
  stroke-dasharray: 6 4;
  opacity: 0.82;
}

.ruler-graphic.preview text {
  opacity: 0.88;
}

.ruler-arrow-head {
  fill: #ffffff;
}

.ruler-graphic text {
  fill: #edf7ff;
  stroke: rgba(16, 18, 20, 0.92);
  stroke-width: 4px;
  paint-order: stroke;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.rubber-band {
  position: absolute;
  z-index: 5;
  border: 1px solid #ffcc66;
  background: rgba(255, 204, 102, 0.14);
  pointer-events: none;
}

.selection-highlight {
  position: absolute;
  z-index: 3;
  border: 2px solid #ffcc66;
  background: rgba(255, 204, 102, 0.12);
  box-shadow: 0 0 0 1px rgba(16, 18, 20, 0.8);
  pointer-events: none;
}

.stats dl {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
}

.stats dt {
  color: #8b97a5;
}

.stats dd {
  margin: 0;
}

.state-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.state-table th,
.state-table td {
  border-bottom: 1px solid #26313d;
  padding: 6px 4px;
  vertical-align: top;
}

.state-table th {
  width: 96px;
  color: #8b97a5;
  font-weight: 600;
  text-align: left;
}

.state-table td {
  color: #d8dee9;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.table-scroll {
  min-height: 0;
  overflow: auto;
}

.ruler-table {
  min-width: 760px;
  table-layout: auto;
}

.ruler-table th {
  width: auto;
  white-space: nowrap;
}

.ruler-table td {
  white-space: nowrap;
}

.ruler-table .points-cell,
.ruler-table .target-cell {
  min-width: 180px;
  white-space: pre-wrap;
}

.empty-state {
  margin: 0;
  color: #8b97a5;
  font-size: 12px;
}

.state-value {
  display: block;
  max-height: 96px;
  overflow: auto;
}

pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  color: #c7d2df;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 32px));
  border: 1px solid #a84f4f;
  background: #271a1c;
  color: #ffd0d0;
  padding: 10px 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 230px minmax(320px, 1fr);
  }

  .right-pane {
    display: none;
  }
}
