/* Components: buttons, inputs, sliders, cards, tabs. Uses ONLY theme variables,
   so restyling = editing a theme file. Page layout is in layout.css. */
* { box-sizing: border-box; }
html { font-size: calc(var(--fs) * var(--ui-scale, 1)); }
/* thin, quiet scrollbars everywhere */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-dim); }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
body { margin: 0; background: var(--bg-image, none) fixed, var(--bg); color: var(--text); font: 1rem/1.3 var(--font); }
button, select, input, textarea { font: inherit; color: var(--text); }
[hidden] { display: none !important; }

/* ── controls ── */
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0 .6em; height: var(--row-h); cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.on, button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
button.ghost:hover { color: var(--text); border-color: var(--line); }
button.danger:hover { border-color: var(--err); color: var(--err); }
button.icon { padding: 0; width: var(--row-h); flex: none; }

select, input[type=text], input[type=number] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  height: var(--row-h); padding: 0 .35em; min-width: 0;
}
select { padding-right: 0; }
input[type=checkbox] { accent-color: var(--accent); width: 1em; height: 1em; margin: 0; flex: none; }

/* Slider: thin track + a value you can type into. */
.slider { display: flex; gap: .4em; align-items: center; min-width: 0; position: relative; }
/* range styling: ui/slider.css */
input.val {
  width: 3.8em; flex: none; text-align: right; background: transparent; border-color: transparent;
  color: var(--text-dim); font-variant-numeric: tabular-nums; padding: 0 .2em;
}
input.val:hover, input.val:focus { border-color: var(--line); color: var(--text); outline: none; }

textarea.code {
  width: 100%; min-height: 12em; resize: vertical; tab-size: 2;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  font: .95rem/1.45 var(--mono); padding: .5em; white-space: pre; overflow: auto;
}

/* ── tabs ── */
.tabs { display: flex; flex-direction: column; min-height: 0; }
.tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 var(--gap); flex: none; }
.tab-bar .tab {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent;
  color: var(--text-dim); height: calc(var(--row-h) + 6px); padding: 0 .8em;
}
.tab-bar .tab:hover { color: var(--text); }
.tab-bar .tab.on { color: var(--text); border-bottom-color: var(--accent); background: transparent; }
.tab-body { display: flex; flex-direction: column; gap: var(--gap); padding: var(--gap); overflow: auto; min-height: 0; }

/* Collapsible blocks (<details>): no JS. */
details.panel, details.sub { border-radius: var(--radius); }
details.panel { background: var(--panel); border: 1px solid var(--line); }
details > summary {
  cursor: pointer; list-style: none; display: flex; gap: .4em; align-items: center;
  color: var(--text-dim); user-select: none;
}
details > summary::before { content: "▸"; font-size: .8em; }
details[open] > summary::before { content: "▾"; }
details.panel > summary { padding: .35em .6em; font-weight: 600; color: var(--text); }
details.panel > .body { padding: 0 .6em .6em; display: flex; flex-direction: column; gap: var(--gap); }
details.sub > summary { padding: .15em 0; font-size: .92em; }
details.sub[open] { padding-bottom: .3em; }

/* ── rows, cards, params ── */
.row { display: flex; gap: .4em; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.label { color: var(--text-dim); font-size: .92em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { color: var(--text-dim); font-size: .88em; }
.err { color: var(--err); font: .9em var(--mono); white-space: pre-wrap; }
.ok { color: var(--ok); }
.sep { flex: 1; }
.badge { font-size: .78em; padding: .05em .45em; border-radius: var(--radius); background: var(--line); color: var(--text-dim); white-space: nowrap; }
.badge.lock { background: var(--warn); color: var(--bg); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: var(--radius); padding: .3em .45em; display: flex; flex-direction: column; gap: .25em;
}
.card.sel { border-left-color: var(--accent); }
.card.off { opacity: .55; }
.card.locked { border-left-color: var(--warn); }
.card > .head { display: flex; gap: .35em; align-items: center; min-width: 0; }
.card > .head .name { flex: 1 1 6em; min-width: 3em; background: transparent; border-color: transparent; font-weight: 600; }
.card > .head .name:hover, .card > .head .name:focus { border-color: var(--line); }
.card > .head .mini { flex: 0 1 6em; min-width: 3em; }
.card > .head .mini input.val { display: none; }       /* value shows as a tooltip */
.card .inner { display: flex; flex-direction: column; gap: .2em; padding: .2em 0 .1em .2em; }
.card.locked .inner, .card.locked .head .mini, .card.locked .head select { pointer-events: none; opacity: .5; }

.param { display: grid; grid-template-columns: 6em minmax(0, 1fr) auto; gap: .35em; align-items: center; min-height: var(--row-h); }
.param.modrow { grid-template-columns: 6em minmax(0, 1fr) minmax(0, 1fr); padding-left: .8em; }
.param select { max-width: 6.5em; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .2em .8em; }
.grid2 .param { grid-template-columns: 4.8em minmax(0, 1fr) auto; }
.meters { display: flex; gap: .5em; align-items: flex-end; height: 3.2em; }
.meters > div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .15em; height: 100%; }
.meters .bar { flex: 1; width: 100%; background: var(--panel-2); border-radius: var(--radius); position: relative; overflow: hidden; }
.meters .bar > i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); height: 0; }
.meters span { font-size: .75em; color: var(--text-dim); }
.learning { outline: 2px dashed var(--accent-2); }
.qr { background: #fff; padding: 6px; border-radius: var(--radius); width: max-content; }
.qr svg { display: block; width: 9em; height: 9em; }
.dot { width: .6em; height: .6em; border-radius: 50%; background: var(--text-dim); display: inline-block; }
.dot.on { background: var(--ok); } .dot.connecting { background: var(--warn); } .dot.off { background: var(--err); }
.badge:empty { display: none; }

/* ── screens map (launcher + Screens tab) ── */
.screens { display: flex; flex-direction: column; gap: var(--gap); }
.screens-map { position: relative; width: 100%; min-height: 8em; }
.monitor {
  position: absolute; box-sizing: border-box; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); padding: .4em; display: flex; flex-direction: column; gap: .3em; overflow: hidden;
  outline: 3px solid var(--bg); outline-offset: -1px;
}
.monitor.on { border-color: var(--ok); }
.monitor.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--panel-2)); }
.monitor .mon-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.monitor .mon-out { font-size: 2em; font-weight: 700; color: var(--accent); line-height: 1; flex: 1; display: flex; align-items: center; justify-content: center; }
.chips { gap: .3em; }
.chip { background: var(--accent); color: var(--bg); border-radius: var(--radius); padding: .1em .7em; cursor: grab; user-select: none; font-weight: 600; }
.locked-lits { pointer-events: none; opacity: .5; }

/* code editor: ui/editor.css */

/* ── right-click menu (src/ui/contextMenu.js) ── */
.ctxmenu { position: fixed; z-index: 1000; min-width: 220px; background: var(--panel); border: 1px solid var(--line);
           border-radius: var(--radius); box-shadow: 0 10px 30px #000a; padding: .25em 0; font-size: .95rem; color: var(--text); }
.ctxmenu .item { display: grid; grid-template-columns: 1.2em 1fr auto; gap: .4em; align-items: center; padding: .3em .8em .3em .4em; cursor: pointer; position: relative; white-space: nowrap; }
.ctxmenu .item:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.ctxmenu .item.disabled { opacity: .4; cursor: default; }
.ctxmenu .item .check { color: var(--accent); }
.ctxmenu .item .hint { color: var(--text-dim); font-size: .85em; }
.ctxmenu .sep { height: 1px; background: var(--line); margin: .25em 0; }
.ctxmenu .title { padding: .35em .8em .2em; color: var(--text-dim); font-size: .8em; text-transform: uppercase; letter-spacing: .06em; }
.ctxmenu .slider-item { display: grid; grid-template-columns: 6em 1fr; gap: .4em; align-items: center; padding: .15em .8em; }
.ctxmenu .sub { display: none; position: absolute; top: -.25em; left: 100%; }
.card > .head .mini input.val, div.mini input.val { display: none; }
.monitor { isolation: isolate; }
.monitor canvas.thumb { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; opacity: .85; border-radius: var(--radius); }
.monitor .mon-name, .monitor .row { background: color-mix(in srgb, var(--panel) 80%, transparent); border-radius: var(--radius); padding: .1em .3em; width: fit-content; }
.monitor .mon-out { text-shadow: 0 1px 6px #000; }

/* ── chat (src/ui/chat.js) ── */
.chat { position: fixed; right: 12px; top: 44px; z-index: 900; width: min(360px, calc(100vw - 24px)); max-height: 70vh;
        background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: 0 10px 30px #000a;
        display: flex; flex-direction: column; gap: .4em; padding: .6em; }
.chat.inline { position: static; width: auto; max-height: 50vh; box-shadow: none; border-color: var(--line); }
.chat-list { overflow: auto; display: flex; flex-direction: column; gap: .35em; min-height: 6em; }
.chat .msg { background: var(--panel-2); border-radius: var(--radius); padding: .3em .5em; max-width: 90%; }
.chat .msg.me { align-self: flex-end; background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); }
.chat .msg .who { font-weight: 600; margin-right: .5em; }
.chat .msg .when { color: var(--text-dim); font-size: .8em; }
.chat .msg .text { white-space: pre-wrap; word-break: break-word; }

/* ── audio bands ── */
.band { display: flex; flex-direction: column; gap: .15em; padding: .3em 0; border-top: 1px solid var(--line); }
.band-name { width: 5em; flex: none; }
.hmeter { position: relative; flex: 1; height: .8em; background: var(--panel-2); border-radius: var(--radius); overflow: hidden; }
.hmeter > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); width: 0; }
.hmeter > i.raw { background: color-mix(in srgb, var(--text-dim) 35%, transparent); }
.hmeter > i.floor, .hmeter > i.ceil { width: 2px; background: var(--warn); }
.hmeter > i.ceil { background: var(--ok); }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px); background: var(--panel); color: var(--text);
         border: 1px solid var(--warn); padding: .5em 1em; z-index: 2000; opacity: 0; transition: .2s; pointer-events: none; font: 13px var(--font); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.tag { display: inline-flex; align-items: center; gap: .2em; font-size: .8em; padding: .05em .45em; border: 1px solid var(--line); background: var(--panel-2); color: var(--text-dim); white-space: nowrap; }
.tag.ok { color: var(--ok); }
.person { border: 1px solid var(--line); border-left: 3px solid var(--line); background: var(--panel); padding: .35em .5em; display: flex; flex-direction: column; gap: .3em; }
.person.me { border-left-color: var(--accent); }
.person.away { opacity: .55; }
.person select.addsel { max-width: 11em; font-size: .85em; height: calc(var(--row-h) - 4px); }
.card.noperm .inner, .card.noperm .head .mini, .card.noperm .head select { pointer-events: none; opacity: .45; }

/* ── + add picker / drop veil ── */
.picker { position: fixed; z-index: 1000; width: min(560px, calc(100vw - 16px)); max-height: 80vh; overflow: auto; background: var(--panel);
          border: 1px solid var(--accent); box-shadow: 0 14px 40px #000c; padding: .6em .7em .8em; display: flex; flex-direction: column; gap: .35em; }
.picker .psec { margin-top: .4em; font-size: .75em; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); }
.picker .pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 4px; }
.pcard { height: auto; display: flex; flex-direction: column; align-items: center; gap: .25em; padding: .55em .3em; background: var(--panel-2); border: 1px solid var(--line); }
.pcard:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel-2)); }
.pcard .picon { font-size: 1.35em; line-height: 1; color: var(--accent); }
.pcard .plabel { font-size: .82em; white-space: normal; text-align: center; line-height: 1.15; }
.drop-veil { position: fixed; inset: 0; z-index: 1500; display: none; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent);
             border: 3px dashed var(--accent); color: var(--text); font-size: 1.6em; font-weight: 700; pointer-events: none; }
.drop-veil.on { display: grid; }

/* ── camera calibration wizard ── */
.calib-modal { position: fixed; inset: 0; z-index: 1200; background: #000a; display: grid; place-items: center; }
.calib-box { width: min(700px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--accent); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.calib-view { width: 100%; height: auto; background: #000; cursor: crosshair; border: 1px solid var(--line); }
.calib-step { font-weight: 600; color: var(--accent); min-height: 1.3em; }
