:root {
  --bg: #17181c; --panel: #1f2026; --panel2: #26272f; --line: #33343e; --text: #e6e7eb; --muted: #9a9caa;
  --accent: #3b82f6; --accent2: #2563eb; --danger: #e5484d; --ok: #12b886; --warn: #f59f00;
  --canvas: #f3f4f6;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 13px; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--text); background: #15161a; border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=color] { padding: 1px 2px; height: 30px; width: 100%; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); }
a { color: #74a7ff; }
kbd { background: #2d2e38; border: 1px solid #44465a; border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: inherit; white-space: nowrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 11px; }

#app { display: grid; height: 100vh; grid-template-columns: 270px 1fr 300px; grid-template-rows: 46px 1fr auto 32px;
  grid-template-areas: "tb tb tb" "lib stage props" "lib drawer props" "lib pages props"; }

/* Toolbar */
#toolbar { grid-area: tb; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
#toolbar .brand { font-size: 16px; letter-spacing: .3px; margin-right: 4px; white-space: nowrap; }
#toolbar .brand b { color: var(--accent); }
#doc-name { width: 170px; background: transparent; border-color: transparent; font-weight: 600; }
#doc-name:hover { border-color: var(--line); }
.tgroup { display: flex; gap: 2px; padding-left: 8px; border-left: 1px solid var(--line); }
#toolbar button { background: transparent; border: 1px solid transparent; border-radius: 5px; padding: 5px 9px; cursor: pointer; white-space: nowrap; }
#toolbar button:hover { background: var(--panel2); border-color: var(--line); }
#toolbar button.active { background: #1e3a6b; border-color: var(--accent); }
#toolbar button:disabled { opacity: .35; cursor: default; }
#toolbar button.accent { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }
#toolbar button.accent:hover { background: var(--accent); }
#zoom-label { min-width: 54px; }

/* Bibliotheek */
#library { grid-area: lib; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.lib-top { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.lib-top input { flex: 1; }
#lib-list { overflow-y: auto; flex: 1; padding-bottom: 20px; }
.lib-cat { display: flex; align-items: center; gap: 6px; padding: 7px 10px 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.lib-cat:hover { color: var(--text); }
.lib-cat .chev { transition: transform .15s; font-size: 9px; }
.lib-cat.collapsed .chev { transform: rotate(-90deg); }
.lib-cat .dot { width: 8px; height: 8px; border-radius: 2px; }
.lib-cat .cnt { margin-left: auto; font-size: 10px; }
.lib-item { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 10px; cursor: grab; position: relative; border-left: 2px solid transparent; }
.lib-item:hover { background: var(--panel2); border-left-color: var(--accent); }
.lib-item .thumb { width: 34px; height: 26px; border-radius: 4px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: #fff; object-fit: contain; background: #fff; overflow: hidden; }
img.thumb { background: #fff; }
.lib-item .meta { min-width: 0; flex: 1; }
.lib-item .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .sub { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .badge { font-size: 9px; background: #3a2f12; color: #ffd43b; border-radius: 3px; padding: 0 4px; margin-left: 5px; }
.lib-item .acts { display: none; gap: 2px; }
.lib-item:hover .acts { display: flex; }
.lib-item .acts button { background: #33343e; border: 0; border-radius: 4px; width: 22px; height: 22px; cursor: pointer; font-size: 11px; }
.lib-item .acts button:hover { background: var(--accent); }
.empty { padding: 20px; color: var(--muted); }

/* Canvas */
#stage { grid-area: stage; position: relative; overflow: hidden; background-color: var(--canvas); min-width: 0; min-height: 0; }
#stage.grid { background-image:
  radial-gradient(circle, #c9ccd3 1px, transparent 1.2px),
  linear-gradient(#e2e4e9 1px, transparent 1px), linear-gradient(90deg, #e2e4e9 1px, transparent 1px); }
#canvas { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; touch-action: none; }
#canvas.space, #canvas.panning { cursor: grab; }
#canvas.panning { cursor: grabbing; }
#canvas[data-tool=text] { cursor: text; }
#canvas[data-tool=zone] { cursor: crosshair; }
#canvas .node { cursor: move; }
#canvas .zone { cursor: default; }
#canvas .zone .zhead, #canvas .zone .zborder { cursor: move; }
#canvas .port { cursor: crosshair; }
#canvas .port:hover circle, #canvas .port:hover rect:not(.phit) { stroke-width: 3; }
#canvas .cable, #canvas .clabel { cursor: pointer; }
#canvas .cable:hover path:nth-child(2) { stroke-width: 3; }
.inline-ed { position: absolute; z-index: 20; background: #fff; color: #111; border: 2px solid var(--accent); border-radius: 4px; padding: 4px 6px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }

/* Eigenschappen */
#props { grid-area: props; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
#props-body { padding: 4px 0 30px; }
.psec { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.psec h4, .dev-ed h4 { margin: 0 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 11px; color: var(--muted); }
.field small { color: #7d7f8c; font-size: 10.5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chk { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; cursor: pointer; }
.btn:hover { border-color: #555869; background: #2d2e38; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
.psec .btnrow { padding: 0; }
.ib { background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; padding: 2px 6px; color: var(--muted); }
.ib:hover { background: var(--panel2); color: var(--text); border-color: var(--line); }
.ib:disabled { opacity: .3; }
.ib.big { font-size: 16px; padding: 4px 0; }
.align { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.align .ib { border-color: var(--line); color: var(--text); }
.imgrow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.imgrow img { width: 60px; height: 40px; object-fit: contain; background: #fff; border-radius: 4px; }
.conn { background: #15161a; border-radius: 6px; padding: 8px; line-height: 1.5; }
.conn .arrow { color: var(--muted); }
.warn { background: #3b2a06; color: #ffc94d; border-radius: 6px; padding: 6px 8px; }
.swatches { display: flex; gap: 4px; align-items: center; }
.swatches .sw { width: 22px; height: 22px; border-radius: 4px; border: 2px solid transparent; cursor: pointer; }
.swatches .sw.on { border-color: #fff; }
.swatches input { width: 34px; }
.sigfilter { display: flex; flex-direction: column; gap: 1px; }
.sigrow { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; }
.sigrow.unused { opacity: .5; }
.sigrow .cnt { margin-left: auto; color: var(--muted); font-size: 11px; }
.swatch { display: inline-block; width: 22px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 4px; }

/* Poorten editor */
.ports-ed { display: flex; flex-direction: column; gap: 6px; }
.ptable { display: flex; flex-direction: column; gap: 3px; max-height: 360px; overflow-y: auto; }
.prow { display: grid; grid-template-columns: 1fr 54px 62px 50px 22px 22px; gap: 3px; align-items: center; }
.prow.used .pname { border-left: 3px solid var(--ok); }
.prow input, .prow select { padding: 3px 4px; font-size: 12px; }
.padd { display: grid; grid-template-columns: 44px 50px 66px 1fr; gap: 3px; }
.padd .btn { grid-column: 1 / -1; }
.padd input, .padd select { padding: 3px 4px; font-size: 12px; }

/* Lade */
#drawer { grid-area: drawer; background: var(--panel); border-top: 1px solid var(--line); height: 280px; display: flex; flex-direction: column; min-width: 0; }
#drawer[hidden], [hidden] { display: none !important; }
.d-head { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.d-head .tab { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 5px 8px; cursor: pointer; color: var(--muted); }
.d-head .tab.on { color: var(--text); border-bottom-color: var(--accent); }
.d-body { overflow: auto; flex: 1; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
table.grid th { position: sticky; top: 0; background: var(--panel2); text-align: left; padding: 5px 6px; font-weight: 600; color: var(--muted); }
table.grid td { padding: 2px 6px; border-bottom: 1px solid #2a2b33; white-space: nowrap; }
table.grid td.num { text-align: right; font-weight: 700; width: 60px; }
table.grid td input { background: transparent; border-color: transparent; padding: 2px 4px; width: 100%; min-width: 70px; }
table.grid td input:focus { background: #15161a; border-color: var(--accent); }
table.grid tr:hover td { background: #262833; cursor: pointer; }
table.grid tr.sel td { background: #1e3a6b; }
table.grid tr.mism td { color: #ffc94d; }
.cabsum { padding: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { background: var(--panel2); border-radius: 12px; padding: 2px 9px; }

/* Pagina's */
#pagebar { grid-area: pages; display: flex; align-items: stretch; background: var(--panel); border-top: 1px solid var(--line); padding: 0 6px; gap: 6px; min-width: 0; }
#pages { display: flex; gap: 2px; overflow-x: auto; }
.ptab { background: transparent; border: 0; border-top: 2px solid transparent; padding: 0 14px; cursor: pointer; color: var(--muted); white-space: nowrap; display: flex; align-items: center; user-select: none; }
.ptab:hover { color: var(--text); background: var(--panel2); }
.ptab.active { color: var(--text); border-top-color: var(--accent); background: var(--panel2); }
.ptab.add { font-size: 16px; padding: 0 10px; }
#status { align-self: center; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Context menu */
#ctx { position: fixed; z-index: 100; background: #2a2b33; border: 1px solid #40424f; border-radius: 7px; padding: 4px; min-width: 210px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
#ctx button { display: flex; width: 100%; justify-content: space-between; gap: 20px; background: transparent; border: 0; padding: 6px 10px; border-radius: 4px; cursor: pointer; text-align: left; }
#ctx button:hover { background: var(--accent2); }
#ctx hr { border: 0; border-top: 1px solid #40424f; margin: 4px 0; }

/* Modals */
.m-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: min(460px, 94vw); max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { width: min(860px, 96vw); }
.modal.qa { width: min(600px, 94vw); }
.m-head { display: flex; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.m-head h3 { margin: 0; font-size: 15px; flex: 1; }
.m-body { padding: 14px; overflow-y: auto; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
input.wide { width: 100%; font-size: 15px; padding: 9px 10px; }
.qa-list { max-height: 50vh; overflow-y: auto; margin: 8px 0; }
.qa-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 5px; cursor: pointer; }
.qa-item.on, .qa-item:hover { background: #1e3a6b; }
.qa-item .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.qa-port { margin-left: auto; font-size: 12px; color: #8fd3b6; white-space: nowrap; }
.dev-ed { display: flex; flex-direction: column; gap: 10px; }
.dev-cols { display: grid; grid-template-columns: 1fr 310px; gap: 16px; }
.dev-cols > div:first-child { display: flex; flex-direction: column; gap: 8px; }
.dev-prev { background: var(--canvas); border-radius: 8px; display: flex; align-items: flex-start; justify-content: center; padding: 10px; max-height: 340px; overflow: auto; }
.dev-ed .ptable { max-height: 300px; }
.help .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.help td { padding: 3px 6px; vertical-align: top; }
.help td:first-child { white-space: nowrap; }

/* Print dialoog */
.pp { display: grid; grid-template-columns: 1fr 380px; gap: 18px; }
.pp-opts { display: flex; flex-direction: column; gap: 10px; }
.seg { display: flex; flex-wrap: wrap; gap: 3px; }
.seg button { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 4px 9px; cursor: pointer; }
.seg button.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.pp-prev { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #111216; border-radius: 8px; padding: 12px; }
.pp-sheet { background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.5); display: flex; flex-direction: column; }
.pp-sheet .pt-draw { flex: 1; min-height: 0; }
.pp-sheet svg { width: 100%; height: 100%; }
.pp-tb { height: 9%; border-top: 1px solid #999; background: repeating-linear-gradient(90deg, #eee 0 30%, #fff 30% 32%); }

/* Toast */
#toast { position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%) translateY(20px); background: #2a2b33; border: 1px solid #44465a; padding: 8px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; z-index: 300; max-width: 80vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.ok { border-color: var(--ok); }
#toast.err { border-color: var(--danger); }
#toast.warn { border-color: var(--warn); }

/* Print */
#print-root { display: none; }
@media print {
  html, body { background: #fff !important; color: #000; overflow: visible !important; height: auto; }
  #app, #modal-root, #ctx, #toast { display: none !important; }
  #print-root { display: block; color: #000; font-family: "Segoe UI", system-ui, Arial, sans-serif; }
  .psheet { display: flex; flex-direction: column; page-break-after: always; break-after: page; overflow: hidden; }
  .psheet:last-child { page-break-after: auto; break-after: auto; }
  .pt-draw { flex: 1; min-height: 0; }
  .pt-draw svg { width: 100%; height: 100%; display: block; }
  .pt-foot { display: flex; gap: 10px; align-items: flex-end; border-top: 1.5px solid #222; padding-top: 2mm; }
  .pt-legend { flex: 1; display: flex; flex-wrap: wrap; gap: 1mm 4mm; font-size: 8pt; align-self: center; }
  .pt-legend span { display: inline-flex; align-items: center; gap: 1.5mm; }
  .pt-legend i { display: inline-block; width: 8mm; }
  .pt-tb { border-collapse: collapse; font-size: 8pt; min-width: 95mm; }
  .pt-tb td { border: 1px solid #333; padding: .6mm 1.5mm; }
  .pt-tb td.big { font-size: 11pt; font-weight: 700; }
  .plist { page-break-before: always; break-before: page; }
  .plist:first-child { page-break-before: auto; }
  .plist h2 { font-size: 13pt; margin: 0 0 3mm; }
  .plist table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
  .plist th { text-align: left; border-bottom: 1.5px solid #000; padding: 1mm; }
  .plist td { border-bottom: 1px solid #ccc; padding: .8mm 1mm; }
  .plist thead { display: table-header-group; }
  .plist tr { page-break-inside: avoid; }
  .plist .sw { display: inline-block; width: 6mm; border-top: 2.5px solid; vertical-align: middle; margin-right: 1.5mm; }
}

@media (max-width: 1000px) {
  #app { grid-template-columns: 220px 1fr 0; }
  #props { display: none; }
}

/* License gate */
#toolbar button.gate { border-radius: 14px; padding: 4px 11px; font-size: 12px; font-variant-numeric: tabular-nums; }
#toolbar button.gate.trial { background: #3a2f12; border-color: #6b5410; color: #ffd43b; }
#toolbar button.gate.full { background: #10301f; border-color: #1f6b43; color: #8ce0b4; }
#toolbar button.gate.readonly { background: #4a1517; border-color: #a3282d; color: #ffb3b5; }
#ro-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 15; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: #2a1214; border: 1px solid #a3282d; color: #ffd6d7; padding: 8px 12px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: calc(100% - 32px); }
#ro-banner a.btn { text-decoration: none; color: var(--text); }
.gate-msg { min-height: 20px; margin-top: 8px; color: var(--muted); }
.gate-msg.err { color: #ff8a8e; }
.cloud { display: flex; flex-direction: column; gap: 12px; }
.cloud-list { max-height: 45vh; overflow: auto; }
.cloud-acts { display: flex; gap: 4px; justify-content: flex-end; }
.cloud-save { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cloud-save input { flex: 1; min-width: 160px; }

/* Share links & sync */
#toolbar button.gate.share { background: #102a44; border-color: #1f5fa0; color: #9cc8ff; }
#share-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 15; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: #10233a; border: 1px solid #2c6bb0; color: #d6e8ff; padding: 7px 12px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: calc(100% - 32px); }
#share-banner.share-edit { background: #0f2a1d; border-color: #1f6b43; color: #cdeedd; }
#share-banner.share-gone { background: #2a1214; border-color: #a3282d; color: #ffd6d7; }
#share-banner a.btn { text-decoration: none; color: var(--text); }
#sync-status { align-self: center; font-size: 12px; white-space: nowrap; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; }
#sync-status.ok { color: #8ce0b4; }
#sync-status.busy { color: #9cc8ff; }
#sync-status.warn { color: #ffc94d; }
#sync-status.err { color: #ff8a8e; }
#sync-status.muted { color: var(--muted); }
.share-dlg { display: flex; flex-direction: column; gap: 10px; }
.share-dlg h4 { margin: 6px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.row-inline { display: flex; align-items: center; gap: 8px; }
.linkrow { display: flex; gap: 6px; }
.linkrow input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.share-item { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.share-ctl { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ok-msg { color: #8ce0b4; margin-bottom: 4px; }

/* Port editor: drag & drop + add row */
.prow { grid-template-columns: 14px 1fr 54px 62px 50px 22px; }
.phandle { cursor: grab; color: var(--muted); user-select: none; text-align: center; font-size: 13px; line-height: 1; touch-action: none; }
.phandle:hover { color: var(--text); }
.prow.dragging { opacity: .3; }
.prow-ghost { position: fixed; z-index: 500; pointer-events: none; opacity: .75; background: var(--panel2); border: 1px solid var(--accent); border-radius: 5px; padding: 2px; box-shadow: 0 8px 24px rgba(0,0,0,.45); display: grid; grid-template-columns: 14px 1fr 54px 62px 50px 22px; gap: 3px; align-items: center; }
.ptable { position: relative; }
.pdrop { position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 6px var(--accent); pointer-events: none; }
.pdrop.noop { opacity: .25; }
.padd { grid-template-columns: 44px 10px 50px 66px 1fr; align-items: center; }
.padd .times { color: var(--muted); text-align: center; }

/* Device sharing */
.ls-pick { max-height: 40vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; display: flex; flex-direction: column; gap: 2px; }
.ls-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.ls-row:hover { background: var(--panel2); }
.ls-thumb { width: 30px; height: 22px; border-radius: 3px; object-fit: contain; background: #fff; flex: none; display: inline-block; }
.ls-tag { margin-left: 8px; font-size: 10px; border-radius: 3px; padding: 0 5px; background: #3a2f12; color: #ffd43b; }
.ls-tag.new { background: #10301f; color: #8ce0b4; }

/* Library cloud sync status */
.lib-sync { padding: 6px 10px; font-size: 11.5px; border-top: 1px solid var(--line); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-sync.synced { color: #8ce0b4; }
.lib-sync.saving { color: #9cc8ff; }
.lib-sync.pending { color: #ffc94d; }
.lib-sync.error { color: #ff8a8e; }

/* Cloud space bar */
.quota { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
#lib-quota { padding: 0 10px 8px; }
.quota .qbar { flex: 1; min-width: 60px; height: 6px; border-radius: 3px; background: #2d2e38; overflow: hidden; }
.quota .qfill { height: 100%; background: var(--ok); border-radius: 3px; transition: width .3s; }
.quota.warn .qfill { background: var(--warn); }
.quota.warn span { color: #ffc94d; }
.quota.full .qfill { background: var(--danger); }
.quota.full span { color: #ff8a8e; }

/* Device icons */
.icon { display: inline-flex; vertical-align: middle; }
.lib-item .thumb .icon { display: flex; }
.icon-row { display: flex; gap: 6px; align-items: center; }
.icon-row select { flex: 1; }
.icon-grid { display: grid; grid-template-columns: repeat(8, 34px); gap: 3px; padding: 4px; }
#ctx .icon-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 5px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text); font-size: 16px; }
#ctx .icon-btn:hover { background: var(--accent2); }
#ctx .icon-btn.on { border-color: var(--accent); background: #1e3a6b; }

/* Library: brands, tags, about */
.lib-filters { display: flex; align-items: center; gap: 6px; padding: 4px 10px 6px; border-bottom: 1px solid var(--line); }
.lib-cat.static { cursor: default; }
.lib-brand { display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 22px; font-size: 12px; color: var(--text); cursor: pointer; user-select: none; }
.lib-brand:hover { background: var(--panel2); }
.lib-brand .chev { font-size: 9px; color: var(--muted); transition: transform .15s; }
.lib-brand.collapsed .chev { transform: rotate(-90deg); }
.lib-brand .cnt { margin-left: auto; font-size: 10px; color: var(--muted); }
.lib-item .badge.legacy { background: #2d2e38; color: #9a9caa; }
.lib-item .badge.unv, .about .badge.unv { background: #3b2a06; color: #ffc94d; }
.about .badge.legacy { background: #2d2e38; color: #9a9caa; margin-left: 8px; font-size: 10px; border-radius: 3px; padding: 0 5px; }
.lib-more { margin: 6px 10px; }
.about { display: flex; flex-direction: column; gap: 10px; line-height: 1.45; }
.about-head { display: flex; gap: 12px; align-items: center; }
.about .thumb.big { width: 52px; height: 40px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex: none; }
.about h4 { margin: 4px 0; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.about ul { margin: 0; padding-left: 18px; }
.about-conf { border-radius: 6px; padding: 6px 8px; margin: 0; }
.about-conf.high { background: #10301f; color: #c3f0d8; }
.about-conf.medium { background: #2a2b33; }
.about-conf.low { background: #3b2a06; color: #ffd98a; }

/* popups above dialogs; wider signal selects; OTHER type name */
#ctx { z-index: 400; }
.prow { grid-template-columns: 14px 1fr 54px 78px 46px 22px; }
.prow-ghost { grid-template-columns: 14px 1fr 54px 78px 46px 22px; }
.padd { grid-template-columns: 44px 10px 54px 80px 1fr; }
.prow .plabel { grid-column: 2 / -1; font-size: 12px; padding: 2px 6px; border-style: dashed; }
.padd .plabel { grid-column: 3 / -1; font-size: 12px; padding: 3px 6px; border-style: dashed; }

/* icon picker search */
.icon-picker { display: flex; flex-direction: column; gap: 6px; padding: 4px; width: 300px; }
.icon-search { width: 100%; }
.icon-chips { display: flex; flex-wrap: wrap; gap: 3px; }
#ctx .icon-chip { width: auto; display: inline-flex; padding: 2px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 11px; justify-content: center; }
#ctx .icon-chip.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.icon-grid { max-height: 260px; overflow-y: auto; }
#ctx .icon-btn.kb { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-empty { color: var(--muted); padding: 10px; text-align: center; font-size: 12px; }

/* ======================================================================
   Phone & tablet. Desktop is untouched: everything below only applies to
   narrow screens (≤ 1000 px / ≤ 640 px) or touch-first devices.
   ====================================================================== */
.only-compact, .only-phone, #lib-backdrop { display: none !important; }

@media (max-width: 1000px) {
  #app { height: 100vh; height: 100dvh; grid-template-columns: 1fr; grid-template-areas: "tb" "stage" "drawer" "pages"; }
  #btn-lib.only-compact { display: inline-flex !important; align-items: center; }
  .lib-head.only-compact { display: flex !important; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 15px; }
  /* library = slide-in panel */
  #library { position: fixed; z-index: 120; left: 0; top: 0; bottom: 0; width: min(380px, 92vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 8px 0 30px rgba(0,0,0,.45); }
  body.lib-open #library { transform: none; }
  body.lib-open #lib-backdrop { display: block !important; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 110; }
  /* inspector = bottom sheet */
  #props { display: block; position: fixed; z-index: 115; left: 0; right: 0; bottom: 0; max-height: 70vh; max-height: 70dvh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform .2s ease; box-shadow: 0 -10px 30px rgba(0,0,0,.45); overscroll-behavior: contain; }
  body.sheet-open #props { transform: none; }
  .sheet-head.only-compact { display: flex !important; justify-content: center; align-items: center; position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 8px 6px 2px; }
  .sheet-grip { width: 42px; height: 4px; border-radius: 2px; background: #555869; }
  #props-close { position: absolute; right: 6px; top: 2px; }
  .psec.info { gap: 6px; }
  .info-title b { font-size: 15px; }
  .info-port { display: grid; grid-template-columns: 24px auto 1fr; gap: 6px; align-items: center; padding: 3px 0; border-bottom: 1px solid #2a2b33; font-size: 13px; }
  .info-to { color: #8fd3b6; font-size: 12px; text-align: right; }
  #drawer { max-height: 45vh; }
}

@media (max-width: 640px) {
  #mobilebar.only-phone { display: flex !important; position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--panel); border-top: 1px solid var(--line); }
  #mobilebar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10.5px; background: none; border: 0; color: var(--text); padding: 0; min-width: 0; }
  #mobilebar button:active { background: var(--panel2); }
  #mobilebar button span { font-size: 19px; line-height: 1; }
  #app { height: calc(100vh - 56px); height: calc(100dvh - 56px - env(safe-area-inset-bottom, 0px)); }
  #toolbar { gap: 6px; padding: 0 8px; }
  #toolbar .tgroup, #doc-name, #btn-drawer, #btn-print, #btn-help, #btn-cloud, #btn-lib { display: none !important; }
  #toolbar .brand { font-size: 15px; flex: 1; }
  #status, #sync-status { display: none; }
  #props { bottom: calc(56px + env(safe-area-inset-bottom, 0px)); max-height: 65vh; max-height: 65dvh; }
  #drawer { position: fixed; left: 0; right: 0; top: 46px; bottom: calc(56px + env(safe-area-inset-bottom, 0px)); max-height: none; height: auto; z-index: 105; }
  .m-back { padding-top: 0; align-items: stretch; }
  .modal, .modal.wide, .modal.qa { width: 100vw; max-height: none; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
  .dev-cols, .pp, .help .cols { grid-template-columns: 1fr; }
  #share-banner, #ro-banner { top: 6px; font-size: 12px; padding: 6px 8px; gap: 6px; max-width: calc(100% - 16px); }
  #ctx { max-width: calc(100vw - 16px); }
  .icon-picker { width: min(300px, calc(100vw - 28px)); }
  .icon-grid { grid-template-columns: repeat(auto-fill, 40px); }
  #toast { bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
}

@media (pointer: coarse) {
  body { touch-action: manipulation; }
  #toolbar button, .btn, .ib, .ptab { min-height: 40px; }
  .btn.sm { min-height: 36px; }
  #ctx button { min-height: 42px; padding: 10px 14px; }
  #ctx .icon-btn { width: 40px; height: 40px; min-height: 40px; }
  .lib-item { min-height: 50px; }
  .lib-cat, .lib-brand { min-height: 40px; }
  .lib-item .acts { display: flex; }                 /* no hover-only controls on touch */
  .lib-item .acts button { width: 34px; height: 34px; }
  input, select, textarea { font-size: 16px; }       /* avoids iOS zoom-on-focus */
  .prow input, .prow select, .padd input, .padd select { font-size: 15px; min-height: 36px; }
  .prow { grid-template-columns: 22px 1fr 58px 84px 50px 30px; }
  .phandle { font-size: 18px; }
}
@media (max-width: 640px) { #toolbar #btn-lib.only-compact { display: none !important; } }
@media (max-width: 1000px) {
  #props { transform: translateY(calc(100% + 90px)); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  body.sheet-open #props { transform: none; visibility: visible; transition: transform .2s ease; }
  #library { visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  body.lib-open #library { visibility: visible; transition: transform .2s ease; }
}

/* Port editor: two-line rows, readable names */
.prow, .prow-ghost { display: block; grid-template-columns: none; padding: 4px 2px 5px; border-bottom: 1px solid #2a2b33; }
.prow-top { display: grid; grid-template-columns: 18px 1fr 26px; gap: 4px; align-items: center; }
.prow .pname { font-size: 13px; padding: 4px 7px; width: 100%; min-width: 0; }
.prow-meta { display: flex; gap: 4px; padding: 3px 26px 0 22px; align-items: center; }
.prow-meta select { font-size: 11.5px; padding: 2px 3px; height: 24px; min-width: 0; }
.prow-meta .pdir { flex: 0 0 66px; } .prow-meta .psig { flex: 0 0 84px; } .prow-meta .pside { flex: 0 0 82px; }
.prow-meta .plabel { flex: 1; min-width: 60px; grid-column: auto; font-size: 12px; padding: 2px 6px; border-style: dashed; }
.prow.used .pname { border-left: 3px solid var(--ok); }
.prow-ghost { background: var(--panel2); }
@media (pointer: coarse) {
  .prow .pname { font-size: 16px; min-height: 40px; }
  .prow-meta select { font-size: 15px; height: 36px; }
  .prow-meta .plabel { font-size: 15px; min-height: 36px; }
  .prow-top { grid-template-columns: 26px 1fr 36px; }
  .prow-meta { padding-left: 30px; padding-right: 36px; }
}

.inline-ed.port-ed { padding: 4px 8px; font-weight: 500; }

/* licence lock: visible, not hidden */
#toolbar button.locked::after { content: ' 🔒'; font-size: 11px; }
#toolbar button.locked { opacity: .85; }
.lock-explain { display: flex; gap: 14px; align-items: flex-start; line-height: 1.5; }
.lock-big { font-size: 30px; line-height: 1; }
