/* Circuit Studio (/circuit-simulator). It wears Video Studio's frame and
   panels (video-studio.css), as CAD Studio does: menus and Export along the
   top, then the view picker, Run and the tools, then the parts library, the
   view with the dock (code, serial monitor, scope) under it, and the
   settings. On a phone the side panels become sheets opened from tabs. */

/* ---- Start screen ---- */
.cs-new .st-new-row > .st-field { flex: 0 1 auto; }

/* ---- The frame ---- */
.cs-work { grid-template-rows: auto auto minmax(0, 1fr); }
.cs-body { grid-template-columns: 264px minmax(0, 1fr) 290px; }
.cs-main { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.cs-menu { max-height: 72vh; overflow-y: auto; scrollbar-width: thin; }
.cs-menu-head { margin: 6px 10px 2px; color: var(--accent-strong); font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; }

/* ---- The tool bar ---- */
.cs-bar { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 4px 8px; background: var(--surface); border-bottom: 1px solid var(--border); }
.cs-bar > * { flex: none; }
.cs-bar .seg { flex-wrap: nowrap; gap: 4px; margin: 0; }
.cs-run { display: inline-flex; align-items: center; gap: 5px; min-width: 76px; justify-content: center; }
.cs-run.is-on { color: #14111f; background: #ffb86b; border-color: #ffb86b; }
.cs-time { min-width: 64px; color: #7ee2b8; font: 0.76rem var(--mono); font-variant-numeric: tabular-nums; }
.cs-time.is-slow { color: #ffb86b; }
.cs-speed { width: auto; min-width: 104px; }
.cs-gap { width: 1px; height: 22px; margin: 0 4px; background: var(--border); }
.cs-pcb-btns { display: flex; align-items: center; gap: 6px; }
.cs-pcb-btns[hidden] { display: none; }
.cs-width { width: auto; }
.cs-bar-end { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.cs-route { display: inline-flex; align-items: center; gap: 5px; }
.cs-route:disabled { opacity: 0.55; }
.cs-bar .vs-ib:disabled { opacity: 0.4; cursor: default; }

/* ---- The view ---- */
.cs-view { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #24203a; }
.cs-svg { display: block; width: 100%; height: 100%; touch-action: none; outline: none; user-select: none; -webkit-user-select: none; }
.cs-svg:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.cs-grid-dot { fill: rgba(255, 255, 255, 0.07); }
.cs-svg[data-view="bb"] .cs-grid-dot { fill: rgba(255, 255, 255, 0.05); }
.cs-svg text { pointer-events: none; }
.cs-tip { position: absolute; z-index: 5; max-width: 340px; padding: 4px 8px; color: var(--text); background: rgba(14, 12, 22, 0.92); border: 1px solid var(--border); font: 0.72rem/1.4 var(--mono); white-space: pre-wrap; pointer-events: none; }
.cs-msg { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 6; margin: 0; pointer-events: none; }
.cs-msg:not(:empty) { width: fit-content; max-width: calc(100% - 20px); padding: 6px 10px; color: var(--text); background: rgba(20, 17, 31, 0.9); border: 1px solid var(--border); border-radius: 0; }
.cs-msg[data-kind="warn"] { border-color: #e8b44f; }
.cs-msg[data-kind="ok"] { border-color: #2ec4b6; }
.cs-app.is-running .cs-view { box-shadow: inset 0 0 0 2px rgba(255, 184, 107, 0.55); }

/* ---- The dock ---- */
.cs-dock { display: grid; grid-template-rows: auto; min-width: 0; background: var(--surface); border-top: 1px solid var(--border); }
.cs-dock.is-open { grid-template-rows: auto 236px; }
.cs-dock-head { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 0 6px; }
.cs-dock-tabs { display: flex; flex: none; }
.cs-dock-tab { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; font: inherit; font-size: 0.76rem; cursor: pointer; }
.cs-dock-tab:hover { color: var(--text); }
.cs-dock-tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.cs-dock-tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cs-dock-status { flex: 1 1 auto; min-width: 0; overflow: hidden; color: var(--muted); font: 0.72rem var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.cs-dock-status[data-kind="err"] { color: #ff9a9a; }
.cs-dock-status[data-kind="ok"] { color: #7ee2b8; }
.cs-dock-toggle { flex: none; transition: transform 160ms ease; }
.cs-dock.is-open .cs-dock-toggle { transform: rotate(180deg); }
.cs-pane { min-height: 0; border-top: 1px solid var(--border); }
.cs-pane[hidden] { display: none; }

.cs-code-pane { display: grid; min-height: 0; }
.cs-code-wrap { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; background: #12101c; }
.cs-gutter { min-width: 38px; padding: 8px 6px 8px 8px; overflow: hidden; color: rgba(255, 255, 255, 0.28); font: 0.78rem/1.55 var(--mono); text-align: right; user-select: none; }
.cs-gutter span { display: block; }
.cs-gutter span.is-err { color: #14111f; background: #ff7a7a; }
.cs-code { display: block; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 8px 10px; color: #e8e4f8; background: transparent; border: 0; border-radius: 0; outline: none; resize: none; font: 0.78rem/1.55 var(--mono); tab-size: 2; white-space: pre; overflow: auto; }
.cs-code:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }

.cs-serial-pane { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.cs-serial-out { min-height: 0; margin: 0; padding: 8px 10px; overflow: auto; color: #c9f5d9; background: #0b0a12; font: 0.76rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.cs-serial-bar { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-top: 1px solid var(--border); }
.cs-serial-in { flex: 1 1 auto; min-width: 0; padding: 4px 8px; border-radius: 0; font: 0.78rem var(--mono); }
.cs-serial-end { width: auto; flex: none; }
.cs-auto { flex: none; font-size: 0.74rem; }

.cs-scope-pane { display: grid; grid-template-columns: minmax(0, 1fr) 220px; }
.cs-scope-main { position: relative; min-width: 0; min-height: 0; }
.cs-scope-canvas { display: block; width: 100%; height: 100%; }
.cs-scope-side { display: flex; flex-direction: column; gap: 6px; min-height: 0; padding: 6px 8px; overflow-y: auto; border-left: 1px solid var(--border); }
.cs-scope-add { display: flex; gap: 4px; }
.cs-scope-add .vs-select { flex: 1 1 auto; min-width: 0; }
.cs-chan { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 20px; align-items: center; gap: 6px; font-size: 0.74rem; }
.cs-chan-dot { width: 10px; height: 10px; border-radius: 50%; }
.cs-chan-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-chan-v { font: 0.7rem var(--mono); color: var(--muted); }
.cs-chan-x { display: grid; place-items: center; width: 20px; height: 20px; padding: 0; color: var(--muted); background: none; border: 0; cursor: pointer; }
.cs-chan-x:hover { color: var(--text); }

/* ---- The library ---- */
.cs-app .vs-lib { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.cs-lib-head { padding: 8px 10px 0; }
.cs-lib-tabs { display: flex; }
.cs-lib-tabs .seg-btn { flex: 1 1 0; }
.cs-lib-body { min-height: 0; padding: 8px 10px 16px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.cs-search { width: 100%; margin-bottom: 6px; padding: 5px 9px; border-radius: 0; font-size: 0.8rem; }
.cs-cats .vs-sec { margin-bottom: 2px; }
.cs-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.cs-tile { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; padding: 7px 2px 5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 0; font: inherit; font-size: 0.64rem; line-height: 1.2; text-align: center; cursor: grab; transition: border-color 140ms ease, color 140ms ease; }
.cs-tile:hover { color: var(--text); border-color: var(--accent); }
.cs-tile:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cs-tile-icon { display: grid; place-items: center; color: var(--text); }
.cs-tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.cs-calc-row .vs-numwrap { flex: 0 1 150px; }
.cs-calc-in { width: 100%; min-width: 0; padding: 4px 8px; border-radius: 0; font: 0.8rem var(--mono); }
.cs-calc-out { margin: 4px 0 8px; padding: 6px 8px; color: var(--text); background: var(--surface-2); border-left: 2px solid var(--accent); font-size: 0.76rem; line-height: 1.45; }
.cs-bands { display: flex; justify-content: center; margin: 6px 0 2px; }
.cs-band-body { display: flex; gap: 7px; padding: 4px 18px; background: #d9c49a; border-radius: 12px; }
.cs-band { width: 9px; height: 26px; border: 1px solid rgba(0, 0, 0, 0.25); }

/* ---- Settings ---- */
.cs-insp-head { display: flex; align-items: flex-start; gap: 10px; margin: 2px 0 10px; }
.cs-insp-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }
.cs-insp-title { display: grid; gap: 4px; flex: 1 1 auto; min-width: 0; }
.cs-insp-title b { font-size: 0.86rem; }
.cs-insp-sub { color: var(--muted); font-size: 0.74rem; }
.cs-ref-field .input { width: 90px; }
.cs-ref, .cs-value, .cs-text { min-width: 0; padding: 4px 8px; border-radius: 0; font: 0.8rem var(--mono); }
.cs-value { width: 100px; }
.cs-text { width: 140px; }
.cs-value-warn { display: block; color: #ff9a9a; font-size: 0.7rem; }
.cs-value-warn:empty { display: none; }
.cs-range-out { min-width: 44px; font: 0.74rem var(--mono); text-align: right; }
.cs-insp-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.cs-insp-btns .btn { display: inline-flex; align-items: center; gap: 5px; }
.cs-reads { display: grid; gap: 3px; }
.cs-read { display: flex; justify-content: space-between; gap: 10px; font-size: 0.78rem; }
.cs-read span { color: var(--muted); }
.cs-read b { font: 600 0.78rem var(--mono); font-variant-numeric: tabular-nums; }
.cs-pins { display: grid; gap: 2px; }
.cs-pin { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) 22px; align-items: center; gap: 6px; font-size: 0.74rem; }
.cs-pin-name { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.cs-pin-net { overflow: hidden; font: 0.7rem var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.cs-pin.is-open .cs-pin-net { color: #ffb86b; }
.cs-pin-scope { display: grid; place-items: center; width: 22px; height: 20px; padding: 0; color: var(--muted); background: none; border: 0; cursor: pointer; }
.cs-pin-scope:hover { color: var(--text); }
.cs-swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.cs-swatch { height: 24px; padding: 0; border: 1px solid rgba(0, 0, 0, 0.5); border-radius: 0; cursor: pointer; }
.cs-swatch.is-on { box-shadow: 0 0 0 2px var(--accent); }
.cs-swatch:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cs-app .vs-insp-hint.is-error { color: #ff9a9a; }
.cs-app .vs-insp-hint.is-warn { color: #ffb86b; }
.cs-app .vs-insp-hint.is-ok { color: #7ee2b8; }

/* ---- Dialogs ---- */
.cs-dlg { display: grid; gap: 10px; min-width: min(400px, 80vw); }
.cs-dlg .vs-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cs-dlg .vs-field > .input, .cs-dlg .vs-field > .vs-select { flex: 1 1 auto; min-width: 0; max-width: 300px; }
.cs-dlg-opts { display: grid; gap: 10px; }

/* ---- Phones ---- */
@media (max-width: 760px) {
  .cs-new .st-new-row > .st-field { flex: 1 1 100%; }
  .cs-new .seg { flex-wrap: wrap; }
  .cs-work { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .cs-body { grid-template-columns: minmax(0, 1fr); }
  .cs-main { height: 100%; }
  .cs-bar { gap: 4px; padding: 3px 6px; overflow-x: auto; scrollbar-width: none; }
  .cs-bar::-webkit-scrollbar { display: none; }
  .cs-bar .vs-ib { width: 36px; height: 36px; }
  .cs-bar .seg-btn, .cs-run { padding: 5px 9px; font-size: 0.8rem; }
  .cs-run { min-width: 0; }
  .cs-speed, .cs-gap, .cs-route span { display: none; }
  .cs-dock.is-open { grid-template-rows: auto 42vh; }
  .cs-dock-tab span { display: none; }
  .cs-scope-pane { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .cs-scope-side { max-height: 120px; border-left: 0; border-top: 1px solid var(--border); }
  .cs-msg { top: 6px; bottom: auto; }
}
