:root {
  --bg: #f6f4fb;
  --panel: #ffffff;
  --text: #14112b;
  --muted: #6b6785;
  --line: #e6e2f0;
  --accent: #6d4aff;
  --accent-soft: #eeeaff;
  --on-accent: #ffffff;
  --lime: #c6f432;
  --coral: #ff6b4a;
  --danger: #c2341b;
  --ok: #16a34a;
  --off: #a8a4bd;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0d1f; --panel: #1a1730; --text: #f1eeff; --muted: #a39fc0;
    --line: #2c2848; --accent: #a594ff; --accent-soft: #2a2350; --on-accent: #14112b; --danger: #ff8a73;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button.icon { padding: 4px 8px; }
button:disabled { opacity: .5; cursor: default; }

.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; display: block; }
.brand .wordmark { width: 76px; height: auto; display: block; }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; width: min(360px, 100%); display: grid; gap: 16px;
}
.login-card label { display: grid; gap: 6px; color: var(--muted); }
.error { color: var(--danger); margin: 0; min-height: 1em; }

/* shell */
header {
  display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
nav { display: flex; gap: 4px; flex: 1; }
nav button { border: none; background: none; color: var(--muted); }
nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { padding: 24px; max-width: 1200px; margin: 0 auto; }
h2 { font-size: 18px; margin: 0 0 16px; }
h3 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input[type=text], .row > input:not([type]) { flex: 1 1 160px; }
.spacer { flex: 1; }

/* table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--off); margin-right: 6px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.table-wrap { overflow-x: auto; }

/* media grid */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { aspect-ratio: 16/9; background: #000; display: grid; place-items: center; color: #9ca3af; font-size: 13px; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: contain; }
.tile-body { padding: 10px; display: grid; gap: 6px; }
.tile-body input { width: 100%; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* playlists */
.split { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } main { padding: 16px; } header { gap: 10px; padding: 10px 16px; flex-wrap: wrap; } }
.list { display: grid; gap: 4px; }
.list button { text-align: left; border-color: transparent; display: flex; justify-content: space-between; gap: 8px; }
.list button.active { background: var(--accent-soft); color: var(--accent); }
.items { display: grid; gap: 6px; margin: 12px 0; }
.item { display: grid; grid-template-columns: 26px 54px 1fr 110px auto; gap: 10px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.item .mini { width: 54px; height: 32px; background: #000; border-radius: 4px; overflow: hidden; display: grid; place-items: center; font-size: 10px; color: #aaa; }
.item .mini img { width: 100%; height: 100%; object-fit: cover; }
.item input { width: 100%; }
.item .num { color: var(--muted); text-align: center; }
@media (max-width: 560px) { .item { grid-template-columns: 22px 1fr 80px; } .item .mini { display: none; } .item .acts { grid-column: 1 / -1; } }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-box { background: var(--panel); border-radius: var(--radius); padding: 22px; width: min(720px, 100%); max-height: 90vh; overflow: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.form-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.rule { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; margin-bottom: 8px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; user-select: none; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30;
}
.empty { text-align: center; padding: 30px; color: var(--muted); }

/* screens: actions + screenshot */
.acts-cell { white-space: nowrap; }
.acts-cell button + button { margin-left: 6px; }
.last-cmd { font-size: 12px; margin-top: 4px; }
.last-cmd.fail { color: var(--danger); }
.shot-wrap { background: #000; border-radius: 8px; overflow: hidden; display: grid; place-items: center; min-height: 200px; color: #9ca3af; }
.shot-wrap img { width: 100%; height: auto; display: block; }
.remote { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }

/* layout editor */
.layout-editor { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
@media (max-width: 960px) { .layout-editor { grid-template-columns: 1fr; } }
.canvas-wrap { display: grid; place-items: center; background: repeating-conic-gradient(var(--line) 0% 25%, transparent 0% 50%) 50% / 16px 16px; border-radius: 8px; padding: 12px; }
.canvas { position: relative; width: 100%; aspect-ratio: 16 / 9; box-shadow: 0 1px 6px rgba(0,0,0,.25); overflow: hidden; touch-action: none; user-select: none; }
.canvas.portrait { aspect-ratio: 9 / 16; width: auto; height: min(68vh, 760px); }
.zone {
  position: absolute; border: 1.5px dashed rgba(255,255,255,.55); cursor: move;
  display: grid; place-items: center; text-align: center; overflow: hidden; font-size: 12px;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); padding: 4px;
}
.zone.media { background: rgba(15,118,110,.55); }
.zone.ticker { background: rgba(180,83,9,.6); }
.zone.clock { background: rgba(79,70,229,.6); }
.zone.sel { border: 2px solid #fff; outline: 2px solid var(--accent); z-index: 50; }
.zone .zl { font-weight: 600; line-height: 1.2; pointer-events: none; }
.zone .zs { opacity: .85; font-size: 11px; pointer-events: none; }
.zone .rs { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, #fff 50%); }
.props { display: grid; gap: 10px; }
.props label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.props textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-height: 80px; resize: vertical; }
.props input[type=color] { padding: 2px; height: 34px; width: 100%; }
.xywh { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.xywh input { width: 100%; }
.zone-list { display: grid; gap: 4px; margin-bottom: 8px; }
.zone-list button { text-align: left; display: flex; justify-content: space-between; border-color: transparent; }
.zone-list button.active { background: var(--accent-soft); color: var(--accent); }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }
.tpl { border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; background: var(--panel); text-align: center; font-size: 12px; }
.tpl:hover, .tpl.active { border-color: var(--accent); }
.tpl .mini-canvas { position: relative; aspect-ratio: 16/9; background: #111; border-radius: 4px; margin-bottom: 6px; overflow: hidden; }
.tpl .mini-canvas.portrait { aspect-ratio: 9/16; height: 70px; margin: 0 auto 6px; }
.tpl .mini-canvas div { position: absolute; border: 1px solid #111; }

code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; background: var(--accent-soft); color: var(--text); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
code.copy { cursor: copy; }

/* v2: sites, users, roles */
.login-card input { width: 100%; }
.site-box { display: flex; align-items: center; gap: 8px; }
.site-box select { font-weight: 600; max-width: 240px; }
.role { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.role.viewer { background: var(--line); color: var(--muted); }
.user-box { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-width: 180px; box-shadow: 0 6px 24px rgba(0,0,0,.12); z-index: 10; display: grid; }
.menu button { border: none; text-align: left; background: none; }
.menu button:hover { background: var(--accent-soft); }
.subnav { display: flex; gap: 4px; margin-bottom: 16px; }
.subnav button { border: none; background: none; color: var(--muted); }
.subnav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.edit-only.locked { display: none !important; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.cmd { display: block; padding: 10px 12px; margin: 8px 0; font-size: 12.5px; }
.access { width: 100%; }
.access td { padding: 6px 8px; }
.access select { width: 100%; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--line); color: var(--muted); margin: 1px 2px 1px 0; }
.pill.admin { background: var(--accent); color: #fff; }
.pill.off { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
@media (max-width: 900px) { header { flex-wrap: wrap; } nav { order: 3; flex-basis: 100%; overflow-x: auto; } }

/* v2.1: licensing */
#alert-bar { background: #fef3c7; color: #78350f; border-bottom: 1px solid #fcd34d; padding: 8px 24px; font-size: 13px; }
#alert-bar a { color: inherit; font-weight: 600; }
@media (prefers-color-scheme: dark) { #alert-bar { background: #3b2a06; color: #fcd34d; border-color: #78350f; } }
.lic { font-size: 12px; }
.lic.grace { color: #b45309; font-weight: 600; }
.lic.expired { color: var(--danger); font-weight: 600; }
.pill.warn { background: #fef3c7; color: #92400e; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.seats { display: flex; gap: 22px; flex-wrap: wrap; margin: 4px 0 6px; }
.seats div { display: grid; }
.seats strong { font-size: 22px; }
.seats span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; max-width: 420px; }
.bar > div { height: 100%; background: var(--accent); }
.bar.full > div { background: #d97706; }
.back { border: none; background: none; color: var(--accent); padding: 0; margin-bottom: 10px; }
.notice.warn { background: #fef3c7; color: #78350f; }

/* v2.3: two-factor */
.brand strong { font-size: 16px; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 10px; padding: 8px; border: 1px solid var(--line); }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; letter-spacing: .04em; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; background: var(--accent-soft); padding: 14px 18px; border-radius: 10px; }
.setup-page { max-width: 640px; margin: 40px auto; }
.mfa-steps { display: grid; grid-template-columns: 216px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 560px) { .mfa-steps { grid-template-columns: minmax(0, 1fr); } }
.policy { display: grid; gap: 10px; }
.policy label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.policy label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.policy input { margin-top: 3px; }
.policy small { display: block; color: var(--muted); }
