:root {
  --bg: #f5f3ef;
  --card: #ffffff;
  --text: #1d1b18;
  --muted: #6f6a62;
  --line: #e3ded5;
  --accent: #a8823f;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --soft: #f0ebe2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --card: #1f1d1a; --text: #f1ede6; --muted: #a39d93;
    --line: #34302a; --accent: #c9a86a; --accent-ink: #151412; --danger: #e5675a; --soft: #2a2722;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.brand { font-weight: 800; letter-spacing: 0.12em; font-size: 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand span { font-weight: 400; color: var(--muted); letter-spacing: 0.02em; }
.brand .logo {
  width: 30px; height: 30px; flex: none; background: var(--text);
  -webkit-mask: url(/logo.svg) center / contain no-repeat; mask: url(/logo.svg) center / contain no-repeat;
}
.login-card .brand .logo { width: 44px; height: 44px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
a.btn { color: inherit; text-decoration: none; justify-content: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.icon-btn { border: 1px solid var(--line); background: var(--card); border-radius: 6px; width: 32px; height: 32px; cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=time], select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login-card .brand { margin-bottom: 8px; }
.err { color: var(--danger); min-height: 1.5em; font-size: 14px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--soft); color: var(--text); font-weight: 600; }
.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.save-state { font-size: 13px; color: var(--muted); }
.save-state.dirty { color: var(--accent); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0; font-size: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 16px; }

/* Screens */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card-row { display: flex; gap: 8px; align-items: center; }
.card-row > input[type=text] { flex: 1; }
.field-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.tv-link { display: flex; gap: 6px; align-items: center; background: var(--soft); border-radius: 8px; padding: 6px 6px 6px 10px; }
.tv-link code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.rule { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.day { border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 3px 8px; font-size: 13px; cursor: pointer; }
.day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.time-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.time-row select { flex: 1; }
.now-playing { font-size: 13px; color: var(--muted); }
.now-playing b { color: var(--text); }

/* Playlists */
.pl-layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.pl-nav { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.pl-nav button { width: 100%; text-align: left; border: 1px solid transparent; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.pl-nav button.active { background: var(--card); border-color: var(--line); font-weight: 600; }
.pl-nav .count { float: right; color: var(--muted); font-size: 13px; font-weight: 400; }
.pl-main { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.items { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.item.dragging { opacity: 0.4; }
.item.over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.handle { cursor: grab; color: var(--muted); padding: 0 4px; user-select: none; }
.item .thumb { width: 96px; height: 54px; flex: none; border-radius: 6px; }
.item .meta { flex: 1; min-width: 0; }
.item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 12px; color: var(--muted); }
.dur { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.dur input { width: 64px; }
.empty-note { color: var(--muted); padding: 20px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }

/* Media */
.thumb { background: #000; object-fit: cover; display: block; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); margin-bottom: 14px; }
.drop.over { border-color: var(--accent); color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.tile .thumb { width: 100%; aspect-ratio: 16 / 9; }
.tile .info { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.tile .name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .tile-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.tile.pick { cursor: pointer; }
.tile.pick:hover { border-color: var(--accent); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--soft); color: var(--muted); }

.upload-row { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 8px; }
.upload-row .bar { flex: 1; height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.upload-row .bar div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.upload-row .label { width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-row.error { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px);
}

.media-main { min-width: 0; }
.search { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); margin-bottom: 10px; }
.pl-nav li.drop-over button { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.folder-ico { margin-right: 6px; }
.tile[draggable=true] { cursor: grab; }
.tile select { width: 100%; font-size: 12px; padding: 4px 6px; }
.picker-tools { display: flex; gap: 8px; margin: 8px 0 10px; flex-wrap: wrap; }
.picker-tools input { flex: 1; min-width: 160px; }

details.add-media { margin-top: 16px; }
details.add-media summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

@media (max-width: 760px) {
  .pl-layout { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .actions { width: 100%; }
  .item .thumb { width: 72px; height: 40px; }
}
