:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #66706a;
  --line: #e2e5e0;
  --soft: #eef1ec;
  /* Cartsnparts orange. White text on it is too faint, so text on orange uses --on-accent,
     and orange text on white uses the deeper --accent-text. */
  --accent: #EF790C;
  --accent-hover: #D96A04;
  --accent-soft: #FDEEDF;
  --accent-text: #B05300;
  --on-accent: #1F1300;
  --ok: #177245;
  --ok-soft: #e3f2e9;
  --danger: #c0392b;
  --warn: #a86400;
  --warn-soft: #fff4dd;
  --blue: #2f6fd6;
  --sleep: #2b3240;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1b201d;
    --text: #e8ece9;
    --muted: #9aa49e;
    --line: #2c332f;
    --soft: #232a26;
    --accent: #EF790C;
    --accent-hover: #F68C2E;
    --accent-soft: #3A2412;
    --accent-text: #F59A45;
    --on-accent: #1F1300;
    --ok: #3fae74;
    --ok-soft: #1e3328;
    --danger: #ef6b5b;
    --warn: #f0b04a;
    --warn-soft: #3a2f1a;
    --blue: #6b9cf0;
    --sleep: #0b0e14;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 26px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 4px; }
p { margin: 0 0 12px; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }
.small, small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); margin: 8px 0; min-height: 0; }
.error:empty { display: none; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand.center { justify-content: center; margin-bottom: 8px; }
.logo { width: 16px; height: 26px; border-radius: 4px; background: var(--accent); position: relative; }
.logo::after { content: ''; position: absolute; inset: 4px 3px 7px; background: var(--card); border-radius: 1px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--soft); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-icon { font-size: 14px; }
.page { max-width: 1100px; margin: 0 auto; padding: 24px 24px 80px; }
.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 12px; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--card); border-top: 1px solid var(--line);
    justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .nav-link { flex-direction: column; gap: 0; padding: 6px 4px; font-size: 11px; flex: 1; align-items: center; }
  .nav-icon { font-size: 18px; }
  .brand { flex: 1; }
  .page { padding: 16px 16px 100px; }
  h1 { font-size: 22px; }
}

/* ---------- cards & layout ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card.highlight { outline: 2px solid var(--accent); }
.card.placeholder { display: grid; place-items: center; min-height: 240px; text-align: center; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.section-head p { margin: 0; }
.head-right { display: flex; align-items: center; gap: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; align-items: center; }
.actions.left { justify-content: flex-start; margin-top: 8px; }
.empty { color: var(--muted); padding: 24px; text-align: center; list-style: none; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; min-height: 38px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--soft); }
.btn.ghost.danger, .btn.danger.ghost { color: var(--danger); background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; font-size: 15px; flex-shrink: 0;
}
.icon-btn:hover { background: var(--soft); color: var(--text); }
.link { border: 0; background: none; color: var(--accent-text); cursor: pointer; padding: 0; font: inherit; font-size: 13px; }
.link:hover { text-decoration: underline; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--card);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 38px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type=time], input[type=date] { width: auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.inline-field { display: flex; align-items: center; gap: 10px; max-width: 420px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; cursor: pointer; }
.search { max-width: 260px; margin-left: auto; }

.segmented { display: inline-flex; background: var(--soft); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500;
  padding: 6px 14px; border-radius: 7px; cursor: pointer;
}
.segmented button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.screen-pick { margin-bottom: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; min-width: 52px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.presets { display: flex; gap: 14px; margin-top: 6px; }

.switch { position: relative; display: inline-block; width: 40px; height: 24px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; }
.switch span::after {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch.big { width: 50px; height: 28px; }
.switch.big span::after { width: 22px; height: 22px; }
.switch.big input:checked + span::after { transform: translateX(22px); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.green { background: var(--ok-soft); color: var(--ok); }
.pill.red { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill.blue { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.pill.grey { background: var(--soft); color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 6px; background: var(--soft); color: var(--muted); margin: 4px 4px 0 0; }
.media-meta .tag { align-self: flex-start; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tags { display: flex; flex-wrap: wrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.dot.sleep { background: var(--sleep); }
.note.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- toasts & modal ---------- */
#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.2); transition: opacity .3s, transform .3s; max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
@media (max-width: 760px) { #toasts { bottom: 90px; } }

.backdrop { position: fixed; inset: 0; background: rgba(10, 14, 12, .5); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: min(480px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 20px 20px; overflow: auto; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 32px 28px; }

/* ---------- overview ---------- */
.setup .steps { list-style: none; padding: 0; margin: 8px 0 0; display: flex; gap: 24px; flex-wrap: wrap; }
.setup li { display: flex; align-items: center; gap: 8px; }
.setup li.done { color: var(--muted); text-decoration: line-through; }
.steps .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; margin: 0; }
.steps li.done .check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.screen-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.screen-card-body { display: grid; grid-template-columns: 180px 1fr; gap: 24px; }
@media (max-width: 600px) { .screen-card-body { grid-template-columns: 1fr; } .screen-frame { max-width: 200px; margin: 0 auto; } }
.screen-frame {
  aspect-ratio: 9 / 16; width: 100%;
  background: #000; border-radius: 10px; overflow: hidden;
  border: 6px solid #222; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  display: grid; place-items: center; color: #889;
}
.screen-frame img, .screen-frame video { width: 100%; height: 100%; object-fit: contain; display: block; }
.screen-frame.asleep { background: var(--sleep); }
.screen-frame.large { width: min(300px, 70vw); margin: 0 auto 10px; }
.frame-msg { display: flex; flex-direction: column; align-items: center; font-size: 14px; gap: 4px; text-align: center; padding: 8px; }
.frame-msg small { font-size: 13px; }
.frame-msg .big { font-size: 34px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.facts dd { margin: 0; }
.warnings { margin: 14px 0 0; padding: 10px 12px 10px 28px; background: var(--warn-soft); color: var(--warn); border-radius: 8px; font-size: 13px; }

/* ---------- media ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; background: var(--card);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.uploads { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.upload-row { display: grid; grid-template-columns: 1fr auto 140px; gap: 12px; align-items: center; background: var(--card); padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); }
.upload-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.media-grid > .empty { grid-column: 1 / -1; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.media-card {
  display: flex; flex-direction: column; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 0; overflow: hidden; cursor: pointer; font: inherit; color: inherit; position: relative;
}
.media-card:hover { border-color: var(--accent); }
.media-card.picked { outline: 3px solid var(--accent); border-color: var(--accent); }
.media-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; min-width: 0; }
.media-meta .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-num:empty { display: none; }
.pick-num { position: absolute; top: 8px; right: 8px; background: var(--accent); color: var(--on-accent); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.picker { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); max-height: 55vh; overflow: auto; padding: 4px; }

.thumb { aspect-ratio: 9 / 16; background: #111; position: relative; overflow: hidden; display: grid; place-items: center; color: #777; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb .badge { position: absolute; bottom: 6px; left: 6px; background: rgba(0,0,0,.7); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.thumb.small { width: 40px; flex-shrink: 0; border-radius: 5px; }
.thumb.small .badge, .thumb.mini .badge { display: none; }
.thumb.mini { width: 22px; border-radius: 3px; }

.media-detail { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
@media (max-width: 600px) { .media-detail { grid-template-columns: 1fr; } }
.detail-preview { background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 9 / 16; display: grid; place-items: center; }
.detail-preview img, .detail-preview video { width: 100%; height: 100%; object-fit: contain; }

/* ---------- playlists ---------- */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.pl-list { display: flex; flex-direction: column; gap: 8px; }
.pl-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.pl-item:hover { border-color: var(--accent); }
.pl-item.active { border-color: var(--accent); background: var(--accent-soft); }
.pl-item .name { font-weight: 600; }
.pl-thumbs { display: flex; gap: 2px; width: 70px; flex-shrink: 0; }
.back-link { display: none; margin-bottom: 8px; text-decoration: none; }
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; }
  .split.has-detail .pl-list { display: none; }
  .back-link { display: inline-block; }
  .split:not(.has-detail) .placeholder { display: none; }
}
.editor-head { display: flex; align-items: center; gap: 12px; }
.title-input { font-size: 20px; font-weight: 700; border-color: transparent; padding-left: 6px; margin-left: -6px; }
.title-input:hover { border-color: var(--line); }
.save-status { white-space: nowrap; }
.pl-rows { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.pl-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.pl-row.sortable-ghost { opacity: .4; }
.pl-row-name { flex: 1; min-width: 0; }
.pl-row-name > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handle { cursor: grab; color: var(--muted); padding: 0 4px; user-select: none; letter-spacing: -2px; }
.duration { display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.duration input { width: 72px; text-align: right; }
.editor-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

/* ---------- schedule ---------- */
.sched-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.sched-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.sched-item.paused { opacity: .6; }
.sched-item.sortable-ghost { opacity: .4; }
.sched-text { flex: 1; min-width: 0; }
@media (max-width: 600px) {
  .sched-item { flex-wrap: wrap; }
  .sched-text { flex-basis: calc(100% - 60px); }
  .section-head { flex-direction: column; }
}
.radio-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (max-width: 600px) { .radio-row { grid-template-columns: 1fr; } }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio input { margin-top: 4px; }
.radio span { display: flex; flex-direction: column; }
.sleep-table { border-collapse: collapse; width: 100%; max-width: 560px; margin-bottom: 10px; }
.sleep-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 8px; }
.sleep-table td { padding: 5px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
.sleep-table tr.off td:first-child { color: var(--muted); }
.sleep-table input[type=time]:disabled { opacity: .35; }

.timeline { display: flex; flex-direction: column; gap: 6px; }
.tl-row { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 10px; }
.tl-day { font-size: 13px; font-weight: 500; }
.tl-bar { position: relative; height: 30px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.tl-bar.labels { height: 16px; background: none; overflow: visible; }
.tl-bar.labels span { position: absolute; font-size: 11px; color: var(--muted); }
.tl-seg { position: absolute; top: 0; bottom: 0; color: #fff; font-size: 11px; display: flex; align-items: center; padding: 0 6px; overflow: hidden; white-space: nowrap; border-right: 1px solid rgba(255,255,255,.35); text-shadow: 0 1px 2px rgba(0,0,0,.45); }
.tl-seg span { overflow: hidden; text-overflow: ellipsis; }
.tl-seg.sleep { background: var(--sleep); color: #9aa3b5; }
.tl-seg.none { background: repeating-linear-gradient(45deg, var(--soft), var(--soft) 4px, var(--line) 4px, var(--line) 8px); color: var(--muted); }
.tl-now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); box-shadow: 0 0 0 1px var(--card); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 13px; }
.legend > span { display: flex; align-items: center; gap: 6px; }
@media (max-width: 600px) { .tl-row { grid-template-columns: 60px 1fr; gap: 6px; } }

/* ---------- screens ---------- */
.pair-form { display: grid; grid-template-columns: 180px 1fr auto; gap: 12px; align-items: end; }
.pair-form .field { margin: 0; }
@media (max-width: 600px) { .pair-form { grid-template-columns: 1fr; } }
.code-input { font-size: 22px; letter-spacing: .15em; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.howto { margin: 4px 0 16px; padding-left: 20px; color: var(--muted); }
.device-info { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.device-info summary { cursor: pointer; color: var(--muted); font-weight: 500; }
.device-info .facts { margin: 12px 0; }

/* ---------- account & users ---------- */
.user-btn { gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
@media (max-width: 760px) { .user-name { display: none; } }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 10px; }
.users-table td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.users-table .tag { margin-left: 8px; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { margin-left: 4px; }
@media (max-width: 700px) {
  .users-table thead { display: none; }
  .users-table tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 0; border-top: 1px solid var(--line); }
  .users-table td { border: 0; padding: 2px 6px; }
  .users-table td.email { grid-column: 1; }
  .users-table td.row-actions { grid-column: 1 / -1; text-align: left; padding-top: 8px; }
}
.page-head .spacer { flex: 1; }
.login-card .field { margin-bottom: 4px; }
