:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #17202b;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
}

/* ---- sidebar ---- */
nav {
  width: 220px; flex-shrink: 0; padding: 20px 14px;
  background: #101828; color: #d0d5dd;
  display: flex; flex-direction: column; gap: 4px;
}
nav .logo {
  font-size: 20px; font-weight: 800; color: #fff; margin: 2px 10px 18px;
  display: flex; align-items: center; gap: 10px;
}
nav .logo .dot { width: 12px; height: 12px; border-radius: 4px; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
nav a {
  color: inherit; text-decoration: none; padding: 9px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; font-weight: 500;
}
nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
nav a.active { background: var(--accent); color: #fff; }
nav .spacer { flex: 1; }
nav .foot { font-size: 12px; color: #667085; padding: 0 12px; }
nav .foot a { display: inline; padding: 0; color: #98a2b3; }

/* ---- main ---- */
main { flex: 1; padding: 28px 34px; overflow-y: auto; min-width: 0; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }

.demo-banner {
  background: linear-gradient(90deg, #4f46e5, #7c3aed); color: #fff;
  padding: 10px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px;
  box-shadow: var(--shadow);
}
.demo-banner a { color: #fff; font-weight: 600; }

/* ---- cards & grids ---- */
.grid { display: grid; gap: 14px; }
.grid.screens { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.media { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}

/* screens */
.screen-card .top { display: flex; align-items: center; gap: 10px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.status-dot.online { background: var(--green); box-shadow: 0 0 6px rgba(22,163,74,.6); }
.screen-card .name { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-card .meta { color: var(--muted); font-size: 13px; margin: 6px 0 12px; min-height: 18px; }
.screen-card .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.screen-card label { font-size: 13px; color: var(--muted); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.sched { background: #ecfdf3; color: var(--green); }

/* media */
.media-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.media-card .thumb {
  aspect-ratio: 16/9; background: #101828 center/cover no-repeat; display: flex;
  align-items: center; justify-content: center; color: #98a2b3; font-size: 30px;
}
.media-card .thumb img, .media-card .thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-card .body { padding: 10px 12px; }
.media-card .name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card .sub { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; margin-top: 2px; }
.media-card .del { border: none; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 8px; }
.media-card .del:hover { color: var(--red); }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center;
  color: var(--muted); margin-bottom: 16px; background: var(--panel); transition: all .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* playlists */
.playlists-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.pl-list { display: flex; flex-direction: column; gap: 6px; }
.pl-list button {
  text-align: left; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font: inherit; font-weight: 500;
}
.pl-list button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pl-items { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pl-item {
  display: flex; gap: 12px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}
.pl-item.dragover { border-color: var(--accent); }
.pl-item .mini {
  width: 76px; aspect-ratio: 16/9; border-radius: 6px; background: #101828 center/cover no-repeat;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #98a2b3;
}
.pl-item .mini img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.pl-item .grow { flex: 1; min-width: 0; }
.pl-item .nm { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item .drag { cursor: grab; color: var(--muted); font-size: 18px; user-select: none; }
.pl-item input[type=number] { width: 64px; }

/* library picker + modals */
dialog {
  border: none; border-radius: 14px; box-shadow: 0 20px 50px rgba(16,24,40,.25);
  padding: 22px; width: min(680px, 92vw); max-height: 86vh;
}
dialog::backdrop { background: rgba(16, 24, 40, 0.5); }
dialog h2 { margin-bottom: 14px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; max-height: 50vh; overflow-y: auto; }
.picker-grid .media-card { cursor: pointer; }
.picker-grid .media-card:hover { outline: 2px solid var(--accent); }

/* schedule editor */
.sched-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.daypick { display: flex; gap: 3px; }
.daypick button {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0;
}
.daypick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- controls ---- */
button.btn, .btn {
  font: inherit; font-weight: 600; font-size: 13.5px; border-radius: 8px; cursor: pointer;
  padding: 8px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { border-color: #c7cdd6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

input[type=text], input[type=url], input[type=time], input[type=number], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); max-width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.empty {
  text-align: center; color: var(--muted); padding: 46px 20px; background: var(--panel);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #101828; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px;
  transition: transform .25s; z-index: 50; box-shadow: var(--shadow);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }

@media (max-width: 760px) {
  body { flex-direction: column; }
  nav { width: 100%; flex-direction: row; align-items: center; padding: 10px; overflow-x: auto; }
  nav .logo { margin: 0 8px 0 4px; }
  nav .spacer, nav .foot { display: none; }
  main { padding: 18px; }
  .playlists-layout { grid-template-columns: 1fr; }
}
