/* Pocketlab workspace. Root rules are scoped to .uwapp-root.uwapp-pocketlab (the body carries the app class too).
   Light and dark tokens follow html[data-theme] / prefers-color-scheme. No inline styles (CSP): geometry via CSSOM. */
.uwapp-root.uwapp-pocketlab {
  --pl-bg: #eef4f4; --pl-surface: #ffffff; --pl-surface-2: #e2ecec; --pl-ink: #13292a; --pl-muted: #475a5b; --pl-line: #c3d3d3;
  --pl-control: #657a7b; --pl-accent: #0f6b6f; --pl-accent-ink: #0b5558; --pl-on-accent: #ffffff; --pl-warn: #9b2b17; --pl-warn-bg: #fde6df;
  --pl-focus: #b4530f; --pl-good: #1f7a3a; --pl-bubble: #3aa55d; --pl-needle: #0f6b6f; --pl-north: #b42318; --pl-true: #b4530f; --pl-sun: #d97706; --pl-moon: #64748b;
  background: var(--pl-bg); color: var(--pl-ink); color-scheme: light;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
:root[data-theme="dark"] .uwapp-root.uwapp-pocketlab {
  --pl-bg: #0f1717; --pl-surface: #172222; --pl-surface-2: #213030; --pl-ink: #e5f0f0; --pl-muted: #b0c2c2; --pl-line: #314444;
  --pl-control: #87a0a0; --pl-accent: #6fd0d4; --pl-accent-ink: #9fe3e6; --pl-on-accent: #062a2c; --pl-warn: #ffb4a3; --pl-warn-bg: #4a1f17;
  --pl-focus: #fbbf24; --pl-good: #8fe0a7; --pl-bubble: #5ccf80; --pl-needle: #6fd0d4; --pl-north: #ff8a7a; --pl-true: #fbbf24; --pl-sun: #fbbf24; --pl-moon: #cbd5e1;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uwapp-root.uwapp-pocketlab {
    --pl-bg: #0f1717; --pl-surface: #172222; --pl-surface-2: #213030; --pl-ink: #e5f0f0; --pl-muted: #b0c2c2; --pl-line: #314444;
    --pl-control: #87a0a0; --pl-accent: #6fd0d4; --pl-accent-ink: #9fe3e6; --pl-on-accent: #062a2c; --pl-warn: #ffb4a3; --pl-warn-bg: #4a1f17;
    --pl-focus: #fbbf24; --pl-good: #8fe0a7; --pl-bubble: #5ccf80; --pl-needle: #6fd0d4; --pl-north: #ff8a7a; --pl-true: #fbbf24; --pl-sun: #fbbf24; --pl-moon: #cbd5e1;
    color-scheme: dark;
  }
}

/* Platform element defaults leak into app workspaces: reset them at zero specificity. */
:where(.pl-app, .pl-dlg) button { font: inherit; font-size: .9rem; font-weight: 600; padding: 0; border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer; width: auto; min-height: 0; margin: 0; }
:where(.pl-app, .pl-dlg) button:hover { background: none; }
:where(.pl-app, .pl-dlg) :is(input, select, textarea) { font: inherit; font-size: .92rem; color: var(--pl-ink); background: var(--pl-surface); border: 1px solid var(--pl-control); border-radius: 8px; padding: .35rem .5rem; min-height: 36px; width: 100%; max-width: 100%; box-sizing: border-box; margin: 0; }
:where(.pl-app, .pl-dlg) input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--pl-accent); }
:where(.pl-app, .pl-dlg) input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--pl-accent); }
:where(.pl-app, .pl-dlg) table { border-collapse: collapse; width: 100%; margin: 0; font-size: .86rem; }
:where(.pl-app, .pl-dlg) :is(th, td) { text-align: start; padding: 4px 8px; border-bottom: 1px solid var(--pl-line); vertical-align: top; color: var(--pl-ink); white-space: nowrap; }
:where(.pl-app, .pl-dlg) thead th { background: var(--pl-surface-2); color: var(--pl-ink); }
:where(.pl-app, .pl-dlg) caption { text-align: start; font-weight: 700; padding: 0 0 .3rem; color: var(--pl-ink); }
:where(.pl-app, .pl-dlg) a { color: var(--pl-accent-ink); }
:where(.pl-app, .pl-dlg) :is(h1, h2, h3) { color: var(--pl-ink); margin: 0 0 .4rem; line-height: 1.25; }
:where(.pl-app, .pl-dlg) p { margin: .3rem 0; }
:where(.pl-app, .pl-dlg) code, :where(.pl-app, .pl-dlg) kbd { color: var(--pl-ink); background: var(--pl-surface-2); }

.pl-app { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; background: var(--pl-bg); color: var(--pl-ink); position: relative; }
.pl-app :focus-visible, .pl-dlg :focus-visible { outline: 3px solid var(--pl-focus); outline-offset: 2px; }
.pl-hint, .pl-muted { color: var(--pl-muted); font-size: .86rem; overflow-wrap: anywhere; }
.pl-warn { color: var(--pl-warn); background: var(--pl-warn-bg); border-radius: 8px; padding: .45rem .6rem; font-size: .88rem; margin: 0 0 .6rem; }
.pl-status:empty, .pl-appstatus:empty { display: none; }
.pl-status { margin: .4rem 0; font-size: .9rem; color: var(--pl-ink); }
.pl-status.bad, .pl-appstatus.bad { color: var(--pl-warn); font-weight: 600; }

/* ---------- top bar */
.pl-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 10px; background: var(--pl-surface); border-bottom: 1px solid var(--pl-line); }
.pl-bar-start, .pl-bar-end { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.pl-name { font-weight: 700; padding-inline: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.pl-appstatus { margin: 0; padding: 6px 12px; background: var(--pl-surface); border-top: 1px solid var(--pl-line); font-size: .88rem; }

/* ---------- buttons */
.pl-btn { display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding: .35rem .8rem; border: 1px solid var(--pl-control); border-radius: 8px; background: var(--pl-surface); color: var(--pl-ink); }
.pl-btn:hover:not([disabled]) { background: var(--pl-surface-2); }
.pl-btn[disabled], .pl-icon-btn[disabled] { opacity: .55; cursor: not-allowed; }
.pl-btn[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--pl-accent); background: var(--pl-surface-2); }
.pl-btn.primary, :is(.pl-app, .pl-dlg) button[type=submit].pl-btn.primary { background: var(--pl-accent); border-color: var(--pl-accent); color: var(--pl-on-accent); }
.pl-btn.primary:hover:not([disabled]), :is(.pl-app, .pl-dlg) button[type=submit].pl-btn.primary:hover:not([disabled]) { background: var(--pl-accent-ink); border-color: var(--pl-accent-ink); color: var(--pl-on-accent); }
.pl-btn.pl-small { min-height: 32px; padding: .15rem .55rem; font-size: .82rem; }
.pl-btn[hidden], .pl-icon-btn[hidden] { display: none; }
.pl-icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: 8px; color: var(--pl-ink); flex: none; }
.pl-icon-btn:hover:not([disabled]) { background: var(--pl-surface-2); border-color: var(--pl-line); }
.pl-link-btn { color: var(--pl-accent-ink); text-decoration: underline; text-align: start; font-weight: 700; }
.pl-menu-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 .6rem; border-radius: 8px; color: var(--pl-ink); }
.pl-menu-btn:hover, .pl-menu-btn[aria-expanded="true"] { background: var(--pl-surface-2); }
.pl-menu { position: fixed; z-index: 60; min-width: 220px; max-height: min(80vh, 640px); overflow: auto; padding: 4px; background: var(--pl-surface); border: 1px solid var(--pl-line); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / 20%); }
.pl-menu[hidden] { display: none; }
.pl-menu-item { display: flex; width: 100%; justify-content: space-between; gap: 16px; padding: 8px 10px; border-radius: 6px; color: var(--pl-ink); text-align: start; font-weight: 500; }
.pl-menu-item:hover, .pl-menu-item:focus { background: var(--pl-surface-2); }
.pl-menu-item[aria-disabled="true"] { opacity: .55; }
.pl-menu-key { color: var(--pl-muted); font-size: .8rem; }
.pl-menu-sep { height: 1px; margin: 4px 6px; background: var(--pl-line); }

/* ---------- body: instrument list | instrument | notebook */
.pl-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 200px minmax(0, 1fr) 320px; overflow: hidden; }
.pl-nav, .pl-main, .pl-book { overflow: auto; min-width: 0; min-height: 0; position: relative; }
.pl-nav { background: var(--pl-surface); border-inline-end: 1px solid var(--pl-line); padding: 8px; }
.pl-navgroup ul { list-style: none; margin: 0 0 8px; padding: 0; }
.pl-navlabel { margin: 6px 6px 2px; font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--pl-muted); }
.pl-navbtn { display: block; width: 100%; text-align: start; padding: 8px 10px; border-radius: 8px; color: var(--pl-ink); font-weight: 600; min-height: 40px; }
.pl-navbtn:hover { background: var(--pl-surface-2); }
.pl-navbtn[aria-current="page"] { background: var(--pl-accent); color: var(--pl-on-accent); }
.pl-main { padding: 12px 16px 24px; }
.pl-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pl-insttitle { font-size: 1.35rem; margin: 0; }
.pl-book { background: var(--pl-surface); border-inline-start: 1px solid var(--pl-line); padding: 12px; }
.pl-booktitle { display: flex; align-items: center; gap: 6px; font-size: 1.1rem; }
.pl-logs { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.pl-log { border: 1px solid var(--pl-line); border-radius: 10px; padding: 8px 10px; background: var(--pl-bg); min-width: 0; }
.pl-logtitle { font-size: .98rem; margin: 0; }
.pl-logactions { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 4px; }
.pl-log .pl-kv { grid-template-columns: minmax(0, auto) minmax(0, 1fr); font-size: .82rem; }

/* ---------- instrument panes */
.pl-pane { display: grid; gap: 10px; min-width: 0; grid-template-columns: minmax(0, 1fr); }
.pl-pane > * { min-width: 0; }
.pl-sub { font-size: 1.02rem; margin: 10px 0 0; }
.pl-readout { display: grid; gap: 2px; justify-items: center; text-align: center; min-width: 0; padding: 6px 0; }
.pl-big { margin: 0; font: 700 clamp(34px, 9vw, 56px)/1.1 ui-monospace, Menlo, Consolas, monospace; color: var(--pl-ink); overflow-wrap: anywhere; }
.pl-unit { font-size: .42em; font-weight: 600; color: var(--pl-muted); }
.pl-biglabel { margin: 0; color: var(--pl-muted); font-size: .9rem; }
.pl-watch { font-size: clamp(44px, 14vw, 88px); }
.pl-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pl-actions select { width: auto; }
.pl-settings, .pl-form { display: grid; gap: 8px 12px; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); align-items: start; }
.pl-field { display: grid; gap: 3px; min-width: 0; }
.pl-field label { font-weight: 600; font-size: .86rem; }
.pl-field .pl-hint { margin: 0; font-size: .8rem; }
.pl-check { display: flex; align-items: center; gap: 8px; }
.pl-kv { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 3px 14px; margin: 0; }
.pl-kv dt { color: var(--pl-muted); }
.pl-kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pl-kv dd.pl-strong { font-weight: 700; }
.pl-out { min-width: 0; display: grid; gap: 8px; }
.pl-chart { min-width: 0; }
.pl-chart-svg { width: 100%; height: auto; display: block; border-radius: 8px; background: #ffffff; direction: ltr; }
.pl-tablewrap { overflow: auto; max-width: 100%; max-height: 420px; position: relative; border: 1px solid var(--pl-line); border-radius: 8px; }
.pl-gauge { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 16px; align-items: center; min-width: 0; }
.pl-dial { width: 100%; max-width: 260px; height: auto; display: block; direction: ltr; }
.pl-face { fill: var(--pl-surface); stroke: var(--pl-line); stroke-width: 2; }
.pl-mark { stroke: var(--pl-muted); stroke-width: 1.5; fill: none; }
.pl-mark2 { stroke: var(--pl-ink); stroke-width: 3; }
.pl-bubble { fill: var(--pl-bubble); fill-opacity: .8; stroke: var(--pl-ink); stroke-width: 1.5; }
.pl-plumbline { stroke: var(--pl-ink); stroke-width: 2; }
.pl-plumbbob { fill: var(--pl-true); stroke: var(--pl-ink); stroke-width: 1; }
.pl-label { fill: var(--pl-ink); font: 700 16px system-ui, sans-serif; }
.pl-north { fill: var(--pl-north); font: 700 18px system-ui, sans-serif; }
.pl-needle { fill: var(--pl-needle); }
.pl-true { fill: var(--pl-true); }
.pl-hdg { stroke: var(--pl-needle); stroke-width: 3; stroke-dasharray: 6 4; }
.pl-sun { fill: var(--pl-sun); stroke: var(--pl-ink); stroke-width: 1; }
.pl-moon { fill: var(--pl-moon); stroke: var(--pl-ink); stroke-width: 1; }
.pl-point { font-weight: 700; font-size: 1.05rem; min-height: 1.4em; }
.pl-rulerbox { overflow: hidden; min-width: 0; border: 1px solid var(--pl-line); border-radius: 6px; }
.pl-ruler { direction: ltr; }
.pl-rulersvg { display: block; max-width: none; }
.pl-rulerbg { fill: #fff8dc; }
.pl-tick { stroke: #1a1a1a; stroke-width: 1; }
.pl-ticklabel { fill: #1a1a1a; font: 600 12px system-ui, sans-serif; }
.pl-cardrow { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.pl-cardrow .pl-field { flex: 1 1 200px; }
.pl-cardrow .pl-btn { min-width: 44px; min-height: 44px; font-size: 20px; justify-content: center; }
.pl-cardwrap { overflow: auto; min-width: 0; }
.pl-card { display: block; max-width: none; }
.pl-cardrect { fill: none; stroke: var(--pl-accent); stroke-width: 2; stroke-dasharray: 6 4; }
.pl-preview:empty { display: none; }
.pl-video { width: min(320px, 100%); border-radius: 8px; background: #000; }

/* ---------- dialogs */
.pl-dlg { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--pl-line); border-radius: 12px; background: var(--pl-surface); color: var(--pl-ink); box-shadow: 0 20px 60px rgb(0 0 0 / 35%); }
.pl-dlg-wide { width: min(900px, calc(100vw - 24px)); }
.pl-dlg::backdrop { background: rgb(0 0 0 / 45%); }
.pl-dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--pl-line); position: sticky; top: 0; background: var(--pl-surface); z-index: 1; }
.pl-dlg-head h2 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.pl-dlg-lede { padding: 8px 14px 0; color: var(--pl-muted); }
.pl-dlg-body { padding: 12px 14px 16px; display: grid; gap: 10px; min-width: 0; }
.pl-dlg-body > * { min-width: 0; }
.pl-dlg-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pl-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.pl-card { display: grid; gap: 4px; width: 100%; text-align: start; padding: 10px 12px; border: 1px solid var(--pl-line); border-radius: 10px; background: var(--pl-bg); color: var(--pl-ink); }
.pl-card span { font-weight: 400; color: var(--pl-muted); font-size: .86rem; }
.pl-card:hover { border-color: var(--pl-accent); }
.pl-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.pl-list-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pl-wide { width: 100%; }

/* ---------- phones and narrow windows */
@media (max-width: 1100px) {
  .pl-body { grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto; overflow: auto; }
  .pl-book { grid-column: 1 / -1; border-inline-start: 0; border-top: 1px solid var(--pl-line); overflow: visible; }
  .pl-main, .pl-nav { overflow: visible; }
}
@media (max-width: 760px) {
  .pl-body { display: flex; flex-direction: column; overflow: auto; }
  .pl-main, .pl-book { flex: none; }
  .pl-nav { display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; border-inline-end: 0; border-bottom: 1px solid var(--pl-line); padding: 6px; flex: none; }
  .pl-navgroup { display: flex; align-items: center; gap: 2px; flex: none; }
  .pl-navgroup ul { display: flex; gap: 2px; margin: 0; }
  .pl-navlabel { display: none; }
  .pl-navbtn { white-space: nowrap; width: auto; }
  .pl-main { padding: 10px; }
  .pl-gauge { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .pl-dial { max-width: 220px; }
  .pl-name { max-width: 30vw; }
}
@media (prefers-reduced-motion: reduce) { .pl-app *, .pl-dlg * { transition: none !important; animation: none !important; } }
@media print {
  .pl-bar, .pl-nav, .pl-main, .pl-appstatus, .pl-logactions { display: none !important; }
  .pl-body { display: block; overflow: visible; }
  .pl-book { border: 0; overflow: visible; }
}
