/* ==========================================================================
   Code Genie — full-window VS Code-style layout, multi-format toolbar,
   JSON tree/query panel, and dark CodeMirror theme.
   Inherits tokens from ../css/protium-ui.css
   ========================================================================== */

.genie-main { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.genie-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- toolbar (every action visible) ------------------------------------- */
.genie-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--nav);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.genie-toolbar .spacer { flex: 1 1 auto; }
.genie-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.genie-select {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 8px 30px 8px 12px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e9cbd' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.genie-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.genie-status { display: flex; align-items: center; gap: 10px; }
.genie-meta { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* "local · no upload" indicator in the status bar */
.pt-statusbar .sb-local { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); margin-right: 14px; }
.pt-statusbar .sb-local .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

/* hide language-specific controls when not applicable */
.genie-toolbar.not-json .json-only { display: none; }
.genie-toolbar.not-web .web-only { display: none; }

/* ---- body: editor + optional tree panel --------------------------------- */
.genie-body { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.genie-cm { position: relative; flex: 1; min-width: 0; }
.genie-cm .CodeMirror {
  position: absolute; inset: 0; height: 100%;
  background: var(--field); color: var(--text);
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.7; border: 0;
}

/* ---- tree / query side panel -------------------------------------------- */
.genie-tree {
  position: relative;
  flex: 0 0 40%;
  max-width: 560px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
}

/* drag handle on the left edge of a side panel */
.genie-grip { position: absolute; left: -3px; top: 0; bottom: 0; width: 8px; z-index: 6; cursor: col-resize; touch-action: none; }
.genie-grip::before { content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 1px; background: transparent; transition: background var(--t), width var(--t); }
.genie-grip:hover::before, .genie-grip.is-active::before { background: var(--accent); width: 2px; left: 2px; }
.genie-tree-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.genie-tree-head .pt-input { font-family: var(--font-mono); font-size: 12.5px; }
.genie-tree-close {
  flex: none; width: 36px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); border-radius: var(--r-md); cursor: pointer;
}
.genie-tree-close:hover { color: var(--text); border-color: var(--border-strong); }
.genie-tree-close svg { width: 15px; height: 15px; }
.genie-tree-meta { padding: 8px 14px; font-size: 12px; color: var(--text-faint); border-bottom: 1px solid var(--border-faint); }
.genie-tree-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 10px 16px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; }

/* tree nodes */
.tnode { white-space: nowrap; }
.tnode-row { display: flex; align-items: flex-start; gap: 4px; border-radius: 5px; padding: 0 4px; }
.tnode-row:hover { background: var(--surface-2); }
.tnode-row.is-match { background: var(--warn-soft); }
.tcaret { width: 14px; flex: none; color: var(--text-faint); cursor: pointer; user-select: none; text-align: center; }
.tcaret.empty { visibility: hidden; }
.tkey { color: #9cdcfe; cursor: pointer; }
.tcolon { color: var(--text-muted); margin: 0 4px 0 0; }
.tval-string { color: #ce9178; }
.tval-number { color: #b5cea8; }
.tval-boolean, .tval-null { color: #569cd6; }
.tcount { color: var(--text-faint); margin-left: 6px; font-style: italic; }
.tchildren { padding-left: 16px; border-left: 1px solid var(--border-faint); margin-left: 6px; }
.tchildren.collapsed { display: none; }

/* ---- Simulate live-preview panel ---------------------------------------- */
.genie-sim {
  position: relative;
  flex: 0 0 44%;
  max-width: 660px;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.sim-head { align-items: center; }
.sim-head .spacer { flex: 1 1 auto; }
.sim-title { font-size: 12.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* view-size toggle (Fit / 16:9 / 9:16) */
.sim-views { display: inline-flex; gap: 2px; padding: 2px; background: var(--field); border: 1px solid var(--border); border-radius: var(--r-sm); }
.sim-views button { font: inherit; font-size: 11.5px; font-weight: 600; color: var(--text-faint); background: transparent; border: 0; padding: 4px 9px; border-radius: 4px; cursor: pointer; transition: color var(--t), background var(--t); }
.sim-views button:hover { color: var(--text); }
.sim-views button.is-active { background: var(--accent); color: #fff; }
#sim-run svg { width: 13px; height: 13px; }

/* stage: holds the preview; dark backdrop behind device frames */
.sim-stage { position: relative; flex: 1; min-height: 0; background: var(--bg); overflow: auto; }
.sim-stage[data-vp="fit"] { overflow: hidden; }
.sim-frame { border: 0; background: #fff; }
.sim-stage[data-vp="fit"] .sim-frame { position: absolute; inset: 0; width: 100%; height: 100%; }
.sim-stage[data-vp="16:9"], .sim-stage[data-vp="9:16"] { display: flex; align-items: center; justify-content: center; padding: 16px; }
.sim-stage[data-vp="16:9"] .sim-frame,
.sim-stage[data-vp="9:16"] .sim-frame { position: relative; flex: none; max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 12px 34px -14px rgba(0,0,0,0.75); }
.sim-stage[data-vp="16:9"] .sim-frame { width: 100%; height: auto; aspect-ratio: 16 / 9; }
.sim-stage[data-vp="9:16"] .sim-frame { height: 100%; width: auto; aspect-ratio: 9 / 16; }

.sim-substrip { flex: none; display: flex; align-items: center; padding: 5px 12px; border-top: 1px solid var(--border-faint); }
.sim-sub { font-size: 11.5px; color: var(--text-faint); }
.sim-console {
  flex: 0 0 130px; overflow: auto; background: var(--field); border-top: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6; padding: 8px 12px;
}
.sim-console:empty::before { content: "console output appears here"; color: var(--text-faint); font-style: italic; }
.sim-line { white-space: pre-wrap; word-break: break-word; color: var(--text-muted); padding: 1px 0; }
.sim-line.sim-error { color: var(--bad); }
.sim-line.sim-warn { color: var(--warn); }

/* ---- error strip -------------------------------------------------------- */
.genie-error {
  flex: none; display: none; align-items: flex-start; gap: 10px;
  padding: 11px 18px; background: var(--bad-soft); border-top: 1px solid var(--bad-border);
  color: var(--bad); font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; max-height: 30vh; overflow: auto;
}
.genie-error.is-show { display: flex; }
.genie-error svg { width: 15px; height: 15px; flex: none; margin-top: 1px; }

/* ==========================================================================
   CodeMirror theme: .cm-s-protium  (VS Code Dark+ inspired)
   ========================================================================== */
.cm-s-protium.CodeMirror { background: var(--field); color: #d4d4d4; }
.cm-s-protium .CodeMirror-gutters { background: var(--field); border-right: 1px solid var(--border); }
.cm-s-protium .CodeMirror-linenumber { color: var(--text-faint); }
.cm-s-protium .CodeMirror-cursor { border-left: 1.5px solid #aed6ff; }
.cm-s-protium .CodeMirror-activeline-background { background: rgba(255,255,255,0.03); }
.cm-s-protium .CodeMirror-selected { background: var(--accent-soft) !important; }
.cm-s-protium .CodeMirror-focused .CodeMirror-selected { background: var(--accent-soft) !important; }

.cm-s-protium .cm-string { color: #ce9178; }
.cm-s-protium .cm-string-2 { color: #ce9178; }
.cm-s-protium .cm-property { color: #9cdcfe; }
.cm-s-protium .cm-string.cm-property { color: #9cdcfe; }
.cm-s-protium .cm-number { color: #b5cea8; }
.cm-s-protium .cm-atom { color: #569cd6; }
.cm-s-protium .cm-keyword { color: #c586c0; }
.cm-s-protium .cm-def, .cm-s-protium .cm-variable { color: #dcdcaa; }
.cm-s-protium .cm-variable-2 { color: #9cdcfe; }
.cm-s-protium .cm-tag { color: #569cd6; }
.cm-s-protium .cm-attribute { color: #9cdcfe; }
.cm-s-protium .cm-comment { color: #6a9955; }
.cm-s-protium .cm-operator { color: #d4d4d4; }
.cm-s-protium .cm-punctuation, .cm-s-protium .cm-bracket { color: #d4d4d4; }
.cm-s-protium .cm-error { color: var(--bad); }

.cm-s-protium .CodeMirror-matchingbracket { color: #aed6ff !important; border-bottom: 1px solid #aed6ff; }
.cm-s-protium .CodeMirror-foldmarker { color: var(--accent); text-shadow: none; background: var(--accent-soft); border-radius: 4px; padding: 0 4px; }
.cm-s-protium .CodeMirror-foldgutter-open:after { color: var(--text-faint); }
.cm-s-protium .CodeMirror-foldgutter-folded:after { color: var(--accent); }
.cm-error-highlight { background: var(--bad-soft); }

/* scrollbars */
.CodeMirror-vscrollbar::-webkit-scrollbar, .CodeMirror-hscrollbar::-webkit-scrollbar { width: 12px; height: 12px; }
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 999px; border: 3px solid var(--field);
}

@media (max-width: 860px) {
  .genie-tree { flex-basis: 100%; max-width: none; }
  .genie-meta { display: none; }
}
