/* Layout zones — docs/DESIGN.md §4.
 *
 * The rule that shapes everything here: **the canvas is the page**. `#main` is
 * the positioning context and `#canvas` covers it completely (`inset: 0`).
 * Everything else — tool rail, panels, console — is a card floating above it.
 * So opening a panel never changes the drawing's width, which is what makes a
 * panel toggle safe to use while you are looking at something. */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--f-ui);
  font-size: 13px;
  color: var(--t-hi);
  background: var(--s1);
}

#app {
  display: grid;
  grid-template-rows: var(--h-toolbar) 1fr var(--h-console) var(--h-status);
  height: 100%;
}

/* ── toolbar ─────────────────────────────────────────────────────────────── */

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--s0);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--e1);
  z-index: 50;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.2px;
  margin-right: 4px;
}

.brand .ver {
  color: var(--t-lo);
  font-family: var(--f-mono);
  font-size: 11px;
  margin-left: 6px;
}

.sep {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 4px;
}

button {
  font: inherit;
  color: var(--t-hi);
  background: var(--s0);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  cursor: pointer;
}

button:hover {
  background: var(--s-hover);
}

button:active {
  background: var(--s-press);
}

button:disabled {
  color: var(--t-lo);
  cursor: default;
  background: var(--s2);
}

button.primary {
  background: var(--ac);
  border-color: var(--ac);
  color: #fff;
}

button.primary:hover {
  background: var(--ac-hover);
}

button.primary:active {
  background: var(--ac-press);
}

button.active {
  background: var(--ac-soft);
  border-color: var(--ac-line);
  color: var(--ac-press);
}

.spacer {
  flex: 1;
}

/* ── main + canvas ───────────────────────────────────────────────────────── */

#main {
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* The canvas element itself carries the dark background so that the moment
   * before the first frame is not a white flash. */
  background: var(--canvas-bg);
  touch-action: none;
}

/* Tool rail: 52px, floating over the canvas. */
#tool-rail {
  position: absolute;
  top: 12px;
  left: 12px;
  width: var(--w-rail);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--s0);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--e2);
  z-index: 40;
}

#tool-rail button {
  border: none;
  background: transparent;
  padding: 8px 0;
  border-radius: var(--r-sm);
  font-size: 11px;
}

#tool-rail button:hover {
  background: var(--s-hover);
}

/* Panels: cards over the canvas, right dock by default. */
.panel {
  position: absolute;
  width: 272px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: var(--s0);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--e2);
  z-index: 30;
  overflow: hidden;
}

.panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  /* No uppercase — DESIGN.md §3 names that explicitly. */
  text-transform: none;
}

.panel-header .grip {
  color: var(--t-lo);
  cursor: move;
  font-family: var(--f-mono);
}

.panel-body {
  padding: 10px;
  overflow: auto;
  font-size: 12px;
  color: var(--t-mid);
}

#panel-info {
  top: 12px;
  right: 12px;
}

/* Left dock, under the tool rail. */
#panel-layers {
  top: 12px;
  left: calc(12px + var(--w-rail) + 12px);
  width: 248px;
  max-height: 60%;
}

.layer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.layer:hover {
  background: var(--s-hover);
}

.layer .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid var(--line-strong);
  flex: none;
}

.layer .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--t-hi);
}

/* A layer with no geometry is listed, not hidden: its absence from the drawing
 * is information, and a list that silently omits things is a list you cannot
 * trust. It is dimmed because toggling it does nothing. */
.layer.empty .name {
  color: var(--t-lo);
}

.layer .count {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--t-lo);
}

#panel-diagnostics {
  bottom: 12px;
  right: 12px;
  max-height: 45%;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
}

.kv dt {
  color: var(--t-lo);
}

.kv dd {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--t-hi);
}

/* Diagnostics are never decoration. A drawing that lost a layer says so here,
 * and the warning colour is what stops it reading as a caption. */
.diag {
  padding: 6px 8px;
  margin-bottom: 6px;
  border-left: 3px solid var(--warn);
  background: var(--s2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--t-hi);
  font-size: 11px;
  line-height: 1.45;
}

.diag.clean {
  border-left-color: var(--success);
  color: var(--t-mid);
}

/* ── command console ─────────────────────────────────────────────────────── */

#command-console {
  display: flex;
  flex-direction: column;
  background: var(--s0);
  border-top: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: 12px;
}

#console-history {
  flex: 1;
  overflow: auto;
  padding: 6px 10px;
  color: var(--t-mid);
  white-space: pre-wrap;
}

#console-history .err {
  color: var(--danger);
}

#console-history .ok {
  color: var(--success);
}

#console-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--s2);
  border-top: 1px solid var(--line);
}

#console-line label {
  color: var(--t-mid);
}

#console-input {
  flex: 1;
  font: inherit;
  color: var(--t-hi);
  background: transparent;
  border: none;
  outline: none;
}

/* ── status bar ──────────────────────────────────────────────────────────── */

#status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--s0);
  border-top: 1px solid var(--line);
  color: var(--t-mid);
  font-family: var(--f-mono);
  font-size: 11px;
}

#status-bar .grow {
  flex: 1;
}

/* ── the failure screen ──────────────────────────────────────────────────── */

/* WebGPU missing is a full-page state, not a toast. There is no WebGL
 * fallback, so there is nothing behind this to look at. */
#blocked {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--canvas-bg);
  color: #dfe4ee;
}

#blocked[hidden] {
  display: none;
}

#blocked .card {
  max-width: 560px;
  padding: 24px;
  background: var(--s0);
  color: var(--t-hi);
  border-radius: var(--r-lg);
  box-shadow: var(--e3);
}

#blocked h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

#blocked p {
  margin: 0;
  line-height: 1.6;
  color: var(--t-mid);
}

/* The OSNAP marker. Kept in dark-background colours, per DESIGN.md §2: the
 * canvas is outside the light scale and overlays on it are too. */
#snap-marker {
  position: absolute;
  z-index: 25;
  width: 13px;
  height: 13px;
  margin: -7px 0 0 -7px;
  border: 2px solid #33d17a;
  pointer-events: none;
}

#snap-marker[hidden] {
  display: none;
}

/* Endpoint is a square, midpoint a triangle, and so on in AutoCAD. One shape
 * with a label beside it is honest about doing less than that. */
#snap-marker::after {
  content: attr(data-kind);
  position: absolute;
  left: 17px;
  top: -2px;
  font-family: var(--f-mono);
  font-size: 10px;
  color: #33d17a;
  white-space: nowrap;
}

#drop-hint {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8891a8;
  pointer-events: none;
  font-size: 13px;
}

#drop-hint[hidden] {
  display: none;
}
