/* PW TV Screens admin — phone first. */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #17201b;
  --muted: #5d6b63;
  --border: #d9dfdb;
  --accent: #2e7d5b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1e9;
  --ok: #1f8a4c;
  --ok-soft: #e1f4e8;
  --warn: #a86700;
  --warn-soft: #fff1d6;
  --bad: #c0392b;
  --bad-soft: #fde6e3;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 5%);
  --radius: 12px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1512;
    --surface: #18201c;
    --surface-2: #212b26;
    --text: #e6ece8;
    --muted: #97a59d;
    --border: #2d3832;
    --accent: #4fb385;
    --accent-ink: #0b1510;
    --accent-soft: #1d3329;
    --ok: #5ccf8c;
    --ok-soft: #173325;
    --warn: #f0b44c;
    --warn-soft: #3a2c12;
    --bad: #ff7b6e;
    --bad-soft: #3d1c19;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0; }
p { margin: 0 0 10px; }
[hidden] { display: none !important; }
.boot, .loading { padding: 48px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.block { display: block; }
.grow { flex: 1; min-width: 0; }
.mono, code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 12px; }
.warn-text { color: var(--warn); }

/* ── shell ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 0.8rem; letter-spacing: 0.02em;
}
.brand.big { font-size: 1.2rem; margin-bottom: 16px; }
.who { margin-left: auto; color: var(--muted); font-size: 0.85rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-pill { background: var(--warn-soft); color: var(--warn); border-radius: 99px; padding: 2px 10px; font-size: 0.75rem; font-weight: 700; }
.demo-role { width: auto; padding: 4px 8px; font-size: 0.8rem; }

.view { width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); outline: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.tab-icon { font-size: 1.25rem; line-height: 1; }
.tab.active { color: var(--accent); }
@media (min-width: 860px) {
  .tabs { position: sticky; top: 51px; height: auto; justify-content: center; gap: 4px; padding: 6px; border-top: 0; border-bottom: 1px solid var(--border); }
  .tab { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 8px 14px; border-radius: 8px; font-size: 0.9rem; }
  .tab.active { background: var(--accent-soft); }
  body > #app { display: flex; flex-direction: column; }
  .topbar { order: 0; } .tabs { order: 1; } .view { order: 2; padding-bottom: 48px; }
}

.page-head { display: flex; align-items: flex-end; gap: 12px; justify-content: space-between; margin-bottom: 16px; }
.page-head .summary { margin: 2px 0 0; }
.back { display: inline-block; font-size: 0.85rem; text-decoration: none; margin-bottom: 4px; }

/* ── controls ── */
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label > input, label > select { margin-top: 4px; }
input, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input:disabled, select:disabled { opacity: 0.7; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: 20px; min-height: 20px; height: 20px; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--bad); color: #fff; border-color: transparent; }
.btn.danger.ghost, .btn.ghost.danger { background: transparent; color: var(--bad); border-color: var(--border); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.busy { opacity: 0.7; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted);
  font: inherit; font-size: 1rem; cursor: pointer; list-style: none;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.danger:hover { color: var(--bad); }
.link { background: none; border: 0; padding: 6px 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.link.danger { color: var(--bad); }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.actions.left { justify-content: flex-start; }
.actions .push-left { margin-right: auto; }
.actions.sticky { position: sticky; bottom: -16px; background: var(--surface); padding: 12px 0 4px; margin-top: 12px; }
.actions.sticky > span { margin-right: auto; }
.form-error { color: var(--bad); font-size: 0.9rem; min-height: 0; margin: 4px 0; }
.form-error:empty { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; }

/* ── cards & lists ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-row h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cols { display: grid; gap: 16px; }
@media (min-width: 860px) { .cols { grid-template-columns: 1fr 1.25fr; align-items: start; } }
.grid { display: grid; gap: 12px; }
.grid.screens { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid.media { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (min-width: 600px) { .grid.media { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .btn { margin-top: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.row-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; min-height: 36px; }
.chev { color: var(--muted); font-size: 1.3rem; }
.swatch { width: 12px; height: 12px; border-radius: 4px; flex: 0 0 auto; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 0.85rem; }
.facts dd { margin: 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 0.75rem; font-weight: 600; vertical-align: middle; }
.tag.ok { background: var(--ok-soft); color: var(--ok); margin-left: 0; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; margin-top: 10px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }

/* screens */
.screen-card { display: block; color: inherit; text-decoration: none; transition: border-color .15s; }
.screen-card:hover { border-color: var(--accent); }
.now { display: flex; gap: 12px; align-items: center; margin: 4px 0 12px; }
.now-thumb { width: 112px; aspect-ratio: 16/9; border-radius: 8px; background: #000; overflow: hidden; display: grid; place-items: center; color: #777; flex: 0 0 auto; }
.now-thumb.portrait { width: 48px; aspect-ratio: 9/16; }
.now-thumb img { width: 100%; height: 100%; object-fit: contain; }
.now-text { min-width: 0; }
.now-text .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card-foot { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: 0.85rem; }

/* schedule week view */
.week { margin: 4px 0 12px; }
.wk-grid { display: grid; grid-template-columns: 28px repeat(7, 1fr); gap: 3px; }
.wk-day { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--muted); height: 20px; }
.wk-day.today { color: var(--accent); }
.wk-track { position: relative; height: 260px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.wk-hours .wk-track { background: none; overflow: visible; }
.wk-hours span { position: absolute; right: 2px; transform: translateY(-1px); font-size: 0.65rem; color: var(--muted); }
.wk-block { position: absolute; border-radius: 4px; border: 1px solid rgb(255 255 255 / 55%); overflow: hidden; color: #fff; font-size: 0.65rem; font-weight: 600; padding: 2px 3px; line-height: 1.15; }
.wk-block span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.wk-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--bad); z-index: 200; }
.rules .grow .block { font-size: 0.85rem; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day { min-height: 44px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.presets { display: flex; gap: 16px; margin-top: 4px; }
.danger-zone { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.danger-zone summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 6px 0; }

/* playlist editor */
.title-input { font-size: 1.35rem; font-weight: 700; border-color: transparent; background: transparent; padding: 4px 6px; margin-left: -6px; }
.title-input:hover, .title-input:focus { border-color: var(--border); background: var(--surface); }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
.item.dragging { opacity: 0.85; border-color: var(--accent); box-shadow: 0 6px 20px rgb(0 0 0 / 18%); }
.handle { touch-action: none; cursor: grab; border: 0; background: none; color: var(--muted); font-size: 1.3rem; width: 28px; height: 44px; padding: 0; }
.pos { width: 20px; text-align: center; color: var(--muted); font-size: 0.8rem; flex: 0 0 auto; }
.item-thumb { width: 72px; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden; flex: 0 0 auto; display: grid; place-items: center; }
.item-thumb.portrait { width: 32px; aspect-ratio: 9/16; }
.item-thumb img { width: 100%; height: 100%; object-fit: contain; }
.item-main { flex: 1; min-width: 0; }
.dur { font-size: 0.85rem; color: var(--muted); width: 64px; text-align: right; }
.secs { display: flex; align-items: center; gap: 4px; margin: 0; width: 64px; color: var(--muted); }
.secs input { width: 48px; min-height: 36px; padding: 4px 6px; margin: 0; text-align: right; }
.item-btns { display: flex; }
.empty-row { text-align: center; padding: 32px 16px; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.savebar {
  position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap;
  margin-top: 16px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.unsaved { margin-right: auto; color: var(--warn); font-weight: 600; font-size: 0.9rem; }
@media (min-width: 860px) { .savebar { bottom: 12px; } }
@media (max-width: 520px) {
  .item { flex-wrap: wrap; }
  .item-main { flex-basis: calc(100% - 150px); }
  .item-btns { margin-left: auto; }
  .pos { display: none; }
}

/* picker */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pick { text-align: left; background: var(--surface); border: 2px solid var(--border); border-radius: 10px; padding: 6px; font: inherit; color: inherit; cursor: pointer; }
.pick.picked { border-color: var(--accent); }
.pick-thumb { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden; display: grid; place-items: center; }
.pick-thumb.portrait img { height: 100%; width: auto; }
.pick-thumb img { width: 100%; height: 100%; object-fit: contain; }
.pick-badge:empty { display: none; }
.pick-badge { position: absolute; top: 4px; right: 4px; background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 8px; font-weight: 700; font-size: 0.8rem; }
.pick-name { font-weight: 600; font-size: 0.85rem; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* media */
.usage { margin: 4px 0 12px; }
.usage-text { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 4px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar.thin { height: 4px; margin-top: 6px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s; }
.bar-fill.hot { background: var(--warn); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: transparent; }
.media-card { position: relative; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.media-thumb { position: relative; display: grid; place-items: center; aspect-ratio: 16/9; width: 100%; background: #000; border: 0; padding: 0; cursor: zoom-in; }
.media-thumb img { width: 100%; height: 100%; object-fit: contain; }
.type-badge { position: absolute; left: 8px; bottom: 8px; background: rgb(0 0 0 / 70%); color: #fff; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.media-info { padding: 10px 12px 12px; padding-right: 48px; }
.name-btn { display: block; max-width: 100%; background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--text); cursor: text; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uses { margin-top: 4px; }
.media-del { position: absolute; right: 6px; bottom: 8px; }
.queue { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.q-row { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.q-row.ok { border-color: var(--ok); }
.q-row.bad { border-color: var(--bad); background: var(--bad-soft); }
.q-top { display: flex; justify-content: space-between; gap: 12px; }
.q-status { flex: 0 0 auto; font-size: 0.85rem; color: var(--muted); }
.preview { display: grid; place-items: center; background: #000; border-radius: 8px; overflow: hidden; }
.preview video, .preview img { max-width: 100%; max-height: 70vh; display: block; }

/* users */
.user-row { flex-wrap: wrap; }
.role-sel { width: auto; min-width: 110px; }
.more { position: relative; }
.more summary::-webkit-details-marker { display: none; }
.menu { position: absolute; right: 0; top: 44px; z-index: 30; display: flex; flex-direction: column; min-width: 170px; padding: 6px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.roles-help { margin-top: 12px; font-size: 0.9rem; }
.roles-help summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.secret { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.secret code { flex: 1; font-size: 1.2rem; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; letter-spacing: 0.04em; overflow-wrap: anywhere; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 6px; }
.code-input { font-family: ui-monospace, Consolas, monospace; font-size: 1.6rem; letter-spacing: 0.3em; text-transform: uppercase; text-align: center; }

/* modal */
.modal { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); }
.modal.wide { width: min(860px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(0 0 0 / 45%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 0 16px; }
.modal-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 12px 16px 16px; }

/* toast */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 0.9rem; transition: opacity .4s, transform .4s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (max-width: 520px) {
  .who { display: none; }
  .brand { white-space: nowrap; }
  .media-info { padding: 8px 10px 10px; padding-right: 40px; }
  .media-info .small { font-size: 0.78rem; }
}
