*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  font-size: 0.9rem;
  min-height: 100vh;
}

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.nav-links { display: flex; gap: 0.25rem; list-style: none; }
.nav-links a {
  color: #94a3b8;
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover, .nav-links a.active { color: #fff; background: rgba(255,255,255,0.08); }
.nav-links a.active { color: #fff; }
.navbar .spacer { flex: 1; }
.btn-logout {
  background: none;
  border: 1px solid #334155;
  color: #94a3b8;
  padding: 0.3rem 0.75rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.15s, border-color 0.15s;
}
.btn-logout:hover { color: #fff; border-color: #64748b; }
.nav-user {
  color: #94a3b8;
  font-size: .8rem;
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  transition: color .15s, background .15s;
}
.nav-user:hover { color: #fff; background: rgba(255,255,255,.07); }

/* ── Layout ─────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }

/* ── Stat grid ───────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.stat .value { font-size: 2rem; font-weight: 700; color: #3b82f6; line-height: 1; }
.stat .label { font-size: 0.78rem; color: #64748b; margin-top: 0.35rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.825rem;
  font-weight: 500;
  text-decoration: none;
  transition: filter 0.15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(0.92); }
.btn-primary   { background: #3b82f6; color: #fff; }
.btn-danger    { background: #ef4444; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-sm        { padding: 0.3rem 0.65rem; font-size: 0.775rem; }

/* ── Forms ───────────────────────────────────────────────── */
.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label { font-size: 0.78rem; font-weight: 500; color: #475569; }
input[type=text], input[type=url], input[type=number], input[type=password],
select, textarea {
  padding: 0.45rem 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.875rem;
  color: #1e293b;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
tbody td {
  padding: 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* ── Flash messages ──────────────────────────────────────── */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
}
.flash-ok    { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.flash-error { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ── Pairing code ────────────────────────────────────────── */
.pairing-code {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  display: inline-block;
}
.code-expires { font-size: 0.72rem; color: #64748b; margin-top: 0.2rem; }

/* ── Media grid ──────────────────────────────────────────── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.media-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.media-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: #1e293b;
}
.media-thumb-video {
  width: 100%;
  aspect-ratio: 16/9;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 2rem;
}
.media-info {
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}
.media-name { font-size: 0.78rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
}
.login-card {
  background: #1e293b;
  border-radius: 12px;
  padding: 2rem 2.25rem;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-card h1 { color: #f8fafc; font-size: 1.3rem; margin-bottom: 0.4rem; }
.login-card .subtitle { color: #64748b; font-size: 0.8rem; margin-bottom: 1.5rem; }
.login-card label { color: #94a3b8; font-size: 0.78rem; font-weight: 500; display: block; margin-bottom: 0.25rem; }
.login-card input {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  color: #f8fafc;
  margin-bottom: 1rem;
}
.login-card input:focus { border-color: #3b82f6; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 0.6rem; font-size: 0.9rem; }
.login-error {
  background: #450a0a;
  border: 1px solid #7f1d1d;
  color: #fca5a5;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  margin-bottom: 1rem;
}

/* ── Page heading ────────────────────────────────────────── */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; }
.page-header p { color: #64748b; font-size: 0.8rem; margin-top: 0.2rem; }

/* ── Playlist items ──────────────────────────────────────── */
.item-badge { width: 24px; height: 24px; border-radius: 50%; background: #e2e8f0; color: #64748b; display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; }

/* ── Empty state ─────────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1rem; color: #94a3b8; }
.empty p { margin-top: 0.5rem; font-size: 0.85rem; }

/* ── Playlist Editor ─────────────────────────────────────── */
.pe-editor { display: flex; flex-direction: column; }

.pe-top {
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  height: 420px;
  border: 1px solid #e2e8f0;
  border-radius: 10px 10px 0 0;
  overflow: hidden;
  background: #fff;
}

.pe-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e2e8f0;
  overflow: hidden;
  min-width: 0;
}
.pe-panel:last-child { border-right: none; }

.pe-panel-header {
  padding: 0.55rem 0.9rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #64748b;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Library */
.pe-lib-scroll { flex: 1; overflow-y: auto; padding: 0.6rem; }
.pe-lib-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45rem; }
.pe-lib-empty { color: #94a3b8; font-size: 0.82rem; padding: 1rem; text-align: center; }

.pe-lib-card {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
  min-width: 0;
}
.pe-lib-card:hover { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.pe-lib-card--selected { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }

.pe-lib-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  background: #1e293b;
}
.pe-lib-thumb--icon {
  width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  color: #475569;
  font-size: 1.3rem;
}
.pe-lib-info { padding: 0.35rem 0.45rem 0.4rem; }
.pe-lib-name {
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.3rem;
  color: #1e293b;
}
.pe-lib-actions { display: flex; align-items: center; justify-content: space-between; }
.pe-add-btn {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: none;
  background: #3b82f6;
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.pe-add-btn:hover { background: #2563eb; }

/* Preview */
.pe-panel--preview { background: #0f172a; }
.pe-panel--preview .pe-panel-header { background: #1e293b; border-color: #334155; color: #64748b; }
.pe-preview-area { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 0.75rem; }
.pe-preview-empty { color: #475569; font-size: 0.82rem; text-align: center; line-height: 1.5; }
.pe-preview-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.pe-preview-video { max-width: 100%; max-height: 100%; border-radius: 4px; background: #000; }
.pe-preview-pdf { width: 100%; height: 100%; border: none; border-radius: 4px; }

/* Config */
.pe-config-area { flex: 1; overflow-y: auto; padding: 0.8rem; }
.pe-config-empty { color: #94a3b8; font-size: 0.82rem; padding: 0.5rem 0; line-height: 1.5; }
.pe-cfg { display: flex; flex-direction: column; gap: 0.85rem; }
.pe-cfg-name { font-size: 0.88rem; font-weight: 600; word-break: break-all; color: #1e293b; }
.pe-cfg-section { display: flex; flex-direction: column; gap: 0.3rem; }
.pe-cfg-label { font-size: 0.68rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }
.pe-cfg-dur-row { display: flex; gap: 0.4rem; align-items: center; }
.pe-cfg-dur-row input { flex: 1; min-width: 0; }
.pe-cfg-pos-btns { display: flex; gap: 0.35rem; }
.pe-cfg-pos-btns .btn { flex: 1; justify-content: center; }
.pe-cfg-remove { border-top: 1px solid #f1f5f9; padding-top: 0.85rem; margin-top: 0.2rem; }
.pe-cfg-remove .btn { width: 100%; justify-content: center; }

/* Timeline */
.pe-timeline-wrap {
  background: #1e293b;
  border: 1px solid #334155;
  border-top: none;
  border-radius: 0 0 10px 10px;
}
.pe-timeline-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.9rem;
  border-bottom: 1px solid #334155;
}
.pe-timeline-bar span { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: #64748b; }
.pe-timeline {
  display: flex; gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  overflow-x: auto;
  min-height: 124px;
  align-items: flex-start;
}
.pe-timeline::-webkit-scrollbar { height: 5px; }
.pe-timeline::-webkit-scrollbar-track { background: #1e293b; }
.pe-timeline::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
.pe-tl-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #475569; font-size: 0.8rem; text-align: center; min-height: 90px;
}
.pe-tl-item {
  flex-shrink: 0; width: 104px;
  background: #334155; border: 1.5px solid #475569;
  border-radius: 7px; overflow: hidden;
  cursor: pointer; user-select: none;
  transition: border-color 0.12s;
}
.pe-tl-item:hover { border-color: #93c5fd; }
.pe-tl-item--selected { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.3); }
.pe-tl-item--dragging { opacity: 0.45; transform: scale(0.97); }
.pe-tl-item--drag-over { border-color: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.3); }
.pe-tl-thumb {
  width: 100%; aspect-ratio: 16/9;
  object-fit: cover; display: block; background: #0f172a;
}
.pe-tl-thumb--icon {
  width: 100%; aspect-ratio: 16/9;
  display: flex; align-items: center; justify-content: center;
  background: #0f172a; color: #475569; font-size: 1.1rem;
}
.pe-tl-info { padding: 0.3rem 0.45rem 0.35rem; display: flex; flex-direction: column; gap: 0.1rem; }
.pe-tl-pos { font-size: 0.62rem; color: #64748b; font-weight: 700; }
.pe-tl-name { font-size: 0.68rem; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.pe-tl-dur { font-size: 0.62rem; color: #94a3b8; }
