:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --off-bg: #eceff3;
  --drag-bg: #eef4ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1d2128;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --border: #2f3540;
    --accent: #4f8cff;
    --danger: #ef5350;
    --ok: #4ade80;
    --ok-bg: #173a24;
    --off-bg: #2a2f38;
    --drag-bg: #1f2c44;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* beat display rules like button { inline-block } */

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); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code { font-size: .9em; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  padding: .75rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}
.card.narrow { max-width: 380px; margin: 3rem auto; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.inline { display: inline; }

label { display: block; margin-bottom: .8rem; font-weight: 500; }
label.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; margin: 0; }

input[type=text], input:not([type]), input[type=password], input[type=number] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem .6rem;
}
label > input:not([type=checkbox]) { display: block; width: 100%; margin-top: .25rem; }

button, .button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: .45rem .9rem;
  text-decoration: none;
  display: inline-block;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.small { padding: .2rem .6rem; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); background: var(--card); }
.flash-error { border-color: var(--danger); color: var(--danger); }
.flash-success { border-color: var(--ok); color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }

.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; vertical-align: middle; }
.pill.online { background: var(--ok-bg); color: var(--ok); }
.pill.offline { background: var(--off-bg); color: var(--muted); }

/* --- Screen page: wide layout for a 1920px monitor ------------------- */
main.wide { max-width: 1880px; padding-top: 1rem; }
.crumb { margin: 0 0 .75rem; }

.summary { padding: 1rem 1.5rem; }
.summary-title { display: flex; align-items: center; gap: .75rem; margin-bottom: .9rem; }
.summary-title h1 { margin: 0; }
.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr)) minmax(380px, 2fr);
  gap: 1rem;
  margin: 0;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .85rem;
  min-width: 0;
}
.stat dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat dt label { margin: 0; font-weight: inherit; }
.stat dd { margin: .2rem 0 0; font-size: 1.15rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat dd.sub { margin-top: .1rem; font-size: .8rem; font-weight: 400; color: var(--muted); }
.summary .hint { margin: .35rem 0 0; }
.stat-url dd { font-size: 1rem; font-weight: 400; flex-wrap: nowrap; }
.stat-url input { flex: 1; min-width: 0; background: var(--card); }
.summary .ua { margin: .75rem 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.screen-layout {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.side { position: sticky; top: 1rem; }
.side .dropzone { min-height: 220px; }
.playlist-card { min-height: 420px; }
.playlist-card .empty { padding: 3rem 0; text-align: center; }

@media (max-width: 1500px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary .ua { white-space: normal; }
  .stat-url { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .screen-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .side .dropzone { min-height: 110px; }
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 110px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 400;
  margin: 0;
}
.dropzone.over { border-color: var(--accent); background: var(--drag-bg); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.upload-progress { list-style: none; padding: 0; margin: .75rem 0 0; }
.upload-progress li { display: flex; gap: .75rem; align-items: center; padding: .2rem 0; flex-wrap: wrap; }
.upload-progress li.error .state { color: var(--danger); }
.upload-progress .name { flex: 1; min-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.playlist { list-style: none; padding: 0; margin: 0; }
.photo {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: .5rem;
  background: var(--card);
}
.photo.dragging { background: var(--drag-bg); border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.photo.disabled .thumb, .photo.disabled .meta { opacity: .45; }
.handle { cursor: grab; touch-action: none; font-size: 1.2rem; padding: .3rem .55rem; border: 0; background: none; color: var(--muted); }
.photo.dragging .handle { cursor: grabbing; }
.pos { width: 1.8rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb { width: 160px; height: 90px; object-fit: cover; border-radius: 4px; background: #000; display: block; }
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duration { margin: 0; font-weight: 400; white-space: nowrap; }
label.duration > input { display: inline-block; width: 5rem; margin: 0; }
.duration input.saved { border-color: var(--ok); }

.danger-zone { border-color: var(--danger); }

/* --- ComfyUI "fit on background" ----------------------------------- */
.badge {
  display: inline-block;
  margin-left: .4rem;
  padding: 0 .45rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--drag-bg);
  color: var(--accent);
  vertical-align: 1px;
}
.photo .fit { white-space: nowrap; }

.fit-dialog {
  width: min(560px, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.fit-dialog::backdrop { background: rgba(0,0,0,.45); }
.fit-dialog .intro { margin-top: 0; }
.fit-progress { list-style: none; padding: 0; margin: 1rem 0; max-height: 45vh; overflow-y: auto; }
.fit-progress li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .45rem .6rem;
  border-bottom: 1px solid var(--border);
}
.fit-progress .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fit-progress .state { flex-shrink: 0; text-align: right; max-width: 60%; }
.fit-progress li.working .state { color: var(--accent); }
.fit-progress li.ok .state { color: var(--ok); }
.fit-progress li.error .state { color: var(--danger); }
.fit-dialog .actions { justify-content: flex-end; }

@media (max-width: 640px) {
  .photo { flex-wrap: wrap; }
  .meta { flex-basis: calc(100% - 200px); }
  .thumb { width: 72px; height: 40px; }
  .stats { grid-template-columns: 1fr 1fr; }
}
