/* Sketchboard workspace. Root rules are scoped to .uwapp-root.uwapp-sketchboard (the body carries the app class too).
   Light and dark tokens follow html[data-theme] / prefers-color-scheme. The board paper keeps its own colour. */
.uwapp-root.uwapp-sketchboard {
  --sb-bg: #eef1f6; --sb-surface: #ffffff; --sb-surface-2: #eef1f7; --sb-ink: #172033; --sb-muted: #4b5568; --sb-line: #d3d9e3; --sb-control: #6f7a8f;
  --sb-accent: #0f6b5c; --sb-accent-ink: #0b5a4d; --sb-on-accent: #ffffff; --sb-sel: #2563eb; --sb-focus: #b45309; --sb-danger: #a3271b; --sb-tile-fill: #ffffff;
  background: var(--sb-bg); color: var(--sb-ink); color-scheme: light;
  display: flex; flex-direction: column; min-height: 0;
}
:root[data-theme="dark"] .uwapp-root.uwapp-sketchboard {
  --sb-bg: #11151d; --sb-surface: #1b212c; --sb-surface-2: #262e3b; --sb-ink: #eef1f6; --sb-muted: #b7c0cf; --sb-line: #364152; --sb-control: #8d99ad;
  --sb-accent: #5fd0bb; --sb-accent-ink: #8fe3d3; --sb-on-accent: #062a24; --sb-sel: #7fb0ff; --sb-focus: #fbbf24; --sb-danger: #ffb3a8; --sb-tile-fill: #262e3b;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uwapp-root.uwapp-sketchboard {
    --sb-bg: #11151d; --sb-surface: #1b212c; --sb-surface-2: #262e3b; --sb-ink: #eef1f6; --sb-muted: #b7c0cf; --sb-line: #364152; --sb-control: #8d99ad;
    --sb-accent: #5fd0bb; --sb-accent-ink: #8fe3d3; --sb-on-accent: #062a24; --sb-sel: #7fb0ff; --sb-focus: #fbbf24; --sb-danger: #ffb3a8; --sb-tile-fill: #262e3b;
    color-scheme: dark;
  }
}
.uwapp-root.uwapp-sketchboard [hidden], .sb-dialog [hidden] { display: none !important; }

/* Platform element defaults leak into app workspaces: reset them at zero specificity. */
:where(.sb-app, .sb-dialog) 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(.sb-app, .sb-dialog) button:hover { background: none; }
:where(.sb-app, .sb-dialog) :is(input, select, textarea) { font: inherit; font-size: .9rem; color: var(--sb-ink); background: var(--sb-surface); border: 1px solid var(--sb-control); border-radius: 7px; width: auto; margin: 0; padding: 4px 6px; min-width: 0; }
:where(.sb-app, .sb-dialog) input[type="color"] { padding: 1px; width: 44px; height: 30px; }
:where(.sb-app, .sb-dialog) input[type="checkbox"], :where(.sb-app, .sb-dialog) input[type="radio"] { width: auto; accent-color: var(--sb-accent); }
:where(.sb-app, .sb-dialog) table { border-collapse: collapse; width: 100%; margin: 0; font-size: .88rem; }
:where(.sb-app, .sb-dialog) :is(th, td) { text-align: start; padding: 5px 8px; border-bottom: 1px solid var(--sb-line); vertical-align: top; }
:where(.sb-app, .sb-dialog) thead th { background: var(--sb-surface-2); color: var(--sb-ink); }
:where(.sb-app, .sb-dialog) kbd { font-family: ui-monospace, Consolas, monospace; font-size: .85em; padding: 1px 6px; border: 1px solid var(--sb-control); border-bottom-width: 2px; border-radius: 5px; background: var(--sb-surface-2); color: var(--sb-ink); white-space: nowrap; }
:where(.sb-app, .sb-dialog) :is(code, pre) { background: var(--sb-surface-2); color: var(--sb-ink); }
:where(.sb-app, .sb-dialog) h2, :where(.sb-app, .sb-dialog) h3, :where(.sb-app, .sb-dialog) h4 { color: var(--sb-ink); margin: 0; }
:where(.sb-app, .sb-dialog) p { margin: .3rem 0; }
:where(.sb-app, .sb-dialog) ul { margin: 0; padding: 0; }

.sb-app { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; height: 100%; background: var(--sb-bg); color: var(--sb-ink); }
.sb-app :focus-visible, .sb-dialog :focus-visible { outline: 3px solid var(--sb-focus); outline-offset: 2px; }
.sb-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.sb-grow { flex: 1; min-width: 0; }
.sb-hint { color: var(--sb-muted); font-size: .82rem; }
.sb-error { color: var(--sb-danger); font-weight: 600; min-height: 1em; }
.sb-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: .4rem 0; }

/* top bar */
.sb-topbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 4px 8px; background: var(--sb-surface); border-bottom: 1px solid var(--sb-line); min-width: 0; }
.sb-menu-btn { display: inline-flex; align-items: center; gap: 2px; padding: 6px 8px; border-radius: 7px; }
.sb-menu-btn:hover, .sb-icon-btn:hover, .sb-name:hover, .sb-zoom:hover { background: var(--sb-surface-2); }
.sb-icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; min-height: 34px; border-radius: 7px; color: var(--sb-ink); }
.sb-icon-btn:disabled { opacity: .45; cursor: default; }
.sb-sep { width: 1px; align-self: stretch; background: var(--sb-line); margin: 4px 6px; }
.sb-name { padding: 6px 8px; max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.sb-zoom { padding: 6px 8px; font-variant-numeric: tabular-nums; min-width: 6ch; }
.sb-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--sb-control); border-radius: 8px; background: var(--sb-surface); color: var(--sb-ink); }
.sb-btn:hover { background: var(--sb-surface-2); }
.sb-btn:disabled { opacity: .5; cursor: default; }
.sb-btn.sb-btn-primary, .sb-dialog button[type=submit].sb-btn-primary { background: var(--sb-accent); border-color: var(--sb-accent); color: var(--sb-on-accent); }
.sb-btn.sb-btn-primary:hover { filter: brightness(1.08); background: var(--sb-accent); }
.sb-btn.sb-btn-danger { color: var(--sb-danger); border-color: var(--sb-danger); }
.sb-present-btn { margin-inline-start: 4px; }
.sb-panel-toggle, .sb-lib-toggle { display: none; }
.sb-menu-wrap { position: relative; }
.sb-menu { position: fixed; z-index: 60; min-width: 230px; max-height: min(80vh, 640px); overflow: auto; padding: 4px; background: var(--sb-surface); color: var(--sb-ink); border: 1px solid var(--sb-line); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / .2); }
.sb-menu-item { display: flex; justify-content: space-between; gap: 18px; width: 100%; padding: 7px 10px; border-radius: 6px; text-align: start; font-weight: 500; }
.sb-menu-item:hover, .sb-menu-item:focus-visible { background: var(--sb-surface-2); }
.sb-menu-item[aria-disabled="true"] { opacity: .5; cursor: default; }
.sb-menu-key { color: var(--sb-muted); font-size: .8rem; font-weight: 500; }
.sb-menu-sep { height: 1px; background: var(--sb-line); margin: 4px 2px; }
.sb-snapbar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 6px 10px; background: #fef3c7; color: #3d2b00; border-bottom: 1px solid #e6c661; }
.sb-ws-chip { display: inline-flex; align-items: center; }

/* main area */
.sb-main { position: relative; display: flex; flex: 1; min-height: 0; min-width: 0; }
.sb-tools { display: flex; flex-direction: column; gap: 2px; padding: 6px 4px; background: var(--sb-surface); border-inline-end: 1px solid var(--sb-line); overflow-y: auto; }
.sb-tool { display: flex; align-items: center; justify-content: center; width: 38px; height: 36px; border-radius: 8px; color: var(--sb-ink); }
.sb-tool:hover { background: var(--sb-surface-2); }
.sb-tool[aria-pressed="true"] { background: var(--sb-accent); color: var(--sb-on-accent); }
.sb-lib { width: 236px; flex: none; overflow-y: auto; background: var(--sb-surface); border-inline-end: 1px solid var(--sb-line); padding: 6px; }
.sb-lib-tabs { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 6px; }
.sb-lib-tab, .sb-chip { padding: 4px 8px; border-radius: 999px; border: 1px solid var(--sb-line); font-size: .78rem; font-weight: 600; color: var(--sb-ink); }
.sb-lib-tab[aria-selected="true"], .sb-chip[aria-selected="true"] { background: var(--sb-accent); border-color: var(--sb-accent); color: var(--sb-on-accent); }
.sb-shape-grid, .sb-prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 4px; }
.sb-prop-grid { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); }
.sb-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; padding: 4px; border: 1px solid var(--sb-line); border-radius: 8px; background: var(--sb-surface); color: var(--sb-ink); }
.sb-tile:hover { border-color: var(--sb-accent); }
.sb-prop-tile svg { background: #ffffff; border-radius: 6px; }
.sb-prop-name { font-size: .68rem; font-weight: 500; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-props input[type="search"] { width: 100%; margin-bottom: 6px; }
.sb-prop-themes { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 4px; }

.sb-canvas-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; }
.sb-stage { position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden; background: #e7ebf1; touch-action: none; cursor: default; }
.sb-stage:focus-visible { outline: 3px solid var(--sb-focus); outline-offset: -3px; }
.sb-stage[data-tool="hand"], .sb-stage.sb-panning { cursor: grab; }
.sb-stage:not([data-tool="select"]):not([data-tool="hand"]) { cursor: crosshair; }
.sb-svg { display: block; width: 100%; height: 100%; user-select: none; }
.sb-grid-line { stroke: #94a3b8; opacity: .35; }
.sb-dark-paper .sb-grid-line { stroke: #cbd5e1; opacity: .25; }
.sb-sel-box { stroke: var(--sb-sel); }
.sb-sel-line { stroke: var(--sb-sel); opacity: .35; }
.sb-handle { fill: #ffffff; stroke: var(--sb-sel); cursor: pointer; }
.sb-handle-glued { fill: var(--sb-sel); }
.sb-handle-rot { cursor: grab; }
.sb-lock-dot { fill: #a3271b; }
.sb-guide { stroke: #e11d48; stroke-dasharray: 4 3; }
.sb-marquee { fill: rgb(37 99 235 / .08); stroke: #2563eb; stroke-dasharray: 4 3; }
.sb-draft { fill: rgb(37 99 235 / .06); stroke: #2563eb; stroke-dasharray: 5 4; }
.sb-port { fill: #ffffff; stroke: #2563eb; }
.sb-port-on { fill: #2563eb; }
.sb-text-editor { position: absolute; z-index: 5; min-width: 80px; padding: 4px 6px; border: 2px solid var(--sb-sel); border-radius: 6px; background: rgb(255 255 255 / .96); color: #111827; resize: none; line-height: 1.25; }

/* side panel */
.sb-side { width: 300px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--sb-surface); border-inline-start: 1px solid var(--sb-line); }
.sb-tabs { display: flex; border-bottom: 1px solid var(--sb-line); }
.sb-tab { flex: 1; padding: 9px 6px; border-bottom: 3px solid transparent; border-radius: 0; color: var(--sb-ink); }
.sb-tab[aria-selected="true"] { border-bottom-color: var(--sb-accent); color: var(--sb-accent-ink); }
.sb-tabpanel { flex: 1; overflow-y: auto; padding: 10px 12px 16px; min-height: 0; position: relative; }
.sb-panel-title { font-size: 1rem; margin: 0 0 .5rem; overflow-wrap: anywhere; }
.sb-panel-sub { font-size: .9rem; margin: .8rem 0 .3rem; }
.sb-field { display: flex; flex-direction: column; gap: 3px; margin: 0 0 .55rem; min-width: 0; }
.sb-field label { font-size: .82rem; font-weight: 600; }
.sb-field-color { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.sb-field-color > label:first-child { min-width: 6.5em; }
.sb-check { display: flex; align-items: center; gap: 6px; font-size: .86rem; margin: 2px 0 6px; min-height: 28px; }
.sb-check > input[type="checkbox"] { width: 18px; height: 18px; margin: 0 2px; flex: none; }
/* the phone drawer floats over the (focusable) board, so its small controls need the full 24 px target size */
@media (max-width: 760px) { .sb-side input[type="checkbox"], .sb-side input[type="radio"], .sb-lib input[type="checkbox"] { width: 24px; height: 24px; margin: 0; flex: none; } }
.sb-layer .sb-check, .sb-field-color .sb-check { display: inline-flex; margin: 0; }
.sb-grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 8px; }
.sb-span2 { grid-column: 1 / -1; }
.sb-layers { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.sb-layer { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px; border: 1px solid var(--sb-line); border-radius: 8px; }
.sb-layer input[type="text"] { flex: 1 1 90px; }
.sb-outline { list-style: none; margin-top: 6px; max-height: 42vh; overflow-y: auto; border: 1px solid var(--sb-line); border-radius: 8px; position: relative; }
.sb-outline li { border-bottom: 1px solid var(--sb-line); }
.sb-outline-item { display: block; width: 100%; text-align: start; padding: 6px 8px; font-weight: 500; border-radius: 0; overflow-wrap: anywhere; }
.sb-outline-item[aria-pressed="true"] { background: var(--sb-surface-2); box-shadow: inset 4px 0 0 var(--sb-accent); font-weight: 700; }
.sb-outline-detail { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--sb-line); }
.sb-outline-detail textarea { width: 100%; }
.sb-tabpanel input[type="search"] { width: 100%; }

/* status */
.sb-status { display: flex; gap: 10px; align-items: center; padding: 4px 10px; font-size: .82rem; background: var(--sb-surface); border-top: 1px solid var(--sb-line); color: var(--sb-muted); min-height: 28px; }
.sb-status-text { color: var(--sb-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sb-saved { white-space: nowrap; }

/* dialogs */
.sb-dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--sb-line); border-radius: 14px; background: var(--sb-surface); color: var(--sb-ink); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.sb-dialog-wide { width: min(860px, calc(100vw - 24px)); }
.sb-dialog::backdrop { background: rgb(15 23 42 / .45); }
.sb-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; position: sticky; top: 0; background: var(--sb-surface); }
.sb-dialog-head h2 { font-size: 1.1rem; }
.sb-dialog-lede { padding: 0 16px; color: var(--sb-muted); font-size: .9rem; }
.sb-dialog-body { padding: 8px 16px 16px; }
.sb-dialog-body textarea { width: 100%; }
.sb-dialog-body select, .sb-dialog-body input[type="text"] { width: 100%; }
.sb-dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; margin-top: 12px; }
.sb-code { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.sb-template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 8px; }
.sb-template { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px; text-align: start; border: 1px solid var(--sb-line); border-radius: 10px; background: var(--sb-surface); color: var(--sb-ink); }
.sb-template:hover { border-color: var(--sb-accent); }
.sb-template span { font-weight: 400; font-size: .85rem; color: var(--sb-muted); }
.sb-recent { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.sb-recent li { display: flex; gap: 6px; align-items: center; }
.sb-recent-open { flex: 1; justify-content: flex-start; text-align: start; flex-wrap: wrap; }
.sb-warnings { margin: .4rem 0 0 1.2rem; padding: 0; color: var(--sb-muted); font-size: .85rem; }
.sb-table-wrap { overflow-x: auto; position: relative; }
.sb-export-opts { min-height: 3rem; }

/* presentation */
.sb-present { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #0b0f17; color: #f1f5f9; display: flex; flex-direction: column; }
.sb-present:not([open]) { display: none; }
.sb-present-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sb-present-stage svg { max-width: 100%; max-height: 100%; background: #ffffff; border-radius: 6px; }
.sb-present-bar { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px; background: #111827; }
.sb-present-bar .sb-btn { background: #1f2937; color: #f1f5f9; border-color: #64748b; }
.sb-present-count { margin: 0 8px; color: #e2e8f0; }

/* read-only */
.sb-readonly .sb-tools .sb-tool:not([data-tool="select"]):not([data-tool="hand"]) { opacity: .45; }
.uwapp-root.uwapp-sketchboard .uwt-readonly { flex: none; }

/* narrow screens: tools as a row, library and side panel as drawers */
@media (max-width: 760px) {
  .sb-main { flex-direction: column; }
  .sb-tools { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-inline-end: 0; border-bottom: 1px solid var(--sb-line); padding: 4px; }
  .sb-tool { flex: none; }
  .sb-panel-toggle, .sb-lib-toggle { display: inline-flex; }
  .sb-side, .sb-lib { position: absolute; z-index: 20; top: 46px; bottom: 0; width: min(320px, 92vw); visibility: hidden; box-shadow: 0 10px 30px rgb(0 0 0 / .25); }
  .sb-side { inset-inline-end: 0; }
  .sb-lib { inset-inline-start: 0; }
  .sb-side.sb-open, .sb-lib.sb-open { visibility: visible; }
  .sb-name { max-width: 14ch; }
  .sb-present-btn { padding: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) { .sb-app *, .sb-dialog * { transition: none !important; animation: none !important; } }
