:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #1a2130;
  --line: #263047;
  --text: #e6edf3;
  --muted: #8b98ad;
  --accent: #4c8dff;
  --danger: #ff6b6b;
  --ok: #3fb950;
  --warn: #d29922;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
h2 { font-size: 1.35rem; margin: 0; }
h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.5rem 0 .75rem; }
h3:first-child { margin-top: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.accent { color: var(--accent); }
.right { text-align: right; }
.error { color: var(--danger); }
.empty { color: var(--muted); padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- controls ----------------------------------------------------------- */
button, .btn {
  font: inherit;
  padding: .45rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: inline-block;
}
button:hover, .btn:hover { background: #222c40; text-decoration: none; }
button:disabled { opacity: .35; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost, .btn.ghost { background: transparent; }
button.danger, .btn.danger { color: var(--danger); border-color: #4a2530; }
button.full { width: 100%; margin-top: 1rem; }

input, select {
  font: inherit;
  padding: .45rem .6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0e131d;
  color: var(--text);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { padding: 2px; height: 2.1rem; }
input.num { width: 5.5rem; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; flex: 1; }
.field > span { font-size: .8rem; color: var(--muted); }

.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; align-items: center; }

/* --- login -------------------------------------------------------------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login[hidden] { display: none; }
.login .card {
  width: min(24rem, 92vw);
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.login h1 { margin: 0; font-size: 1.5rem; }
.login label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }

/* --- shell -------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: .75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { font-weight: 700; color: var(--text); }
.brand em { font-style: normal; font-size: .7rem; color: var(--muted); margin-left: .25rem; }
#nav { display: flex; gap: .25rem; }
#nav a { padding: .35rem .75rem; border-radius: 8px; color: var(--muted); }
#nav a.active { background: var(--panel-2); color: var(--text); }
.spacer { flex: 1; }

main { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h2 { flex: 1; }

/* --- table -------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.table td { padding: .7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 999px; border: 1px solid var(--line); }
.pill.online { color: var(--ok); border-color: #1d3d28; background: #0f2417; }
.pill.offline { color: var(--warn); border-color: #3d3320; background: #241d0f; }
.pill.unpaired { color: var(--muted); }
.code { margin-left: .5rem; letter-spacing: .15em; color: var(--accent); }

/* --- grids and tiles ---------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.tile { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile img, .tile video { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.tile-generic { aspect-ratio: 16/9; display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.tile figcaption { padding: .6rem .75rem; display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; }
.tile .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.dropzone.hot { border-color: var(--accent); background: #101a2c; }
.upload-row { display: flex; align-items: center; gap: .75rem; padding: .35rem 0; font-size: .85rem; }
.upload-row .bar { height: 6px; background: var(--accent); border-radius: 3px; width: 0; transition: width .2s; flex: 1; }
.upload-row.failed .bar { background: var(--danger); }

/* --- layout preview ----------------------------------------------------- */
.layout-preview {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.layout-preview .pz {
  position: absolute;
  border: 1px solid rgba(76, 141, 255, .8);
  background: rgba(76, 141, 255, .16);
  font-size: .68rem;
  color: #cfe0ff;
  padding: 2px 4px;
  overflow: hidden;
}
.card-tile .layout-preview { border-radius: 0; }

/* --- split panes -------------------------------------------------------- */
.split { display: grid; grid-template-columns: 260px 1fr; gap: 1.25rem; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }

.sidelist { display: flex; flex-direction: column; gap: .25rem; }
.sideitem { display: flex; justify-content: space-between; gap: .5rem; padding: .55rem .75rem; border-radius: 8px; color: var(--text); }
.sideitem:hover { background: var(--panel-2); text-decoration: none; }
.sideitem.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }

.detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.detail-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.title-input { flex: 1; font-size: 1.1rem; font-weight: 600; }
.addrow { padding: .75rem; background: var(--panel-2); border-radius: 8px; margin-bottom: 1rem; }

.items { display: flex; flex-direction: column; gap: .5rem; }
.item { display: flex; align-items: center; gap: .75rem; padding: .5rem; background: var(--panel-2); border-radius: 8px; }
.item .pos { width: 1.5rem; text-align: center; color: var(--muted); font-size: .8rem; }
.item .thumb { width: 72px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.item .thumb.generic { display: grid; place-items: center; font-size: .7rem; color: var(--muted); border: 1px solid var(--line); }
.item-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.item-body .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }

.zonebind { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.zonebind .zonename { font-weight: 600; min-width: 7rem; }
.zonebind select { margin-left: auto; }

.pairbox { text-align: center; padding: 1rem; background: var(--panel-2); border-radius: 8px; margin-bottom: 1rem; }
.pairbox .url { display: block; color: var(--accent); margin: .5rem 0; font-size: .9rem; }
.bigcode { font-size: 2.25rem; letter-spacing: .3em; font-weight: 700; font-family: ui-monospace, Menlo, monospace; }

.kv { margin: 0; }
.kvrow { display: flex; gap: 1rem; padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.kvrow dt { color: var(--muted); min-width: 7rem; margin: 0; }
.kvrow dd { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* --- designer ----------------------------------------------------------- */
.design-split { display: grid; grid-template-columns: 1fr 300px; gap: 1.25rem; align-items: start; }
.stage-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.design-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
  touch-action: none; /* let pointer events drive the drag, not the browser */
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 10% 10%;
}
.dz {
  position: absolute;
  border: 1px solid rgba(76, 141, 255, .75);
  background: rgba(76, 141, 255, .14);
  cursor: move;
  overflow: visible;
}
.dz.selected { border-color: var(--accent); background: rgba(76, 141, 255, .26); box-shadow: 0 0 0 1px var(--accent); }
.dz-label { position: absolute; top: 3px; left: 5px; font-size: .72rem; color: #dbe8ff; pointer-events: none; }
.dz-dims { position: absolute; bottom: 3px; right: 5px; font-size: .68rem; color: #9fbcf0; pointer-events: none; }

.handle { position: absolute; width: 11px; height: 11px; background: #fff; border: 1px solid var(--accent); border-radius: 2px; z-index: 10; }
.h-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.h-n  { left: calc(50% - 5px); top: -6px; cursor: ns-resize; }
.h-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.h-e  { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.h-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.h-s  { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
.h-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.h-w  { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }

.inspector { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; position: sticky; top: 5rem; }

/* --- toasts ------------------------------------------------------------- */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 999; }
.toast {
  padding: .6rem 1rem;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  font-size: .88rem;
  transition: opacity .35s, transform .35s;
  max-width: 26rem;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.out { opacity: 0; transform: translateX(1rem); }

@media (max-width: 900px) {
  .split, .design-split { grid-template-columns: 1fr; }
  .inspector { position: static; }
}
