/* ==========================================================================
   UTC NEXT — design system (SPEC section 8)
   One file, dark broadcast-console aesthetic. Sections:
     01 tokens          02 reset/base       03 layout
     04 top bar         05 buttons/inputs   06 popover + menus
     07 modal base      08 toasts           09 palette
     10 properties      11 pickers/bindings 12 canvas + grid
     13 widget chrome   14 widget types     15 responsive/tablet
   ========================================================================== */

/* --------------------------------------------------------------------------
   01 · Tokens
   -------------------------------------------------------------------------- */
:root {
  --bg: #101418;          /* app background */
  --surface: #1a2026;     /* panels, top bar */
  --surface2: #232b33;    /* cards, widget default */
  --surface3: #2b3540;    /* hover */
  --border: #313c46;
  --text: #e8edf2;
  --text-dim: #93a1ad;
  --accent: #2fa6ff;      /* focus, selection, primary buttons */
  --good: #37ad5f;
  --warn: #e0a63c;
  --bad: #e0483c;
  --radius: 8px;

  --topbar-h: 48px;
  --palette-w: 216px;
  --panel-w: 280px;
  --grid-dot: rgba(255, 255, 255, 0.10);
  --grid-line: rgba(255, 255, 255, 0.03);
  --field-bg: #0d1114;
  --shadow-pop: 0 16px 48px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.5);
  /* Bundled loopless Thai face first (ui/css/fonts.css); Leelawadee UI is
     the system fallback. The user's choice from the settings popover
     overrides this token at runtime (js/fontpref.js). */
  --font: 'IBM Plex Sans Thai', 'Leelawadee UI', 'Segoe UI Variable Text',
          'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Cascadia Mono', 'Consolas', monospace;

  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   02 · Reset / base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1100px 640px at 75% -180px, rgba(47, 166, 255, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  /* >= 1.4 everywhere text can be Thai: upper vowels + lower descenders
     (e.g. "รุ่นอายุ 2.1-3.0 ปี ญูฐ์") need the taller line box. */
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Form controls inherit the Thai-capable stack wholesale. */
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

input, select, textarea {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

::placeholder { color: var(--text-dim); opacity: 0.7; }

::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Scrollbars: thin + dark, one look everywhere */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #40505e; background-clip: padding-box; }
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }

noscript {
  display: block;
  padding: 24px;
  color: var(--warn);
}

/* --------------------------------------------------------------------------
   03 · Layout
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

#palette {
  width: var(--palette-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#properties {
  width: var(--panel-w);
  flex: none;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

/* Live mode: only top bar + canvas (SPEC section 8) */
#app:not(.mode-edit) #palette,
#app:not(.mode-edit) #properties {
  display: none;
}

#canvas-wrap {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
  position: relative;
  background:
    radial-gradient(900px 500px at 50% -120px, rgba(47, 166, 255, 0.04), transparent 65%),
    var(--bg);
}

.panel-title {
  padding: 12px 14px 10px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
  text-transform: uppercase; /* affects Latin only */
  letter-spacing: 0.1em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   04 · Top bar
   -------------------------------------------------------------------------- */
.topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, #1e252d 0%, #171d23 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 2px 12px rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 30;
}

.brand-icon {
  align-self: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  object-fit: contain;
  margin-right: 3px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.14em;
  user-select: none;
  white-space: nowrap;
}
.brand-utc { color: var(--text); }
.brand-next {
  color: var(--accent);
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 55%, transparent);
}
/* Brand becomes a mini-column: "UTC NEXT" over a small version line. */
.brand { align-items: center; }
.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1;
}
.brand-title { display: flex; align-items: baseline; gap: 5px; }
.brand-version {
  align-self: flex-start;
  margin-top: 2px;
  padding: 0;
  background: none;
  border: 0;
  font: inherit;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  cursor: default;
  transition: color 0.12s;
}
.brand-version.clickable { cursor: pointer; }
.brand-version.clickable:hover { color: var(--accent); }

.comp-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 220px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 600;
  white-space: nowrap;
}
.comp-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
}
.comp-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.comp-dirty {
  color: var(--warn);
  font-size: 9px;
  line-height: 1;
}

.tabs {
  flex: 1 1 auto;
  min-width: 0;
  align-self: stretch;
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.5;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: color 0.12s, background 0.12s;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: linear-gradient(180deg, transparent 40%, rgba(47, 166, 255, 0.10));
}
.tab-add {
  font-size: 16px;
  padding: 0 12px;
  color: var(--text-dim);
}
.tab-add:hover { color: var(--accent); }

/* Per-tab delete (edit mode) — an × that appears/brightens on hover */
.tab-label { display: inline-block; }
.tab-del {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  margin-left: 7px;
  margin-right: -4px;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1;
  color: var(--text-dim);
  opacity: 0.5;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.tab:hover .tab-del { opacity: 1; }
.tab-del:hover {
  background: color-mix(in srgb, var(--bad) 30%, transparent);
  color: #fff;
  opacity: 1;
}
.tab-rename {
  width: 110px;
  background: var(--field-bg);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 3px 6px;
}

.conn-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.conn-btn:hover { background: rgba(0, 0, 0, 0.4); border-color: #465665; }
.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 8px 1px color-mix(in srgb, var(--bad) 75%, transparent);
  animation: conn-pulse 1.6s ease-in-out infinite;
}
.conn-btn.on .conn-dot {
  background: var(--good);
  box-shadow: 0 0 8px 1px color-mix(in srgb, var(--good) 75%, transparent);
  animation: none;
}
@keyframes conn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.conn-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.conn-btn.on .conn-label { color: var(--text); }

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.segmented button {
  padding: 4px 16px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: 0.03em;
  transition: color 0.12s, background 0.12s;
}
.segmented button:hover { color: var(--text); }
/* Live = on-air red, Edit = accent blue */
.mode-toggle .seg-live.active {
  background: var(--bad);
  color: #fff;
  box-shadow: 0 0 12px color-mix(in srgb, var(--bad) 55%, transparent);
}
.mode-toggle .seg-edit.active {
  background: var(--accent);
  color: #03121f;
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 45%, transparent);
}

.lang-btn {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* Tablet-only palette/properties overlay toggles (see section 15).
   Scoped to .topbar so this outranks the later .btn display rule. */
.topbar .panel-toggle { display: none; }

/* --------------------------------------------------------------------------
   05 · Buttons + form controls
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 13px;
  background: linear-gradient(180deg, var(--surface3), var(--surface2));
  border: 1px solid var(--border);
  border-radius: 7px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
}
.btn:hover { border-color: #46586a; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, white), color-mix(in srgb, var(--accent) 82%, black));
  border-color: color-mix(in srgb, var(--accent) 70%, black);
  color: #03121f;
}
.btn-primary:hover { border-color: var(--accent); }

.btn-danger {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bad) 88%, white), color-mix(in srgb, var(--bad) 78%, black));
  border-color: color-mix(in srgb, var(--bad) 65%, black);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
}

.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-block { width: 100%; }

input[type="text"],
input[type="number"],
input[type="search"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 6px 9px;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
/* Textareas hold user content (list items etc.) that is often Thai —
   keep the Thai-capable UI face, not the mono stack. */
textarea { resize: vertical; min-height: 60px; font-size: 13px; line-height: 1.55; }

select { cursor: pointer; }
option { background: var(--surface); color: var(--text); }

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  flex: none;
}

/* --------------------------------------------------------------------------
   06 · Popover + menus
   -------------------------------------------------------------------------- */
.popover {
  position: fixed;
  z-index: 950;
  min-width: 250px;
  max-width: min(360px, calc(100vw - 16px));
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  animation: pop-in 0.13s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: none; }
}

.menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  text-align: start;
  font-weight: 500;
  line-height: 1.5;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.menu-item.grow { flex: 1 1 auto; min-width: 0; }
.menu-item-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.menu-meta {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--text-dim);
}
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-title {
  padding: 8px 10px 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
.menu-list { max-height: 42vh; overflow-y: auto; }
.menu-row { display: flex; align-items: center; gap: 2px; }
.menu-empty { padding: 8px 10px; font-size: 12.5px; color: var(--text-dim); }
.menu-x {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12px;
}
.menu-x:hover { color: #fff; background: color-mix(in srgb, var(--bad) 40%, transparent); }

.saveas {
  display: flex;
  gap: 6px;
  padding: 8px 6px 4px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}
.saveas input { flex: 1 1 auto; }

.settings-pop { width: 270px; }
.pop-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 10px;
}
.pop-field > span { font-size: 12px; color: var(--text-dim); }
.pop-status { margin: 6px 10px 2px; font-size: 12px; font-weight: 600; }
.pop-status.good { color: var(--good); }
.pop-status.bad { color: var(--bad); }
.pop-save { margin: 8px 10px 6px; width: calc(100% - 20px); }

/* --------------------------------------------------------------------------
   07 · Modal base (used by the command editor / .vmc importer later)
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 7, 10, 0.66);
  backdrop-filter: blur(3px);
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(84vh, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.75);
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.modal-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}
.modal-header .modal-close { margin-inline-start: auto; }

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px;
}

.modal-footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  border-radius: 0 0 12px 12px;
}

/* Small confirm/alert dialogs (js/dialog.js) — stack above every modal. */
.dialog-backdrop { z-index: 1300; }
.dialog { width: min(400px, 100%); }
.dialog .dialog-message {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}
.dialog .modal-footer .btn { min-width: 96px; min-height: 40px; }

/* --------------------------------------------------------------------------
   08 · Toasts
   -------------------------------------------------------------------------- */
#toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(480px, calc(100vw - 32px));
  padding: 11px 16px;
  line-height: 1.5;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(6px); }
/* Update-ready toast: message + a "restart to install" action, no auto-dismiss. */
.toast.update-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  /* #toasts is pointer-events:none (clicks pass through plain toasts); an
     actionable toast must opt back in or its button can never be clicked —
     this was the real reason "restart to install" did nothing. */
  pointer-events: auto;
}
.toast .toast-action {
  flex: 0 0 auto;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.toast .toast-action:hover { filter: brightness(1.08); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   09 · Palette (left, edit mode)
   -------------------------------------------------------------------------- */
.palette-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: start;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.palette-item:hover {
  background: var(--surface3);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  transform: translateX(2px);
}
.palette-item:active { transform: translateX(2px) scale(0.985); }
.palette-icon {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--field-bg);
  border-radius: 7px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}
.palette-label {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* layout tools pinned under the widget list */
.palette-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  margin-top: 2px;
  border-top: 1px solid var(--border);
  /* arrange + undo/redo stay in view while the widget list scrolls */
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: 0 -8px 16px rgba(0, 0, 0, 0.25);
}
.palette-tool {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 16%, var(--surface2));
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.palette-tool:hover {
  background: color-mix(in srgb, var(--accent) 28%, var(--surface2));
  border-color: var(--accent);
}
.palette-tool:active { transform: scale(0.985); }
.palette-tool-secondary {
  border-color: var(--border);
  background: var(--surface2);
  color: var(--text-dim);
}
.palette-tool-row { display: flex; gap: 6px; }
.palette-tool-row > .palette-tool { flex: 1 1 0; min-width: 0; }
.palette-tool:disabled { opacity: 0.4; cursor: default; transform: none; }
.palette-tool-secondary:disabled:hover { background: var(--surface2); border-color: var(--border); color: var(--text-dim); }
.palette-tool-secondary:hover {
  background: var(--surface3);
  border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
  color: var(--text);
}

/* --------------------------------------------------------------------------
   10 · Properties panel (right, edit mode)
   -------------------------------------------------------------------------- */
.props-head { border-bottom: 1px solid var(--border); }
.props-head .panel-title { border-bottom: none; padding-bottom: 2px; }
.props-widget-id {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 14px 10px;
}
.props-type { font-size: 13px; font-weight: 700; color: var(--accent); }
.props-id { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); }

.props-empty {
  padding: 28px 18px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}

.props-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 12px 14px 28px;
}

.props-section {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.props-section-title {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-label { font-size: 12px; color: var(--text-dim); }
.field-inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.field-inline .field-label { font-size: 13px; color: var(--text); }
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.color-field { display: flex; align-items: center; gap: 6px; }
.color-text { flex: 1 1 auto; font-family: var(--font-mono); font-size: 12px; }

/* --------------------------------------------------------------------------
   11 · Pickers + bindings (SPEC section 7.1)
   -------------------------------------------------------------------------- */
.picker { min-width: 0; }
.picker select, .picker input { width: 100%; }

.bindings {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.binding-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}
.binding-remove { padding: 4px 6px; }
.bindings-add { align-self: flex-start; }
.bindings-empty { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* --------------------------------------------------------------------------
   12 · Canvas + grid
   -------------------------------------------------------------------------- */
.canvas {
  position: relative;
  /* Own stacking context so region widgets with negative z still paint
     above the canvas grid background. */
  z-index: 0;
  min-width: 100%;
  min-height: 100%;
  --grid: 8px;
}
.canvas.edit {
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px),
    radial-gradient(circle, var(--grid-dot) 1px, transparent 1.4px);
  background-size:
    calc(var(--grid) * 8) calc(var(--grid) * 8),
    calc(var(--grid) * 8) calc(var(--grid) * 8),
    var(--grid) var(--grid);
}

/* --------------------------------------------------------------------------
   13 · Widget chrome
   -------------------------------------------------------------------------- */
.widget {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--w-bg, var(--surface2));
  border: 1px solid var(--w-border, var(--border));
  color: var(--w-text, var(--text));
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.15s, border-color 0.15s, background-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

/* Rendered only when the widget has a non-empty name (canvas.js keeps it
   hidden otherwise). Line box tall enough for Thai marks — never crop. */
.widget-caption {
  flex: none;
  padding: 5px 10px 2px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  text-transform: uppercase; /* affects Latin only */
  letter-spacing: 0.07em;
  color: color-mix(in srgb, var(--w-text, var(--text)) 62%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) - 2px);
}

/* Edit-mode interaction: bodies are inert so the chrome drags cleanly */
.canvas.edit .widget { touch-action: none; cursor: move; }
.canvas.edit .widget-body { pointer-events: none; }
.canvas.edit .widget.locked { cursor: default; opacity: 0.82; }

/* Selection outline (SPEC section 8) */
.widget.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Group selection: the last-clicked one (properties panel) is drawn solid */
.canvas.edit .widget.selected:not(.primary):not(:has(.handles)) { outline-style: dashed; }
/* Rubber-band box while drag-selecting on empty canvas */
.marquee {
  position: absolute;
  z-index: 100000;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  pointer-events: none;
}
.props-multi {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface2));
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}

/* Lit/active glow: brighter face + strong ring in the widget border color */
.widget.lit,
.widget:has(.lit) {
  background: color-mix(in srgb, var(--w-bg, var(--surface2)) 72%, white);
  border-color: color-mix(in srgb, var(--w-border, var(--accent)) 45%, white);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--w-border, var(--accent)) 80%, white),
    0 0 18px 3px color-mix(in srgb, var(--w-border, var(--accent)) 65%, transparent),
    0 0 40px 6px color-mix(in srgb, var(--w-border, var(--accent)) 25%, transparent),
    0 2px 10px rgba(0, 0, 0, 0.4);
}

/* 8 resize handles */
.handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px;
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  touch-action: none;
}
.handle-nw { top: 0;    left: 0;    cursor: nwse-resize; }
.handle-n  { top: 0;    left: 50%;  cursor: ns-resize; }
.handle-ne { top: 0;    left: 100%; cursor: nesw-resize; }
.handle-e  { top: 50%;  left: 100%; cursor: ew-resize; }
.handle-se { top: 100%; left: 100%; cursor: nwse-resize; }
.handle-s  { top: 100%; left: 50%;  cursor: ns-resize; }
.handle-sw { top: 100%; left: 0;    cursor: nesw-resize; }
.handle-w  { top: 50%;  left: 0;    cursor: ew-resize; }

/* --------------------------------------------------------------------------
   14 · Widget type minimal styles
   -------------------------------------------------------------------------- */
.w-label {
  display: flex;
  align-items: center;
  padding: 0 10px;
  overflow: hidden;
}
.w-label-text {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  line-height: 1.55; /* room for Thai upper vowels + descenders */
}

/* Placeholder look for unimplemented widget stubs */
.w-stub {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background:
    repeating-linear-gradient(45deg, transparent 0 10px, rgba(255, 255, 255, 0.025) 10px 20px);
}

/* ---- button (widgets/button.js) ---- */
.w-button { display: flex; }

/* Outer chrome: soft drop shadow gives buttons physical depth.
   :not(.lit) keeps this from outranking the lit glow ring (section 13). */
.widget:not(.lit):has(.w-button) {
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.45),
    0 6px 18px rgba(0, 0, 0, 0.22);
}

/* Face: layered top-light gradient + 1px inner highlight over the user's
   bg color. The label lives in .w-btn-label so ellipsis + Thai-safe
   line-height work independently of the flex centering. */
.w-btn-face {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.10) 0%,
    rgba(255, 255, 255, 0.03) 46%,
    rgba(0, 0, 0, 0.05) 54%,
    rgba(0, 0, 0, 0.12) 100%
  );
  border: none;
  color: inherit;
  text-align: center;
  overflow: hidden;
  border-radius: inherit;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -1px 0 rgba(0, 0, 0, 0.20);
  transition: background 0.12s, box-shadow 0.12s, filter 0.12s;
}
/* At small heights (< 30px) flex centering + face overflow clip the label
   symmetrically: no half-cut Thai, padding preserved. */
.w-btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.015em; /* subtle; effectively for Latin */
  line-height: 1.6;        /* Thai upper vowels + lower descenders */
}
/* The face shows the widget name — hide the duplicate caption strip */
.widget:has(.w-button) .widget-caption { display: none; }

/* States (live mode) */
.canvas:not(.edit) .w-btn-face:hover {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.17) 0%,
    rgba(255, 255, 255, 0.07) 46%,
    rgba(0, 0, 0, 0.02) 54%,
    rgba(0, 0, 0, 0.09) 100%
  );
}
.canvas:not(.edit) .w-btn-face:active,
.w-button.pressed .w-btn-face {
  transform: translateY(1px);
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.18) 0%,
    rgba(0, 0, 0, 0.08) 100%
  );
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(0, 0, 0, 0.25);
}
.w-button.pressed { background: rgba(0, 0, 0, 0.10); }
.canvas:not(.edit) .w-btn-face:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* Lit: brighter face on top of the widget-level glow ring */
.widget.lit .w-btn-face {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0.10) 46%,
    rgba(255, 255, 255, 0.02) 54%,
    rgba(0, 0, 0, 0.06) 100%
  );
}

/* Cue/take (button.js + cue.js), live mode only.
   Picked: chosen in its pick group — a gold ring, unlike the lit glow. */
.widget.picked:has(.w-button) {
  border-color: #ffd36a;
  box-shadow:
    0 0 0 2px #ffd36a,
    0 0 16px 2px rgba(255, 211, 106, 0.45),
    0 2px 10px rgba(0, 0, 0, 0.4);
}
.widget.picked .w-btn-face {
  background: linear-gradient(
    180deg,
    rgba(255, 236, 170, 0.30) 0%,
    rgba(255, 236, 170, 0.12) 46%,
    rgba(0, 0, 0, 0.02) 54%,
    rgba(0, 0, 0, 0.06) 100%
  );
}
.widget.picked .w-btn-label::before { content: '✓ '; }
/* Blocked: something is on air, or the required group has no pick yet.
   The face keeps its resting look (no hover/press) and says why on hover. */
.canvas:not(.edit) .widget.blocked { opacity: 0.32; filter: saturate(0.5); }
/* ...but what was picked (= what is on air) stays readable */
.canvas:not(.edit) .widget.blocked.picked { opacity: 0.7; filter: none; }
.canvas:not(.edit) .widget.blocked .w-btn-face,
.canvas:not(.edit) .widget.blocked .w-btn-face:hover,
.canvas:not(.edit) .widget.blocked .w-btn-face:active {
  cursor: not-allowed;
  transform: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.10) 0%,
    rgba(255, 255, 255, 0.03) 46%,
    rgba(0, 0, 0, 0.05) 54%,
    rgba(0, 0, 0, 0.12) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -1px 0 rgba(0, 0, 0, 0.20);
}
/* Hold time ("8 วิ"), then the seconds left + a draining bar while on air */
.w-btn-face { position: relative; }
.w-btn-badge {
  flex: none;
  margin-left: 8px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.30);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.widget.holding .w-btn-badge {
  min-width: 2.4em;
  background: rgba(0, 0, 0, 0.45);
  font-size: 15px;
  text-align: center;
}
.w-btn-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
  transition: width 0.25s linear;
}
.w-btn-badge[hidden],
.w-btn-progress[hidden] { display: none; }

/* ---- region (widgets/region.js) ---- */
/* Soft translucent grouping panel: user's bg color, thinned out */
.widget:has(.w-region) {
  background: color-mix(in srgb, var(--w-bg, var(--surface2)) 45%, transparent);
  border-color: color-mix(in srgb, var(--w-border, var(--border)) 55%, transparent);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: none;
}
.w-region { padding: 8px 12px; }
.w-region-text {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.08em;
  text-transform: uppercase; /* affects Latin only */
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- textfield (widgets/textfield.js) ---- */
.w-textfield {
  display: flex;
  align-items: center;
  padding: 5px;
}
input.w-textfield-input {
  height: 100%;
  min-height: 0;
  padding: 5px 12px;
  font-size: 14px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}
input.w-textfield-input:focus {
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.35),
    0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---- lower third (widgets/lowerthird.js) ---- */
.w-lowerthird {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  overflow: hidden;
}
/* On air: a red ring instead of the shared light-up wash (the panel holds
   text fields that must stay readable). */
.widget.lit:has(.w-lowerthird) {
  background: var(--w-bg, var(--surface2));
  border-color: var(--bad);
  box-shadow:
    0 0 0 1px var(--bad),
    0 0 16px 2px color-mix(in srgb, var(--bad) 45%, transparent),
    0 2px 10px rgba(0, 0, 0, 0.4);
}
.w-lt-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
select.w-lt-style { flex: 1 1 auto; min-width: 0; height: 32px; padding: 2px 8px; font-size: 13.5px; }
.w-lt-badge {
  flex: 0 0 auto;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface3);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.6;
  white-space: nowrap;
}
.w-lt-badge.on {
  background: var(--bad);
  color: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 30%, transparent);
}
.w-lt-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 10px;
  align-items: center;
}
.w-lt-label { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; white-space: nowrap; }
.w-lt-label[hidden], .w-lt-event[hidden] { display: none; }
.w-lt-event { display: flex; align-items: center; gap: 8px; min-width: 0; }
.w-lt-event .w-lt-input { flex: 1 1 auto; }
.w-lt-event .w-lt-input:disabled { opacity: 0.45; }
.w-lt-switch { display: flex; align-items: center; gap: 5px; flex: none; font-size: 12.5px; line-height: 1.6; color: var(--text-dim); white-space: nowrap; cursor: pointer; }
input.w-lt-input { height: 36px; min-width: 0; padding: 4px 10px; font-size: 15px; }
.w-lt-actions { display: flex; gap: 8px; }
.w-lt-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface3);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}
.w-lt-show { background: color-mix(in srgb, var(--good) 82%, #000); border-color: transparent; color: #fff; }
.w-lt-show.update { background: color-mix(in srgb, var(--accent) 70%, #000); }
.w-lt-hide.on { background: color-mix(in srgb, var(--bad) 72%, #000); border-color: transparent; color: #fff; }
.canvas:not(.edit) .w-lt-btn:not(:disabled):hover { filter: brightness(1.12); }
.canvas:not(.edit) .w-lt-btn:not(:disabled):active { transform: translateY(1px); }
.w-lt-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.w-lt-hint { font-size: 12px; line-height: 1.6; color: var(--warn); }
/* Built-in design that isn't in vMix yet (lowerthird.js): the fields wait. */
.w-lowerthird.needs-install .w-lt-grid,
.w-lowerthird.needs-install .w-lt-actions,
.w-lowerthird.needs-install .w-lt-presets { display: none; }
.w-lt-install[hidden] { display: none; }
.w-lt-install { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.w-lt-thumb {
  width: 100%;
  max-height: 96px;
  object-fit: contain;
  border-radius: 6px;
  background:
    repeating-conic-gradient(rgba(255, 255, 255, 0.05) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px,
    #0b0e11;
}
.w-lt-install-text { font-size: 12.5px; font-weight: 600; line-height: 1.6; color: var(--text); }
.w-lt-install-btns { display: flex; gap: 6px; }
.w-lt-install-btns > * { flex: 1 1 0; }
a.w-lt-btn { display: grid; place-items: center; text-decoration: none; color: inherit; }
.w-lt-add[hidden] { display: none; }
.w-lt-install-note,
.w-lt-install-msg { font-size: 11.5px; line-height: 1.6; color: var(--text-dim); }
.w-lt-install-msg:empty { display: none; }
.w-lt-link { color: var(--accent); }
.w-lt-presets {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.w-lt-presets-empty { font-size: 12px; line-height: 1.6; color: var(--text-dim); opacity: 0.8; }
.w-lt-preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  line-height: 1.5;
}
.w-lt-preset b { font-size: 13px; font-weight: 600; }
.w-lt-preset span { font-size: 11.5px; color: var(--text-dim); }
.w-lt-preset b, .w-lt-preset span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canvas:not(.edit) .w-lt-preset:hover { border-color: var(--accent); }
.w-lt-preset.current { border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }

/* ---- list (widgets/list.js): dropdown control + floating panel ---- */
.w-list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  /* Breathing room so the control reads as a distinct dropdown, not a slab
     glued to the widget edges (user feedback: "มันชิดๆ ไป"). */
  padding: 8px 10px;
}
.w-list-control {
  flex: 0 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  max-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.07) 0%,
    rgba(255, 255, 255, 0.01) 55%,
    rgba(0, 0, 0, 0.07) 100%
  ), var(--field-bg);
  border: 1px solid color-mix(in srgb, var(--w-border, var(--border)) 75%, transparent);
  border-radius: 8px;
  color: inherit;
  text-align: start;
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10);
  transition: background 0.12s, box-shadow 0.12s;
}
.canvas:not(.edit) .w-list-control:hover {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.05) 55%,
    rgba(0, 0, 0, 0.04) 100%
  );
}
.canvas:not(.edit) .w-list-control:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.w-list-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6; /* Thai-safe */
}
.w-list-control.empty .w-list-value {
  opacity: 0.55;
  font-weight: 500;
}
.w-list-chevron {
  flex: none;
  font-size: 11px;
  line-height: 1;
  opacity: 0.65;
  transition: transform 0.15s;
}
.w-list-control.open .w-list-chevron { transform: rotate(180deg); }

/* Floating options panel — appended to document.body, never clipped */
.w-list-pop {
  position: fixed;
  z-index: 1100;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  animation: pop-in 0.12s ease-out;
}
.w-list-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px; /* touch row */
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text);
  text-align: start;
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.5;
}
.w-list-opt:hover,
.w-list-opt.active { background: rgba(255, 255, 255, 0.07); }
.w-list-opt.selected {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.w-list-opt.selected:hover,
.w-list-opt.selected.active {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
}
.w-list-opt-check {
  flex: none;
  width: 16px;
  color: var(--accent);
  font-weight: 700;
  opacity: 0;
  text-align: center;
}
.w-list-opt.selected .w-list-opt-check { opacity: 1; }
.w-list-opt-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- timer (widgets/timer.js) ---- */
.w-timer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  overflow: hidden;
}
/* Digits in an inset dark well. Rows share leftover height 4:3:3 so the
   widget degrades gracefully at small heights instead of clipping rows. */
input.w-timer-display {
  flex: 4 1 0;
  min-height: 26px;
  width: 100%;
  padding: 2px 8px;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: inherit;
  text-align: center;
}
input.w-timer-display:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input.w-timer-display.running {
  color: var(--good);
  text-shadow: 0 0 12px color-mix(in srgb, var(--good) 45%, transparent);
}
.w-timer-row {
  flex: 3 1 0;
  min-height: 26px;
  max-height: 44px; /* rows grow toward 40px+ targets on tall widgets */
  display: flex;
  gap: 6px;
}
.w-timer-btn {
  flex: 1 1 0;
  min-width: 40px;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  background: linear-gradient(180deg, var(--surface3), var(--surface2));
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
}
.w-timer-btn:hover { border-color: #4d6175; background: linear-gradient(180deg, #33404c, var(--surface3)); }
.w-timer-btn:active { transform: translateY(1px); }
/* Transport row: Start/Pause is the primary target */
.w-timer-startpause { flex: 1.7 1 0; font-size: 13px; }
.w-timer-startpause.running {
  background: color-mix(in srgb, var(--good) 30%, var(--surface2));
  border-color: color-mix(in srgb, var(--good) 60%, var(--border));
  box-shadow: 0 0 10px color-mix(in srgb, var(--good) 30%, transparent);
}
/* +1m/+10s/-10s/-1m: tidy 4-column row, tabular digits */
.w-timer-adj {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

/* ---- score (widgets/score.js) ---- */
.w-score {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  overflow: hidden;
}
.w-score-top {
  flex: 5 1 0;
  min-height: 28px;
  display: flex;
  align-items: stretch;
  gap: 6px;
}
/* Big value in the same inset well language as the timer */
.w-score-value {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 700;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
}
.w-score-row {
  flex: 3 1 0;
  min-height: 26px;
  max-height: 44px;
  display: flex;
  gap: 6px;
}
.w-score-btn {
  flex: 1 1 0;
  min-width: 40px;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 4px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.4;
  background: linear-gradient(180deg, var(--surface3), var(--surface2));
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
}
.w-score-btn:hover { border-color: #4d6175; background: linear-gradient(180deg, #33404c, var(--surface3)); }
.w-score-btn:active { transform: translateY(1px); }
.w-score-reset { flex: none; width: 40px; color: var(--text-dim); }
.w-score-reset:hover { color: var(--text); }

/* ---- monitor (widgets/monitor.js) ---- */
.w-monitor { display: flex; flex-direction: column; }
.w-monitor-head {
  flex: none;
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px 3px 10px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.06em;
  text-transform: uppercase; /* affects Latin only */
  color: var(--text-dim);
  border-bottom: 1px solid var(--w-border, var(--border));
}
.w-monitor-src {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.w-monitor-power {
  flex: none;
  width: 28px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  transition: color 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.w-monitor-power:hover { color: var(--text); border-color: #4d6175; }
.w-monitor-power.on {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 60%, var(--border));
  background: color-mix(in srgb, var(--good) 14%, transparent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--good) 45%, transparent);
}
.w-monitor-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.w-monitor-img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.w-monitor.has-frame .w-monitor-img { display: block; }
.w-monitor-ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase; /* affects Latin only */
}
.w-monitor.has-frame .w-monitor-ph { display: none; }

/* --------------------------------------------------------------------------
   15 · Responsive / tablet (≤ 1024px) + touch
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  :root { --panel-w: 300px; }

  /* Palette/properties become slide-in overlays (SPEC section 8) */
  #app.mode-edit #palette,
  #app.mode-edit #properties {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    z-index: 700;
    transition: transform 0.18s ease-out;
    box-shadow: 0 0 48px rgba(0, 0, 0, 0.6);
  }
  #app.mode-edit #palette {
    left: 0;
    transform: translateX(-102%);
  }
  #app.mode-edit #properties {
    right: 0;
    transform: translateX(102%);
  }
  #app.mode-edit #palette.open,
  #app.mode-edit #properties.open {
    transform: none;
  }

  /* Show the toggle buttons in the top bar (edit mode only) */
  #app.mode-edit .panel-toggle { display: inline-flex; }

  .comp-btn { max-width: 140px; }
}

@media (max-width: 700px) {
  .conn-label { display: none; }
  .brand { font-size: 12px; }
}

/* Touch: min 40px hit targets (SPEC section 8) */
@media (pointer: coarse) {
  .btn, .tab, .menu-item, .segmented button, .comp-btn, .conn-btn {
    min-height: 40px;
  }
  input[type="text"], input[type="number"], select { min-height: 38px; }
  .handle { width: 22px; height: 22px; margin: -11px; }
  .w-timer-row, .w-score-row { min-height: 36px; max-height: 48px; }
  .w-list-opt { min-height: 48px; }
  .w-list-control { min-height: 48px; }
}

/* --------------------------------------------------------------------------
   16 · Command editor + .vmc import modals (command-editor.js / vmc-import.js)
   -------------------------------------------------------------------------- */
.cmd-modal {
  width: min(980px, 100%);
  height: min(680px, 84vh);
}
.cmd-widget-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.cmd-body {
  display: grid;
  grid-template-columns: minmax(230px, 320px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

/* left: function catalog */
.cmd-catalog {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.cmd-groups {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cmd-group-h {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: start;
}
.cmd-group-h:hover { background: rgba(255, 255, 255, 0.05); }
.cmd-group-arrow { flex: none; width: 12px; color: var(--text-dim); font-size: 10px; }
.cmd-group-n {
  margin-inline-start: auto;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.cmd-group-list { display: flex; flex-direction: column; padding: 0 0 4px 14px; }
.cmd-fn {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  text-align: start;
}
.cmd-fn:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.cmd-fn-name { display: block; font-size: 13px; font-weight: 600; }
.cmd-fn-desc {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* right: sequence + params */
.cmd-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}
.cmd-seq-head { display: flex; align-items: baseline; gap: 8px; }
.cmd-seq-head .props-section-title { flex: 1 1 auto; }
.cmd-seq-count { font-size: 11px; font-weight: 700; color: var(--text-dim); }
.cmd-seq {
  flex: 1 1 auto;
  min-height: 90px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
}
.cmd-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px 2px 2px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.cmd-row:last-child { border-bottom: none; }
.cmd-row.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.cmd-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  text-align: start;
}
.cmd-row-idx {
  flex: none;
  min-width: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-align: end;
}
.cmd-row-fn { flex: none; font-size: 13px; font-weight: 600; }
.cmd-row-sum {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--text-dim);
}
.cmd-row-btn { flex: none; padding: 4px 7px; }
.cmd-row-rm:hover { color: #fff; background: color-mix(in srgb, var(--bad) 40%, transparent); }

.cmd-params {
  flex: none;
  max-height: 46%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
}
.cmd-params-head { display: flex; align-items: baseline; gap: 8px; }
.cmd-params-fn { font-size: 13.5px; font-weight: 700; }
.cmd-params-group { font-size: 11px; color: var(--text-dim); }
.cmd-help { font-size: 12px; color: var(--text-dim); line-height: 1.45; }
.cmd-help-warn { color: var(--warn); }
.cmd-params-grid { display: flex; flex-direction: column; gap: 9px; }
.cmd-msg { padding: 14px 10px; font-size: 12.5px; color: var(--text-dim); text-align: center; }

/* narrow screens: stack catalog above the sequence */
@media (max-width: 760px) {
  .cmd-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: 240px minmax(0, 1fr); }
  .cmd-modal { height: min(92vh, 100%); }
}

/* .vmc import summary */
.vmc-modal { width: min(560px, 100%); }

/* ---- pageant panel wizard (pageant-wizard.js) ---- */
.pg-modal { width: min(760px, 100%); }
.pg-section { margin-bottom: 14px; }
.pg-hint { margin: 2px 0 8px; font-size: 12px; line-height: 1.6; color: var(--text-dim); }
.pg-hint.pg-warn { color: var(--warn); }
.pg-tabs, .pg-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.pg-inline > input[type=text] { flex: 1 1 240px; min-width: 0; }
.pg-textarea { width: 100%; font-size: 13px; line-height: 1.6; font-family: inherit; resize: vertical; }
.pg-check { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 12.5px; color: var(--text-dim); }
.pg-map { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.pg-mapcol { display: flex; flex-direction: column; gap: 4px; width: 140px; min-width: 0; }
.pg-mapsample { font-size: 11.5px; line-height: 1.5; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pg-row { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 10px; align-items: center; margin: 6px 0; }
.pg-row[hidden], .pg-paste[hidden], .pg-act[hidden] { display: none; }
.pg-label { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }
.pg-count { margin-top: 6px; font-size: 12.5px; line-height: 1.6; color: var(--text); }
.pg-status { margin-inline-end: auto; align-self: center; font-size: 12.5px; line-height: 1.6; color: var(--text-dim); }
.vmc-file {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.vmc-body { display: flex; flex-direction: column; gap: 16px; }
.vmc-line { font-size: 13px; font-weight: 600; }
.vmc-warn { color: var(--warn); font-weight: 500; }
.vmc-counts, .vmc-skips {
  margin: 0;
  padding-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
}
.vmc-skips { color: var(--warn); }
.vmc-hint {
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: 12.5px;
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   17 - Widget parity round: clock / tbar / volume / multistate / playlist /
        container / templates (merged from build agents)
   -------------------------------------------------------------------------- */

/* ---- clock (widgets/clock.js) ---- */
.w-clock {
  display: flex;
  align-items: stretch;
  padding: 7px;
  container-type: size; /* lets the digits scale with widget height (cqh) */
}
.w-clock-time {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(14px, 56cqh, 84px);
  font-weight: 600;
  letter-spacing: 0.05em;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  color: inherit;
}

/* ---- tbar (widgets/tbar.js) ---- */
.w-tbar {
  --tbar: 0; /* 0..1 travel, set from JS */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 7px 7px;
  overflow: hidden;
}
.w-tbar-track {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 44px; /* >= 40px touch target */
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.55);
  touch-action: none; /* raw pointer dragging on touch */
  cursor: ns-resize;
}
.w-tbar-fill {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  height: calc(var(--tbar) * (100% - 8px));
  border-radius: 7px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 80%, white),
    var(--accent)
  );
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
  pointer-events: none;
}
.w-tbar-thumb {
  position: absolute;
  left: -6px;
  right: -6px;
  height: 18px;
  bottom: calc(var(--tbar) * (100% - 18px));
  border-radius: 6px;
  background: linear-gradient(180deg, #3a4754, var(--surface3));
  border: 1px solid #4d6175;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);
  pointer-events: none;
}
.w-tbar-thumb::after { /* grip line */
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  border-radius: 1px;
  background: color-mix(in srgb, var(--text) 45%, transparent);
}
.w-tbar.dragging .w-tbar-thumb {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent),
    0 2px 6px rgba(0, 0, 0, 0.5);
}
.w-tbar-pct {
  flex: none;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-dim);
}
.w-tbar.dragging .w-tbar-pct { color: var(--accent); }

/* ---- volume (widgets/volume.js) ---- */
.w-volume {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 10px;
  overflow: hidden;
}
.w-vol-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  line-height: 1.45; /* Thai upper vowels + descenders */
}
.w-vol-target {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: color-mix(in srgb, var(--w-text, var(--text)) 70%, transparent);
}
.w-vol-value {
  flex: none;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.w-vol-row {
  flex: 1 1 auto;
  min-height: 40px; /* touch */
  display: flex;
  align-items: center;
  gap: 8px;
}
.w-vol-mute {
  flex: none;
  align-self: stretch;
  width: 40px;
  min-height: 40px;
  max-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  background: linear-gradient(180deg, var(--surface3), var(--surface2));
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.w-vol-mute:hover:not(:disabled) { border-color: #4d6175; }
.w-vol-mute:active:not(:disabled) { transform: translateY(1px); }
.w-vol-mute.muted {
  color: var(--bad);
  text-decoration: line-through;
  background: color-mix(in srgb, var(--bad) 18%, var(--surface2));
  border-color: color-mix(in srgb, var(--bad) 55%, var(--border));
  box-shadow: 0 0 10px color-mix(in srgb, var(--bad) 25%, transparent);
}
.w-vol-mute:disabled { opacity: 0.45; cursor: default; }
.w-volume.unbound { opacity: 0.75; }

/* Range slider: dark inset track + accent fill (--vol set from JS) */
.w-vol-slider {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px; /* touch target */
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
.w-vol-slider:disabled { opacity: 0.45; }
.w-vol-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background:
    linear-gradient(
      to right,
      color-mix(in srgb, var(--accent) 65%, var(--surface3)) 0 var(--vol, 0%),
      var(--field-bg) var(--vol, 0%)
    );
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}
.w-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px;
  border-radius: 50%;
  background: linear-gradient(180deg, #3a4754, var(--surface3));
  border: 1px solid #4d6175;
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
.w-vol-slider:not(:disabled)::-webkit-slider-thumb:hover,
.w-vol-slider:not(:disabled):active::-webkit-slider-thumb { border-color: var(--accent); }
.w-vol-slider::-moz-range-track {
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--field-bg);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}
.w-vol-slider::-moz-range-progress {
  height: 10px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 65%, var(--surface3));
}
.w-vol-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(180deg, #3a4754, var(--surface3));
  border: 1px solid #4d6175;
}

/* clock/tbar/volume touch additions — merge into the existing
   `@media (pointer: coarse)` block in section 15 if preferred */
@media (pointer: coarse) {
  .w-vol-row { min-height: 44px; }
  .w-tbar-track { width: 52px; }
}


/* ---- multistate (widgets/multistate.js) ---- */
.w-multistate {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 7px 10px;
  overflow: hidden;
}
.w-multistate-caption {
  flex: none;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.07em;
  text-transform: uppercase; /* affects Latin only */
  color: color-mix(in srgb, var(--w-text, var(--text)) 62%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Value in the same inset dark well language as timer/score. Values can be
   Thai title text (Elements[...].Text) — keep line-height >= 1.5 for the
   mono stack's Thai fallback face. */
.w-multistate-value {
  display: block;
  max-width: 100%;
  padding: 2px 10px;
  text-align: center;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.w-multistate-value.empty { color: var(--text-dim); }

/* ---- playlist (widgets/playlist.js) ---- */
.w-playlist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  overflow: hidden;
}
.w-playlist-name {
  flex: none;
  padding: 0 3px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.06em;
  text-transform: uppercase; /* affects Latin only */
  color: color-mix(in srgb, var(--w-text, var(--text)) 62%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.w-playlist-row {
  flex: 1 1 auto;
  min-height: 34px;
  display: flex;
  gap: 6px;
}
.w-playlist-btn {
  flex: 1 1 0;
  min-width: 40px;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 3px 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  background: linear-gradient(180deg, var(--surface3), var(--surface2));
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
  overflow: hidden;
}
.w-playlist-btn:hover { border-color: #4d6175; background: linear-gradient(180deg, #33404c, var(--surface3)); }
.w-playlist-btn:active { transform: translateY(1px); }
.w-playlist-glyph { flex: none; font-size: 11px; line-height: 1; }
.w-playlist-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.5; /* Thai-safe */
}
/* Start lights from state playList — class "on", deliberately NOT "lit":
   .widget:has(.lit) (section 13) would glow the entire widget. */
.w-playlist-start.on {
  background: color-mix(in srgb, var(--good) 30%, var(--surface2));
  border-color: color-mix(in srgb, var(--good) 60%, var(--border));
  box-shadow: 0 0 10px color-mix(in srgb, var(--good) 30%, transparent);
}

@media (pointer: coarse) {
  .w-playlist-row { min-height: 40px; }
}


/* --------------------------------------------------------------------------
   16 · Container widget + widget templates (container.js / palette.js /
        properties.js template prompt)
   -------------------------------------------------------------------------- */

/* ---- container (widgets/container.js): labeled group frame ---- */
/* Weaker than region (region = 45% bg mix) and dashed, so it reads as a
   grouping frame, not a surface. Sits above regions, below normal widgets. */
.widget:has(.w-container) {
  background: color-mix(in srgb, var(--w-bg, var(--surface2)) 20%, transparent);
  border: 1px dashed color-mix(in srgb, var(--w-border, var(--border)) 80%, transparent);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: none;
}
/* The title chip already shows widget.name — hide the chrome caption. */
.widget:has(.w-container) > .widget-caption { display: none; }
.w-container { padding: 6px 8px; }
.w-container-title {
  display: inline-block;
  max-width: 100%;
  padding: 2px 9px;
  background: color-mix(in srgb, var(--w-bg, var(--surface2)) 85%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--w-border, var(--border)) 70%, transparent);
  border-radius: 6px;
  color: var(--w-text, var(--text));
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5; /* Thai-safe */
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- palette: saved templates section (palette.js) ---- */
.palette-templates {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  margin-top: 2px;
  border-top: 1px solid var(--border);
}
.palette-templates-head {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  line-height: 1.4;
  color: var(--text-dim);
}
.palette-templates-empty {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.55; /* Thai-safe */
  opacity: 0.8;
}
.tmpl-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}
.tmpl-add {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: start;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.tmpl-add:hover {
  background: var(--surface3);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  transform: translateX(2px);
}
.tmpl-add:active { transform: translateX(2px) scale(0.985); }
.tmpl-del {
  flex: none;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.tmpl-del:hover {
  background: color-mix(in srgb, var(--bad) 18%, var(--surface2));
  border-color: color-mix(in srgb, var(--bad) 60%, var(--border));
  color: var(--text);
}

/* ---- template name prompt (properties.js modal) ---- */
.tmpl-name-input {
  display: block;
  width: 100%;
  min-height: 40px;
  font-size: 14px;
  line-height: 1.5; /* Thai-safe */
}

/* --------------------------------------------------------------------------
   18 · External data + MIDI (widgets/externaldata.js / widgets/midi.js)
   -------------------------------------------------------------------------- */

/* ---- externaldata (widgets/externaldata.js) ---- */
.w-extdata { display: flex; flex-direction: column; }
.w-extdata-head {
  flex: none;
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px 3px 10px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.06em;
  text-transform: uppercase; /* affects Latin only */
  color: var(--text-dim);
  border-bottom: 1px solid var(--w-border, var(--border));
}
.w-extdata-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #5a6772; /* off */
  transition: background 0.15s, box-shadow 0.15s;
}
.w-extdata-dot.loading {
  background: var(--accent);
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 60%, transparent);
}
.w-extdata-dot.ok {
  background: var(--good);
  box-shadow: 0 0 8px color-mix(in srgb, var(--good) 55%, transparent);
}
.w-extdata-dot.error {
  background: var(--bad);
  box-shadow: 0 0 8px color-mix(in srgb, var(--bad) 60%, transparent);
}
.w-extdata-title {
  flex: none;
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.w-extdata-count {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: end;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
}
.w-extdata-refresh {
  flex: none;
  width: 28px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  transition: color 0.12s, border-color 0.12s;
}
.w-extdata-refresh:hover { color: var(--text); border-color: #4d6175; }
.w-extdata-refresh:disabled { opacity: 0.5; }
.w-extdata-refresh.busy { animation: extdata-spin 0.9s linear infinite; }
@keyframes extdata-spin { to { transform: rotate(360deg); } }
/* Compact data table in a scroll well; sticky header row */
.w-extdata-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--field-bg);
}
.w-extdata-table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 12px;
  line-height: 1.45; /* Thai-safe */
}
.w-extdata-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px 9px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.05em;
  text-align: start;
  white-space: nowrap;
}
.w-extdata-table td {
  padding: 3px 9px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.w-extdata-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
.w-extdata-table td.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: end;
}
.w-extdata-empty {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 8px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.05em;
  text-align: center;
}
.w-extdata-error {
  flex: none;
  max-height: 3em;
  overflow: hidden;
  padding: 3px 10px 4px;
  border-top: 1px solid color-mix(in srgb, var(--bad) 45%, var(--border));
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: color-mix(in srgb, var(--bad) 75%, white);
  font-size: 11px;
  line-height: 1.4;
}

/* ---- midi (widgets/midi.js): MIDI mapping surface ---- */
.w-midi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  overflow: hidden;
  font-size: 12px;
}
.w-midi-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}
.w-midi-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
}
.w-midi-dot.good {
  background: var(--good);
  box-shadow: 0 0 8px color-mix(in srgb, var(--good) 55%, transparent);
}
.w-midi-dot.warn { background: var(--warn); }
.w-midi-dot.bad { background: var(--bad); }
.w-midi-status {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.45; /* Thai upper vowels + descenders */
  color: var(--text-dim);
}
.w-midi-connect { flex: none; }
.w-midi-device-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.w-midi-device-label {
  flex: none;
  color: var(--text-dim);
  line-height: 1.45;
}
.w-midi-device { flex: 1 1 auto; min-width: 0; }
.w-midi-maps-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.w-midi-maps-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.07em;
  text-transform: uppercase; /* affects Latin only */
  color: color-mix(in srgb, var(--w-text, var(--text)) 62%, transparent);
}
.w-midi-maps {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
}
.w-midi-row {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--field-bg) 55%, transparent);
  border: 1px solid var(--border);
  border-radius: 7px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
/* Activity flash: an incoming message matched this row's filter */
.w-midi-row.hit {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--field-bg));
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 35%, transparent);
}
.w-midi-row select,
.w-midi-row input[type="number"] { min-height: 34px; }
.w-midi-kind { flex: 0 1 auto; }
.w-midi-ch { flex: none; width: 74px; }
.w-midi-num { flex: none; width: 64px; }
.w-midi-target { flex: 1 1 120px; min-width: 0; }
.w-midi-pick { flex: 1 1 140px; min-width: 0; }
.w-midi-pick select,
.w-midi-pick input { width: 100%; min-height: 34px; }
.w-midi-learn {
  flex: none;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.w-midi-learn.armed {
  color: #fff;
  background: color-mix(in srgb, var(--accent) 55%, var(--surface2));
  border-color: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 40%, transparent);
  animation: midi-learn-pulse 1.1s ease-in-out infinite;
}
@keyframes midi-learn-pulse {
  50% { box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 70%, transparent); }
}
.w-midi-rm { flex: none; }
.w-midi-last {
  flex: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 1.5; /* Thai fallback face in the mono stack */
  color: var(--text-dim);
}

/* externaldata + midi touch additions (companion to the section 15
   `@media (pointer: coarse)` block) */
@media (pointer: coarse) {
  .w-extdata-head { min-height: 40px; }
  .w-extdata-refresh { width: 40px; height: 34px; }
  .w-midi-row select,
  .w-midi-row input[type="number"],
  .w-midi-pick select,
  .w-midi-pick input { min-height: 40px; }
  .w-midi-connect, .w-midi-learn, .w-midi-rm { min-height: 40px; }
}

/* --------------------------------------------------------------------------
   19 · Cloud / account (SPEC section 15)
   -------------------------------------------------------------------------- */

/* Top-bar account button (person glyph; accent dot when signed in) */
.acct-btn {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.acct-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.4);
  border-color: #465665;
}
.acct-btn.signed-in {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}
.acct-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #171d23; /* cut-out ring against the top-bar gradient */
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 70%, transparent);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s, transform 0.15s;
}
.acct-btn.signed-in .acct-dot { opacity: 1; transform: none; }

/* ---- Avatars (top-bar button + account popover header) ---- */
.avatar {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface3);
  color: inherit;
}
.acct-avatar {
  width: 26px;
  height: 26px;
}
.avatar.has-photo,
.avatar.has-initial {
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar.has-initial {
  /* stable per-user color from --avatar-hue (set inline by renderAvatar) */
  background: linear-gradient(
    180deg,
    hsl(var(--avatar-hue, 210) 55% 46%),
    hsl(var(--avatar-hue, 210) 60% 34%)
  );
}
.avatar-initial {
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  font-size: 13px;
}
.acct-avatar .avatar-initial { font-size: 12.5px; }

/* Popover identity header */
.account-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 4px;
}
.account-avatar {
  flex: none;
  width: 44px;
  height: 44px;
}
.account-avatar .avatar-initial { font-size: 19px; }
.account-idbox {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.account-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5; /* Thai-safe */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-head .account-user {
  padding: 0;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Account popover (mirrors the settings-popover conventions) */
.account-pop { width: 290px; }
.account-pop .pop-field input { min-height: 40px; }
.account-form[aria-busy="true"] { opacity: 0.65; pointer-events: none; }
.account-actions {
  display: flex;
  gap: 8px;
  padding: 8px 10px 6px;
}
.account-actions .btn { flex: 1 1 0; min-height: 40px; }
.account-error {
  margin: 4px 10px 2px;
  font-size: 12.5px;
  line-height: 1.6; /* Thai-safe */
  color: var(--bad);
  overflow-wrap: anywhere;
}
/* Forgot password */
.account-forgot {
  display: block;
  margin: -2px 10px 2px auto;
  padding: 2px 0;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--accent);
}
.account-forgot:hover { text-decoration: underline; }
.account-reset-hint,
.account-reset-note {
  margin: 2px 10px 6px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
}
.account-reset-sent {
  margin: 4px 10px 6px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--good) 45%, transparent);
  background: color-mix(in srgb, var(--good) 10%, transparent);
}
.account-reset-sent-msg { font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
/* Google sign-in block (GIS renders its own button into .account-google-btn) */
.account-google {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 10px 4px;
}
.account-google-btn {
  display: flex;
  justify-content: center;
  min-height: 40px;
  color-scheme: light; /* GIS button renders best on its own light surface */
}
/* Native desktop Google button — custom & app-styled (matches the app font,
   which GIS's iframe button can't). Opens the real browser to sign in. */
.account-google-native {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
}
.account-google-native .g-logo {
  display: inline-flex;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 4px;
  padding: 2px;
  box-sizing: border-box;
  flex: 0 0 auto;
}
.account-google-native .g-logo svg { width: 100%; height: 100%; display: block; }
.account-google-wait {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 2px 0;
}
.account-google-wait-msg {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: center;
}
.account-google-cancel { min-height: 34px; }
.account-or {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 12px 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.account-or::before,
.account-or::after {
  content: '';
  flex: 1 1 auto;
  height: 1px;
  background: var(--border);
}

.account-user {
  padding: 8px 10px 0;
  font-weight: 700;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
/* Unverified password account: notice + "I've verified" / "Resend" */
.account-verify {
  margin: 6px 10px 6px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
}
.account-verify-msg { font-size: 12.5px; line-height: 1.65; overflow-wrap: anywhere; }
.account-verify-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.account-verify-status { margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--text-dim); overflow-wrap: anywhere; }
.account-verify-status.ok { color: var(--good); }
.account-verify-status.warn { color: var(--warn); }
.account-verify-status.error { color: var(--bad); }
.account-verified {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--good);
}
.account-meta {
  padding: 2px 10px 4px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}
.account-signout {
  margin: 8px 10px 6px;
  width: calc(100% - 20px);
  min-height: 40px;
}

/* Cloud section of the composition menu */
.cloud-row .menu-item { min-height: 40px; }
.cloud-badge {
  flex: none;
  margin-inline-start: 4px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.5; /* Thai-safe for the th badge labels */
  white-space: nowrap;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px;
}
.cloud-badge.both {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
}
.cloud-badge.local {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

/* Touch targets (SPEC section 8: min 40px) */
@media (pointer: coarse) {
  .acct-btn { width: 40px; height: 40px; }
  .account-actions .btn { min-height: 44px; }
  .cloud-row .menu-x { width: 40px; height: 40px; }
}

/* --------------------------------------------------------------------------
   21 · Groups UI (SPEC section 16.4)
   -------------------------------------------------------------------------- */

/* ---- Account popover: "กลุ่มของฉัน" button + pending-invite badge ---- */
.account-groups {
  position: relative;
  margin: 8px 10px 0;
  width: calc(100% - 20px);
  min-height: 40px;
  justify-content: center;
  gap: 8px;
}
.account-groups-label { line-height: 1.5; /* Thai-safe */ }
.account-invite-badge {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  background: var(--bad);
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* ---- Groups modal ---- */
.groups-modal { width: min(560px, 100%); }
.groups-modal .groups-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.5; /* Thai-safe */
}
.groups-body { padding: 12px 14px 16px; }

.groups-section-title {
  padding: 14px 4px 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
.groups-body > .groups-section-title:first-child { padding-top: 4px; }

.groups-error {
  margin: 6px 4px 2px;
  font-size: 12.5px;
  line-height: 1.6; /* Thai-safe */
  color: var(--bad);
  overflow-wrap: anywhere;
}

/* Busy: rows/forms dim + freeze while their request is in flight */
.groups-modal [aria-busy="true"] { opacity: 0.6; pointer-events: none; }

/* ---- Rows (my groups / invites) ---- */
.groups-list { display: flex; flex-direction: column; gap: 2px; }
.groups-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text);
  text-align: start;
  transition: background 0.12s;
}
button.groups-row:hover { background: rgba(255, 255, 255, 0.06); }
.groups-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.groups-invite-row .groups-row-main,
.groups-sent-invite-row .groups-row-main {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.groups-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  line-height: 1.5; /* Thai-safe */
}
.groups-row-meta {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: nowrap;
}
.groups-row-chevron {
  flex: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-dim);
}
.groups-invite-btn { flex: none; min-height: 36px; }
.groups-row-error { margin-top: 0; }

/* ---- Role badges (TH labels) ---- */
.group-role-badge {
  flex: none;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.5; /* Thai-safe */
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid transparent;
}
.group-role-badge.role-owner {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
}
.group-role-badge.role-admin {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.group-role-badge.role-editor {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
}
.group-role-badge.role-viewer {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

/* ---- Create-group form ---- */
.groups-create {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  padding: 2px 4px;
}
.groups-create input { flex: 1 1 auto; min-height: 40px; }
.groups-create .btn { flex: none; min-height: 40px; }

/* ---- Detail view ---- */
.groups-detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}
.groups-back { min-height: 36px; }
.groups-detail-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.groups-members { display: flex; flex-direction: column; gap: 2px; }
.groups-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 5px 8px;
  border-radius: 8px;
}
.groups-member-row:hover { background: rgba(255, 255, 255, 0.04); }
.groups-member-avatar {
  flex: none;
  width: 30px;
  height: 30px;
}
.groups-member-avatar .avatar-initial { font-size: 13.5px; }
.groups-member-id {
  flex: 1 1 auto;
  min-width: 0;
}
.groups-member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.5; /* Thai-safe */
}
.groups-member-you { color: var(--text-dim); font-size: 12px; }
.groups-role-select {
  flex: none;
  width: 118px;
  min-height: 36px;
  font-size: 12.5px;
}
.groups-member-rm { flex: none; width: 32px; height: 32px; }

/* ---- Invite-by-email row ---- */
.groups-invite-form {
  display: flex;
  gap: 6px;
  padding: 2px 4px;
}
.groups-invite-form input { flex: 1 1 auto; min-width: 0; min-height: 40px; }
.groups-invite-form .groups-role-select { min-height: 40px; }
.groups-invite-form .btn { flex: none; min-height: 40px; }

.groups-group-invites { display: flex; flex-direction: column; gap: 2px; }
.groups-sent-invite-row { min-height: 40px; }
.groups-sent-invite-row .groups-row-name { font-weight: 500; font-size: 13px; }

/* ---- Leave / delete ---- */
.groups-danger-zone {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.groups-danger-btn { flex: 1 1 0; min-height: 40px; }

/* ---- Comp-menu group sections (cloud/sync.js, SPEC 16.4) ---- */
.cloud-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 4px;
}
.cloud-group-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.5; /* Thai-safe */
}
.cloud-group-push {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.cloud-group-push:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.cloud-group-push:disabled { opacity: 0.5; pointer-events: none; }
.cloud-group-list .menu-empty { padding-block: 6px; }

/* ---- Touch targets (SPEC section 8: min 40px) ---- */
@media (pointer: coarse) {
  .groups-row { min-height: 48px; }
  .groups-member-row { min-height: 48px; }
  .groups-member-rm { width: 40px; height: 40px; }
  .groups-invite-btn { min-height: 40px; }
  .groups-role-select { min-height: 40px; }
  .groups-back { min-height: 40px; }
  .cloud-group-push { width: 40px; height: 34px; }
  .groups-modal .modal-close { min-width: 40px; min-height: 40px; }
}


/* --------------------------------------------------------------------------
   22 - Hosted cloud-mode banner (main.js detectHostedMode)
   -------------------------------------------------------------------------- */
.hosted-banner {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  font-size: 12.5px;
  line-height: 1.55; /* Thai-safe */
  color: var(--text);
}
.hosted-banner-text { min-width: 0; }
.hosted-banner-link {
  flex: none;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
}
.hosted-banner-link:hover { border-bottom-color: var(--accent); }
.hosted-banner-close {
  flex: none;
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.hosted-banner-close:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }

/* ==========================================================================
   Cloud Data (per-user datasets) — properties picker + manager modal
   ========================================================================== */
.cloud-dataset-field .field-hint { color: var(--text-dim); font-size: 12px; }
.cloud-ds-row { display: flex; gap: 6px; align-items: center; }
.cloud-ds-select {
  flex: 1 1 auto; min-width: 0; height: 30px; padding: 0 8px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font: inherit;
}
.cloud-ds-manage { flex: 0 0 auto; }

.cloud-modal-overlay {
  position: fixed; inset: 0; z-index: 4000;
  background: rgba(6, 10, 14, 0.62);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  opacity: 0; transition: opacity 0.14s;
}
.cloud-modal-overlay.open { opacity: 1; }
.cloud-modal {
  width: min(880px, 96vw); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-pop); overflow: hidden;
}
.cloud-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.cloud-modal-title { margin: 0; font-size: 16px; font-weight: 700; }
.cloud-modal-x {
  border: 0; background: none; color: var(--text-dim); font-size: 18px;
  cursor: pointer; width: 30px; height: 30px; border-radius: 8px;
}
.cloud-modal-x:hover { background: var(--surface2); color: var(--text); }
.cloud-modal-body { padding: 16px 18px; overflow: auto; }

.cloud-modal input[type="text"], .cloud-modal select, .cloud-modal textarea {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; padding: 6px 9px;
}
.cloud-modal input[type="text"]:focus, .cloud-modal select:focus, .cloud-modal textarea:focus {
  outline: none; border-color: var(--accent);
}

.cloud-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.cloud-hint, .cloud-loading, .cloud-empty { color: var(--text-dim); font-size: 13px; line-height: 1.6; }
.cloud-empty { padding: 24px; text-align: center; }

.cloud-ds-list { display: flex; flex-direction: column; gap: 8px; }
.cloud-ds-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2);
}
.cloud-ds-name { font-weight: 600; }
.cloud-ds-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.cloud-ds-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.cloud-editor { display: flex; flex-direction: column; gap: 10px; }
.cloud-name-input { flex: 1 1 auto; height: 38px; font-size: 15px; font-weight: 600; }
.cloud-sec-title { font-size: 12px; font-weight: 700; color: var(--text-dim); letter-spacing: 0.04em; margin-top: 4px; }
.cloud-cols { display: flex; flex-direction: column; gap: 6px; }
.cloud-col-item {
  display: flex; gap: 6px; align-items: center;
  padding: 7px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2);
}
.cloud-col-label { flex: 1 1 auto; height: 32px; }
.cloud-col-type { flex: 0 0 140px; height: 32px; }
.cloud-col-del, .cloud-row-del {
  border: 0; background: none; color: var(--text-dim); cursor: pointer;
  width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; transition: background .12s, color .12s;
}
.cloud-col-del:hover, .cloud-row-del:hover { background: var(--bad); color: #fff; }
.cloud-add-col { align-self: flex-start; border-style: dashed; color: var(--text-dim); }
.cloud-add-col:hover { color: var(--text); border-color: var(--accent); }
.cloud-modal .btn { min-height: 32px; }
.cloud-modal .btn-sm { min-height: 30px; padding: 5px 12px; font-size: 12.5px; }

.cloud-grid-scroll { overflow: auto; max-height: 42vh; border: 1px solid var(--border); border-radius: var(--radius); }
.cloud-grid { border-collapse: collapse; width: 100%; }
.cloud-grid th {
  position: sticky; top: 0; z-index: 1; background: var(--surface2); text-align: left;
  padding: 7px 9px; font-size: 12px; font-weight: 600; color: var(--text-dim);
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); white-space: nowrap;
}
.cloud-grid td { padding: 0; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.cloud-grid tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.cloud-cell {
  width: 100%; min-width: 96px; height: 30px; border: 0 !important;
  background: transparent !important; padding: 5px 8px !important; color: var(--text);
}
.cloud-cell:focus { background: color-mix(in srgb, var(--accent) 15%, transparent) !important; box-shadow: none !important; }
.cloud-grid-x { width: 34px; text-align: center; }

.cloud-editor-actions {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--border);
}
.cloud-grow { flex: 1 1 auto; }

.cloud-sub-overlay {
  position: absolute; inset: 0; z-index: 10; background: rgba(6, 10, 14, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.cloud-sub-card {
  width: min(560px, 94%); max-height: 84%; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-pop); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.cloud-sub-title { margin: 0; font-size: 15px; font-weight: 700; }
.cloud-paste-area { width: 100%; min-height: 140px; resize: vertical; font-family: ui-monospace, monospace; font-size: 12.5px; }
.cloud-paste-preview { display: flex; flex-direction: column; gap: 6px; }
.cloud-detect-cols { display: flex; flex-wrap: wrap; gap: 5px; }
.cloud-detect-chip { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); }
.cloud-sub-actions { display: flex; justify-content: flex-end; gap: 8px; }

.cloud-modal-overlay { position: fixed; }

/* Settings AI key hint + "Ask AI" properties field */
.pop-hint { padding: 2px 12px 6px; font-size: 11.5px; line-height: 1.55; color: var(--text-dim); }
.pop-field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pop-field-head > span { font-size: 12px; color: var(--text-dim); }
.pop-link {
  background: none; border: 0; padding: 0; cursor: pointer; white-space: nowrap;
  color: var(--accent); font: inherit; font-size: 11.5px; font-weight: 600;
}
.pop-link:hover { text-decoration: underline; }
.pop-ok { color: var(--good); font-weight: 600; }
.ai-query-field { display: flex; flex-direction: column; gap: 6px; }
.ai-q-row { display: flex; gap: 6px; }
.ai-q-input {
  flex: 1 1 auto; min-width: 0; height: 30px; padding: 0 8px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font: inherit;
}
.ai-q-input:focus { outline: none; border-color: var(--accent); }
.ai-q-ask { flex: 0 0 auto; }
.ai-q-status { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
.ai-q-status:empty { display: none; }
.ai-q-spec {
  font-size: 11.5px; color: var(--accent); line-height: 1.5;
  overflow-wrap: anywhere; padding: 3px 7px;
  background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px;
}
.ai-q-clear { align-self: flex-start; }

/* Remote control (RTDB relay) modal */
.remote-modal { max-width: 560px; }
.remote-sec { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.remote-intro {
  margin: 2px 0 12px; padding: 9px 11px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--text); font-size: 12.5px; line-height: 1.55;
}
.remote-sec-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: -2px 0 4px; }
.remote-sep { margin: 16px 0; height: 1px; background: var(--border); border: 0; }
.remote-row { display: flex; gap: 8px; align-items: center; }
.remote-name { flex: 1 1 auto; height: 34px; }
.remote-status { font-size: 12.5px; line-height: 1.5; }
.remote-status.on { color: var(--good); font-weight: 600; }
.remote-status.off { color: var(--text-dim); }
.remote-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); flex: 0 0 auto; display: inline-block; }
.remote-dot.on { background: var(--good); box-shadow: 0 0 8px color-mix(in srgb, var(--good) 60%, transparent); }
.remote-connected {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--good); border-radius: var(--radius);
  background: color-mix(in srgb, var(--good) 10%, transparent);
}
.remote-conn-label { flex: 1 1 auto; font-weight: 600; }
.remote-list { display: flex; flex-direction: column; gap: 6px; }
.remote-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2);
}
.remote-item-meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.remote-item-name { font-weight: 500; overflow-wrap: anywhere; }
.remote-badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--border); color: var(--text-dim); }
/* Cross-user sharing (requests / grants / shared inbox) */
.remote-sub { font-size: 12px; font-weight: 600; color: var(--text-dim); margin: 12px 0 4px; }
.remote-share { margin-top: 10px; }
.remote-req { display: flex; flex-direction: column; gap: 6px; }
.remote-req-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2); flex-wrap: wrap; }
.remote-req-main { min-width: 0; }
.remote-req-name { font-weight: 500; overflow-wrap: anywhere; }
.remote-req-email { font-size: 11.5px; color: var(--text-dim); overflow-wrap: anywhere; }
.remote-req-actions { display: flex; align-items: center; gap: 6px; }
.remote-grants { display: flex; flex-direction: column; gap: 8px; }
.remote-station-sel, .remote-group-sel { height: 32px; max-width: 220px; }
.remote-via { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--surface2); color: var(--text-dim); }
.remote-share-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.remote-share-label { font-size: 12.5px; color: var(--text-dim); }
.remote-shared-owner { font-size: 11.5px; color: var(--text-dim); overflow-wrap: anywhere; }
.remote-shared-rm { margin-left: 4px; }