:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a; --text: #e8eaf0; --muted: #8b93a7;
  --accent: #4f8cff; --accent-2: #2f6de0; --danger: #ff6b6b; --ok: #4fd18b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 8px 12px; }
button:hover { background: #262b36; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger-solid { background: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
button.wide { width: 100%; }
button.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; line-height: 1; }
button.pill { border-radius: 999px; padding: 8px 16px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--danger); margin: 8px 0; }

/* layout */
#app { display: flex; height: 100%; }
#sidebar { width: 260px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 8px; overflow: hidden; }
.brand { font-weight: 700; font-size: 16px; padding: 0 6px 6px; }
.side-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 0 6px; }
#folders { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder { display: flex; justify-content: space-between; gap: 8px; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; }
.folder:hover { background: var(--panel2); }
.folder.active { background: rgba(79,140,255,.18); }
.folder .cnt { color: var(--muted); font-variant-numeric: tabular-nums; }
.folder .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#main { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 26px 60px; }

#welcome { max-width: 520px; margin: 12vh auto 0; text-align: center; }
#welcome h1 { margin: 0 0 8px; }
#welcome form { display: flex; gap: 8px; margin-top: 20px; }
#welcome input { flex: 1; }

.lib-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.lib-head h2 { margin: 0; font-size: 22px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.filters select { min-width: 200px; max-width: 100%; }
.filters input { flex: 1; min-width: 200px; }
.bulkbar { position: sticky; top: -22px; z-index: 3; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.channel-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.channel-list:empty { display: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; content-visibility: auto; contain-intrinsic-size: 40px; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel2); }
.row.sel { background: rgba(79,140,255,.14); }
.row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tag { color: var(--muted); font-size: 12px; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row input[type=checkbox] { width: 16px; height: 16px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 50px 10px; }
#sentinel { height: 1px; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form, .dlg-body { padding: 20px; }
dialog h3 { margin: 0 0 12px; }
dialog input[type=text], dialog input:not([type]), dialog input[type=search], dialog select { width: 100%; }
.actions { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 16px; }
.wide-dlg { width: min(860px, calc(100vw - 32px)); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h3 { margin: 0; }
.field { display: block; margin-bottom: 12px; color: var(--muted); }
.field select, .field input { display: block; width: 100%; margin-top: 6px; color: var(--text); }
.seg { display: flex; gap: 16px; margin: 6px 0; color: var(--text); }
.seg label { display: flex; align-items: center; gap: 6px; }
.field .seg input { display: inline-block; width: auto; margin: 0; }
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick-list button { text-align: left; display: flex; justify-content: space-between; }
.imp-tools { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.imp-tools input { flex: 1; }
.imp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.imp-cats, .imp-prev { border: 1px solid var(--line); border-radius: 10px; height: 340px; overflow-y: auto; }
.imp-prev { padding: 8px 10px; }
.cat { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.cat .cn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cat .cn:hover { color: var(--accent); }
.cat .cc { color: var(--muted); font-variant-numeric: tabular-nums; }
.prev-item { padding: 3px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #232834; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 2000; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { border-color: var(--danger); }

/* player */
#player { position: fixed; inset: 0; background: #000; z-index: 1000; color: #fff; user-select: none; }
#video { width: 100%; height: 100%; background: #000; object-fit: contain; }
#player .topbar, #player .bottombar { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 14px 18px; transition: opacity .25s; }
#player .topbar { top: 0; background: linear-gradient(#000c, #0000); }
#player .bottombar { bottom: 0; background: linear-gradient(#0000, #000c); }
#player.idle .topbar, #player.idle .bottombar { opacity: 0; pointer-events: none; }
#player.idle { cursor: none; }
#player button { background: #ffffff22; border-color: #ffffff22; color: #fff; }
#player button:hover { background: #ffffff44; }
.now { min-width: 0; }
.now-name { font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-pos { color: #cbd1e0; font-size: 12px; }
.grow { flex: 1; }
#volume { width: 110px; padding: 0; accent-color: var(--accent); }
.osd { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; pointer-events: none; text-align: center; padding: 0 24px; }
.osd button { pointer-events: auto; }
#osdMsg { background: #000a; padding: 10px 16px; border-radius: 10px; max-width: 80%; }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100%); background: #11141bf2; border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 5; }
.drawer-head { display: flex; gap: 8px; padding: 12px; align-items: center; }
.drawer-head select { flex: 1; min-width: 0; }
.drawer-filters { display: flex; gap: 8px; padding: 0 12px 10px; }
.drawer-filters select { flex: 1; min-width: 0; }
.drawer-filters input { flex: 1; min-width: 0; }
.drawer select, .drawer input { background: #1e222b; color: #fff; }
.drawer-empty { padding: 24px 16px; color: #8b93a7; text-align: center; }
.drawer-list { flex: 1; overflow-y: auto; }
.drawer-item { padding: 10px 14px; cursor: pointer; display: flex; gap: 10px; border-bottom: 1px solid #ffffff10; content-visibility: auto; contain-intrinsic-size: 40px; }
.drawer-item:hover { background: #ffffff14; }
.drawer-item.current { background: rgba(79,140,255,.3); }
.drawer-item .n { color: #8b93a7; font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.drawer-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 800px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; max-height: 46vh; overflow-y: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #main { padding: 16px 14px 60px; }
  .imp-cols { grid-template-columns: 1fr; }
  .imp-cats, .imp-prev { height: 180px; }
  #volume { display: none; }
  .row .tag { display: none; }
}

/* sign-in / invite screens */
#auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.auth-brand { font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.auth-card h2 { margin: 0 0 14px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card form > button { margin-top: 4px; }
.auth-card p { margin: 12px 0 0; }
#acceptIntro { margin: 0 0 16px; }
.button-link { display: inline-block; margin-top: 14px; padding: 9px 14px; border-radius: 8px; background: var(--accent); color: #fff; text-decoration: none; }
.field input[type=email], .field input[type=password], .field input:not([type]) { display: block; width: 100%; margin-top: 6px; color: var(--text); }

/* account block in the sidebar */
.account { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; display: flex; flex-direction: column; gap: 6px; }
.account-email { font-size: 12px; color: var(--muted); padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { padding: 6px 10px; font-size: 13px; }

/* administration */
#admin h3.sub { margin: 22px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.invite-form { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-form input { flex: 1; min-width: 220px; }
.table { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
.table:empty::after { content: 'None'; display: block; padding: 14px; color: var(--muted); }
.trow { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.trow:last-child { border-bottom: 0; }
.trow .who { flex: 1; min-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .meta { color: var(--muted); font-size: 12px; }
.trow .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.trow .acts button { padding: 5px 9px; font-size: 12px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); margin-left: 6px; }
.badge.admin { color: var(--accent); border-color: var(--accent); }
.badge.off { color: var(--danger); border-color: var(--danger); }
#linkInput { width: 100%; font-size: 12px; }

@media (max-width: 800px) {
  #folders { flex: none; max-height: 18vh; }
  .account { flex-direction: row; flex-wrap: wrap; }
  .account-email { flex: 1 0 100%; }
  .account button { flex: 1; width: auto; }
}

/* phone as remote */
.target { min-width: 180px; }
body.has-remote #main { padding-bottom: 96px; }
.remote { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: #121722; border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(0,0,0,.4); }
.remote-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.remote-text { min-width: 0; }
.remote-tv { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remote-now { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remote-btns { display: flex; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #666; flex: none; }
.dot.on { background: var(--ok); }
.tv-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.tv-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.tv-row .tv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-row .tv-meta { color: var(--muted); font-size: 12px; }
.tv-row button { padding: 5px 9px; font-size: 12px; }
.tv-empty { color: var(--muted); padding: 8px 2px; }
