/* Drawing Language Editor — CAD-inspired dark UI, restrained accent, dense */

:root {
  --bg:            #0f1113;
  --surface:       #16191d;
  --surface-alt:   #1c2025;
  --surface-high:  #232830;
  --border:        #2a2f37;
  --border-strong: #3a4048;
  --text:          #d6d9de;
  --text-muted:    #8a9099;
  --text-faint:    #5b6169;
  --accent:        #4fb3bf;         /* muted teal — engineering blue-green */
  --accent-hover:  #6ac5d0;
  --success:       #7cb87c;
  --warning:       #d6a24a;
  --error:         #e07070;
  --mono:          "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  --sans:          -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100vh; overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 22px; color: var(--accent);
  line-height: 1;
}
.brand-text { line-height: 1.15; }
.brand-title { font-weight: 600; font-size: 14px; letter-spacing: 0.01em; }
.brand-sub { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); }
.btn {
  background: var(--accent);
  color: #0a1113;
  border: none;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn:hover { background: var(--accent-hover); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}
.btn.ghost:hover { background: var(--surface-alt); border-color: var(--accent); color: var(--accent); }

/* ---- Workspace grid ---- */
.workspace {
  display: grid;
  grid-template-columns: 260px minmax(340px, 1fr) minmax(340px, 1.2fr);
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;
}
.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0 0 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-count {
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.filter-row {
  margin-bottom: 8px;
}
.filter-row input[type="search"] {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 3px;
  outline: none;
}
.filter-row input[type="search"]:focus {
  border-color: var(--accent);
}
.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}
.tag {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--sans);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.1s, color 0.1s;
}
.tag:hover { border-color: var(--border-strong); color: var(--text); }
.tag.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 179, 191, 0.08);
}
.tag-count {
  font-size: 9px;
  color: var(--text-faint);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.tag.active .tag-count { color: var(--accent); }

.example-list { list-style: none; padding: 0; margin: 0; }
.example-list li {
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.example-list li:hover { background: var(--surface-alt); border-color: var(--border); }
.example-list li.active { background: var(--surface-high); border-color: var(--accent); color: var(--accent); }
.example-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.example-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-badge {
  font-size: 9px;
  color: var(--text-faint);
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.cat-examples        { color: var(--accent); }
.cat-frames          { color: var(--warning); }
.cat-symbols         { color: var(--success); }
.cat-frame-guides    { color: #b48fd6; }
.cat-extended-symbols{ color: #d09570; }
.cat-my-drawings     { color: var(--accent-hover); background: rgba(79, 179, 191, 0.12); }
.example-desc {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  line-height: 1.35;
}
.more-hint {
  cursor: default;
  color: var(--text-faint);
  font-size: 11px;
  padding: 8px 10px;
  font-style: italic;
}
.more-hint:hover { background: transparent; border-color: transparent; }

.ref-group { margin-bottom: 12px; }
.ref-heading {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 6px 0;
  font-weight: 600;
}
.ref-list { list-style: none; padding: 0; margin: 0; }
.ref-list li {
  padding: 5px 0;
  font-size: 11.5px;
  border-bottom: 1px dashed var(--border);
}
.ref-list li:last-child { border-bottom: none; }
.ref-sig { font-family: var(--mono); color: var(--accent); font-size: 11px; display: block; margin-bottom: 2px; }
.ref-desc { color: var(--text-muted); font-size: 11px; line-height: 1.35; }
.ref-footer { font-size: 11px; color: var(--text-faint); margin-top: 10px; line-height: 1.4; }

/* ---- Editor pane ---- */
.editor-pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.pane-header {
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  height: 34px;
  flex-shrink: 0;
}
.pane-title { font-size: 12px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.06em; }
.pane-hint { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.pane-spacer { flex: 1; }

.zoom-toolbar {
  display: flex; align-items: center; gap: 4px;
  font-family: var(--mono); font-size: 11px;
}
.zbtn {
  background: var(--bg); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 2px 8px; min-width: 24px; height: 22px;
  font-family: var(--mono); font-size: 11px; line-height: 1;
  cursor: pointer; user-select: none;
}
.zbtn:hover { background: var(--surface-alt); color: var(--text); border-color: var(--border-strong); }
.zbtn:active { transform: translateY(1px); }
.zoom-level {
  color: var(--text-muted); min-width: 46px; text-align: center;
  font-variant-numeric: tabular-nums;
}

#editor {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  padding: 16px 18px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  resize: none;
  tab-size: 2;
}

.status-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  min-height: 28px;
  flex-shrink: 0;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.status-bar.ok    .status-dot { background: var(--success); }
.status-bar.error .status-dot { background: var(--error); }
.status-bar.busy  .status-dot { background: var(--warning); animation: pulse 1s ease-in-out infinite; }
.status-bar.error #status-text { color: var(--error); }
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---- Preview pane ---- */
.preview-pane {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--surface-alt);
}
.preview-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;      /* pan/zoom controlled by JS, not native scroll */
  background:
    linear-gradient(var(--surface-alt), var(--surface-alt)),
    repeating-linear-gradient(0deg, transparent 0 19px, rgba(255,255,255,0.02) 19px 20px),
    repeating-linear-gradient(90deg, transparent 0 19px, rgba(255,255,255,0.02) 19px 20px);
  background-blend-mode: normal, normal, normal;
  cursor: grab;
  user-select: none;
}
.preview-canvas.dragging { cursor: grabbing; }
.preview-canvas svg {
  /* v0.6: SVG always fills the preview pane as a fixed A3 landscape sheet.
     The SVG's own viewBox (locked to 1191x801 language units in svg.py)
     plus preserveAspectRatio=xMidYMid meet handles scaling; small drawings
     sit at their real A3 position, big ones get clipped. Pan/zoom JS still
     applies a CSS transform on top for user interaction. */
  position: absolute;
  top: 12px; left: 12px;
  right: 12px; bottom: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  transform-origin: 0 0;
  background: #fafaf7;      /* paper */
  box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
  border-radius: 2px;
  display: block;
}
.preview-empty {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-size: 13px;
  font-style: italic;
}

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 220px 1fr; grid-template-rows: 55% 45%; }
  .preview-pane { grid-column: 2; }
  .editor-pane { grid-column: 2; grid-row: 1; }
  .sidebar { grid-column: 1; grid-row: 1 / span 2; }
}

/* v0.7 bidirectional selection */
#svg-host svg [data-statement-id][data-selected="true"] {
  outline: 2px solid #01696f;
  outline-offset: 2px;
}
#svg-host svg [data-statement-id][data-selected="true"] > * {
  stroke: #01696f !important;
  stroke-width: 2 !important;
}
#stmt-list .stmt-row.selected {
  background: #f0f7f8;
  border-left: 3px solid #01696f;
}
/* v0.7.2 toolbar hygiene: keep buttons on ONE line, no word-wrap. */
.app header button {
  white-space: nowrap;
  font-size: 13px;
  padding: 4px 10px;
  line-height: 1.3;
}

/* v0.7.2 text-editor: keyboard cursor row */
#stmt-list .stmt-row.cursor {
  border-left: 3px solid #f6b93b;
}
#stmt-list .stmt-row:focus {
  outline: 2px solid #01696f;
  outline-offset: -2px;
}
#stmt-list .stmt-row { cursor: text; }
#stmt-list .stmt-op, #stmt-list .stmt-args { cursor: text; }

/* v0.7 cursor bubble — floating readout + transform buttons following the mouse
   whenever there is at least one selected canvas statement. */
.cursor-bubble {
  position: fixed;
  z-index: 1000;
  background: #ffffff;
  border: 1px solid #d4d1ca;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 6px 8px;
  font-size: 11px;
  color: #28251d;
  pointer-events: auto;
  user-select: none;
  min-width: 160px;
}
.cursor-bubble .cb-coord {
  font-family: ui-monospace,Menlo,Consolas,monospace;
  color: #7a7974;
}
.cursor-bubble .cb-info {
  font-family: ui-monospace,Menlo,Consolas,monospace;
  color: #01696f;
  margin: 4px 0;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cursor-bubble .cb-buttons {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}
.cursor-bubble .cb-buttons button {
  width: 24px; height: 22px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
}
.cursor-bubble .cb-titlebar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid #eeece5;
  padding-bottom: 4px;
}
.cursor-bubble .cb-drag-handle {
  cursor: grab;
  color: #bab9b4;
  font-size: 12px;
  padding: 0 2px;
  user-select: none;
}
.cursor-bubble.dragging .cb-drag-handle { cursor: grabbing; }
.cursor-bubble .cb-pin,
.cursor-bubble .cb-close {
  border: 1px solid transparent;
  background: transparent;
  padding: 0 4px;
  font-size: 11px;
  cursor: pointer;
  color: #7a7974;
  border-radius: 3px;
}
.cursor-bubble .cb-pin:hover,
.cursor-bubble .cb-close:hover { background: #f2f0ea; }
.cursor-bubble[data-pinned="true"] .cb-pin { color: #01696f; background: #e6f2f3; border-color: #01696f; }
.cursor-bubble .cb-coord { flex: 1; }

/* v0.7 inline statement editor — double-click a cell to edit opcode/args. */
.stmt-inline-edit {
  font: inherit;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 1px 3px;
  border: 1px solid #01696f;
  border-radius: 3px;
  background: #fff;
  color: #28251d;
  outline: none;
}

/* v0.7 Frames tab — inline fields editor. */
.frame-fields-panel { padding: 6px 4px 10px; border-bottom: 1px solid #eeece5; }
.frame-fields-editor { font-size: 11px; }
.frame-fields-head,
.frame-fields-row {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 0.7fr 0.7fr 22px;
  gap: 4px;
  align-items: center;
  margin-bottom: 3px;
}
.frame-fields-head { color: #7a7974; font-size: 10px; padding: 0 2px; }
.frame-fields-row input {
  font-family: ui-monospace,Menlo,Consolas,monospace;
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid #d4d1ca;
  border-radius: 3px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.frame-fields-row .ff-del {
  background: transparent;
  border: 1px solid transparent;
  color: #a12c7b;
  cursor: pointer;
  padding: 0;
  font-size: 11px;
}
.frame-fields-actions {
  display: flex; gap: 4px; align-items: center; margin-top: 6px;
}
.frame-fields-actions button { font-size: 11px; padding: 2px 8px; }
.ff-status { font-size: 11px; margin-left: 4px; }
.ff-status.ok { color: #437a22; }
.ff-status.err { color: #a12c7b; }

/* v0.7 rubber-band selection — drag on empty canvas to marquee-select. */
.rubber-band {
  position: fixed;
  pointer-events: none;
  border: 1px dashed #01696f;
  background: rgba(1, 105, 111, 0.08);
  z-index: 900;
  border-radius: 2px;
}
