/* ==========================================================================
   app.css — layout, top bar, rail, buttons, splitters, status bar, toasts.
   Light "product" theme matching the Raiiotronix module photo.
   ========================================================================== */
:root {
  --font: Inter, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --surface-3: #F1F3F6;
  --border: #E5E8EC;
  --border-strong: #D5DAE0;
  --text: #1E2329;
  --text-2: #4A515B;
  --muted: #8A919B;
  --accent: #F37A33;
  --accent-600: #E2651D;
  --accent-50: #FFF3EB;
  --accent-100: #FEE3D1;
  --green: #22C55E;
  --red: #E5484D;
  --blue: #3E9BE0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 10px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 16px 36px -8px rgba(16, 24, 40, .18), 0 4px 10px -4px rgba(16, 24, 40, .08);
  --topbar-h: 60px;
  --status-h: 28px;
  --rail-w: 68px;
  --side-w: 232px;   /* category menu width (set by splitter) */
  --right-w: 400px;  /* right panel width (set by splitter) */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font-family: var(--mono); font-size: 11px; background: var(--surface-3); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Icons ---------- */
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 15px; height: 15px; }
.ic.xs { width: 13px; height: 13px; }

/* ---------- App grid ---------- */
.app { display: grid; grid-template-rows: var(--topbar-h) 1fr var(--status-h); height: 100vh; }
.main { display: flex; min-height: 0; position: relative; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 14px 0 18px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-xs); position: relative; z-index: 30; min-width: 0; }
.tb-left, .tb-center, .tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-left { flex: 1 1 auto; }
.tb-center { flex: none; }
.tb-right { flex: none; gap: 8px; }
.tb-sep { width: 1px; height: 26px; background: var(--border); flex: none; }

.logo { display: flex; align-items: center; text-decoration: none; flex: none; }
#logoText { font: 700 23px var(--font); fill: #3B4048; letter-spacing: -0.4px; }
/* Block Studio wordmark next to the Raiiotronix logo (orange brand colour) */
.product-name { margin-left: 8px; padding: 3px 9px; border-radius: 999px; background: var(--accent-50); color: var(--accent-600);
  font: 700 13px var(--font); letter-spacing: .2px; white-space: nowrap; border: 1px solid var(--accent-100); }
.sb-brand { color: var(--accent-600) !important; font-weight: 600; }

.project { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 10px; border-radius: 10px;
  border: 1px solid transparent; transition: background .15s, border-color .15s; min-width: 0; }
.project:hover { background: var(--surface-2); border-color: var(--border); }
.project:focus-within { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-100); }
#projectName { border: 0; outline: 0; background: transparent; font-weight: 600; font-size: 14.5px; width: 170px; min-width: 60px; text-overflow: ellipsis; }
.save-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.save-pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.save-pill.dirty i { background: #F5A524; }
.save-path-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }

.btn-group { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 2px; gap: 1px; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: transparent;
  border-radius: 8px; color: var(--text-2); transition: background .15s, color .15s; }
.icon-btn:hover { background: #fff; color: var(--text); box-shadow: var(--shadow-xs); }
.icon-btn:active { transform: translateY(0.5px); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.zoom-label { border: 0; background: transparent; font-size: 12px; font-weight: 600; color: var(--text-2);
  min-width: 46px; height: 32px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.zoom-label:hover { background: #fff; }

.tb-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border: 0;
  background: transparent; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--text-2);
  cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; user-select: none; }
.tb-btn:hover, .tb-btn:focus-visible { background: #fff; color: var(--text); box-shadow: var(--shadow-xs); outline: none; }
.tb-btn .ic { width: 16px; height: 16px; }

.btn-run, .btn-stop { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 18px; border-radius: 11px;
  font-weight: 600; font-size: 14px; border: 1px solid transparent; transition: all .15s; white-space: nowrap; }
.btn-run { background: linear-gradient(180deg, #F88A48 0%, #F37A33 55%, #E86B22 100%); color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 4px 12px -2px rgba(243,122,51,.55), 0 1px 2px rgba(0,0,0,.1); padding: 0 20px 0 16px; }
.btn-run:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 8px 18px -4px rgba(243,122,51,.6); }
.btn-run:active { transform: translateY(0); }
.btn-run .ic { width: 15px; height: 15px; }
.btn-run.running { background: linear-gradient(180deg, #4ADE80, #22C55E 60%, #16A34A); box-shadow: 0 4px 12px -2px rgba(34,197,94,.5); }
.btn-stop { background: #fff; color: var(--text-2); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-stop .ic { width: 13px; height: 13px; }
.btn-stop:not(:disabled) { color: var(--red); border-color: #F3C4C5; }
.btn-stop:not(:disabled):hover { background: #FFF5F5; }
.btn-stop:disabled { opacity: .5; cursor: default; }

/* Soft buttons used in panels */
.btn-soft { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--border-strong); background: #fff; border-radius: 8px; font-size: 12.5px; font-weight: 500;
  color: var(--text-2); box-shadow: var(--shadow-xs); transition: all .15s; white-space: nowrap; }
.btn-soft:hover { border-color: #C3C9D1; color: var(--text); background: var(--surface-2); }
.btn-soft:disabled { opacity: .45; pointer-events: none; }
.btn-soft.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-soft.accent:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn-soft.danger { color: var(--red); }
.btn-soft.wide { width: 100%; margin-top: 14px; }

/* ---------- Tooltips (data-tip) ---------- */
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 8px); transform: translate(-50%, -3px);
  background: #1F242B; color: #fff; font-size: 11.5px; font-weight: 500; padding: 5px 8px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .12s, transform .12s; z-index: 200; box-shadow: var(--shadow-md); }
[data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .35s; }
.rail [data-tip]::after { left: calc(100% + 10px); top: 50%; transform: translate(-3px, -50%); }
.rail [data-tip]:hover::after { transform: translate(0, -50%); }
.tb-right > [data-tip]:last-child::after, .rp-head [data-tip]::after { left: auto; right: 0; transform: translate(0, -3px); }
.tb-right > [data-tip]:last-child:hover::after, .rp-head [data-tip]:hover::after { transform: none; }

/* ---------- Rail ---------- */
.rail { width: var(--rail-w); flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 0;
  background: var(--surface); border-right: 1px solid var(--border); z-index: 25; }
.rail-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 56px; padding: 8px 0 6px; border: 0; background: transparent;
  border-radius: 12px; color: var(--muted); font-size: 10.5px; font-weight: 500; transition: background .15s, color .15s; position: relative; }
.rail-btn .ic { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--surface-3); color: var(--text); }
.rail-btn.active { background: var(--accent-50); color: var(--accent-600); }
.rail-btn.active::before { content: ""; position: absolute; left: -6px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.rail-spacer { flex: 1; }

/* ---------- Work area ---------- */
.work { flex: 1 1 auto; position: relative; min-width: 0; display: flex; flex-direction: column; }
.work-top { flex: 1 1 auto; position: relative; min-height: 0; }
#blocklyDiv { position: absolute; inset: 0; z-index: 0; }

/* ---------- Splitters ---------- */
.splitter { width: 9px; margin: 0 -4px; cursor: col-resize; z-index: 40; position: relative; flex: none; touch-action: none; outline: none; }
.splitter::before { content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 1px; background: transparent; transition: background .15s, width .15s, left .15s; }
.splitter::after { content: ""; position: absolute; top: 50%; left: 2px; width: 5px; height: 36px; margin-top: -18px; border-radius: 4px;
  background: var(--border-strong); opacity: 0; transition: opacity .15s; }
.splitter:hover::before, .splitter:focus-visible::before, .splitter.dragging::before { background: var(--accent); width: 3px; left: 3px; }
.splitter:hover::after, .splitter.dragging::after { opacity: 1; background: var(--accent); }
.splitter-left { position: absolute; top: 0; bottom: 0; left: calc(var(--side-w) - 4px); margin: 0; }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none !important; }
body.resizing iframe, body.resizing #blocklyDiv { pointer-events: none; }
body.resizing-v, body.resizing-v * { cursor: row-resize !important; user-select: none !important; }
body.resizing-v #blocklyDiv { pointer-events: none; }
.sb-btn { border: 0; background: transparent; font: inherit; color: inherit; padding: 2px 6px; border-radius: 6px; }
.sb-btn:hover { background: var(--surface-3); color: var(--text); }
.app.dock-open .sb-btn { color: var(--accent-600); }

/* ---------- Status bar ---------- */
.statusbar { display: flex; align-items: center; gap: 18px; padding: 0 14px; background: var(--surface); border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.sb-item { display: inline-flex; align-items: center; gap: 6px; }
.sb-grow { flex: 1; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.warn { background: #F5A524; }
.dot.idle { background: #C3C9D1; }
.dot.run { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.2); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(34,197,94,.05); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: calc(var(--status-h) + 14px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column;
  gap: 8px; z-index: 300; align-items: center; pointer-events: none; }
.toast { background: #1F242B; color: #fff; padding: 10px 14px 10px 12px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px; animation: toastIn .2s ease-out; pointer-events: auto; max-width: 520px; }
.toast i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.toast.error i { background: var(--red); }
.toast.info i { background: var(--accent); }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 26, 34, .35); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 400; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(420px, 92vw); background: #fff; border-radius: 14px; padding: 20px; box-shadow: var(--shadow-lg); animation: toastIn .18s; }
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal p { margin: 0 0 14px; color: var(--text-2); font-size: 13.5px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; max-height: 55vh; overflow-y: auto; }   /* v12.2: multi-line notices (custom code, pins) */
.input, .select { width: 100%; height: 36px; border: 1px solid var(--border-strong); border-radius: 9px; padding: 0 11px; background: #fff; outline: none; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-100); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions .btn-soft { height: 34px; padding: 0 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1500px) {
  .tb-btn span { display: none; }
  .tb-btn { padding: 0 8px; }
  #projectName { width: 140px; }
}
@media (max-width: 1100px) {
  .save-pill span { display: none; }
  .tb-center .btn-group:first-child { display: none; }
  :root { --rail-w: 60px; }
}
@media (max-width: 1024px) {
  :root {
    --side-w: 190px;
    --right-w: 320px;
  }
  .tb-btn.tb-text-hide span { display: none; }
  .project { padding: 3px 6px; }
  #projectName { width: 110px; font-size: 13px; }
}
@media (max-width: 768px) {
  :root {
    --rail-w: 52px;
    --side-w: 170px;
  }
  .rail-btn span { display: none; }
  .rail-btn { width: 44px; padding: 6px 0; }
  .tb-left .logo svg { width: 28px; height: 28px; }
  .tb-left #logoText { display: none; }
  .tb-left .product-name { margin-left: 4px; }
  .tb-btn { padding: 0 6px; }
  .zoom-label { min-width: 36px; }
  .btn-run { padding: 0 12px; font-size: 13px; }
}

/* v11: hint shown over an empty workspace */
.ws-empty-hint { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 2; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 12px; padding: 16px 20px; box-shadow: var(--shadow-md);
  color: var(--text-2); font-size: 13px; max-width: 320px; }
.ws-empty-hint[hidden] { display: none; }
.ws-empty-hint p { margin: 0 0 10px; line-height: 1.45; }

/* v11: error-boundary toast (js/core/error-boundary.js) */
.err-toast { align-items: flex-start; max-width: 560px; border-left: 3px solid var(--red); }
.err-toast i { margin-top: 5px; }
.err-toast .et-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.err-toast .et-msg { font: 12px var(--mono); color: #FECACA; overflow-wrap: anywhere; }
.err-toast .et-safe { font-size: 12px; color: #CBD5E1; }
.err-toast .et-actions { display: flex; gap: 8px; margin-top: 4px; }
.err-toast button { font: 600 12px var(--font); border-radius: 7px; padding: 4px 10px; cursor: pointer; border: 1px solid #475569; background: #334155; color: #fff; }
.err-toast button:hover { background: #475569; }
.err-toast .et-x { padding: 4px 8px; background: transparent; }
.board-btn, .board-btn span { white-space: nowrap; }
.board-btn { flex: none; }
.tb-left { overflow: hidden; }
@media (max-width: 1360px) { #projectName { width: 110px; } .save-pill > span { display: none; } }
