:root {
  --bg: #ffffff;
  --bg-sunken: #f8f9fa;
  --bg-raised: #ffffff;
  --bg-hover: #f1f3f4;
  --bg-selected: #e8f0fe;
  --border: #dadce0;
  --border-soft: #e8eaed;
  --text: #202124;
  --text-muted: #5f6368;
  --text-faint: #80868b;
  --accent: #1a73e8;
  --accent-hover: #1b66c9;
  --accent-soft: #e8f0fe;
  --danger: #d93025;
  --success: #1e8e3e;
  --warning: #e37400;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
  --shadow-2: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  --radius: 8px;
  --radius-lg: 16px;
  --sidebar-w: 256px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1f;
    --bg-sunken: #131314;
    --bg-raised: #2a2a2a;
    --bg-hover: #303134;
    --bg-selected: #1f3a5f;
    --border: #3c4043;
    --border-soft: #2f3134;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --text-faint: #7d8085;
    --accent: #8ab4f8;
    --accent-hover: #a8c7fa;
    --accent-soft: #1f3a5f;
    --danger: #f28b82;
    --success: #81c995;
    --warning: #fdd663;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .6), 0 1px 3px 1px rgba(0, 0, 0, .3);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, .6), 0 4px 8px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* Class-level display rules would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Google Sans", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--accent); }

.icon { width: 20px; height: 20px; flex: none; fill: currentColor; }
.icon-sm { width: 16px; height: 16px; flex: none; fill: currentColor; }

/* ------------------------------------------------------------------ login */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  background: var(--bg-sunken);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-1);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 400;
}

.login-card .sub {
  margin: 0 0 28px;
  color: var(--text-muted);
}

.field { margin-bottom: 18px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 24px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  .btn-primary { color: #202124; }
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.error-msg {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 13px;
}

.error-msg:empty { display: none; }

/* ------------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas: "brand top" "side main";
  height: 100%;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--bg-sunken);
  font-size: 20px;
  color: var(--text-muted);
}

.brand strong { font-weight: 400; color: var(--text); }

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px 0 8px;
  background: var(--bg-sunken);
}

.search {
  flex: 1;
  max-width: 720px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 48px;
  border-radius: 24px;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.search input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 500;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) { .avatar { color: #202124; } }

.sidebar {
  grid-area: side;
  padding: 0 12px 16px;
  overflow-y: auto;
}

.new-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px 4px;
  padding: 14px 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: var(--shadow-1);
  font-size: 14px;
  font-weight: 500;
}

.new-btn:hover { box-shadow: var(--shadow-2); background: var(--bg-hover); }

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  border-radius: 0 20px 20px 0;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--bg-selected); color: var(--accent); font-weight: 500; }
.tree-item.drop-target { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -2px; }
.tree-item .label { overflow: hidden; text-overflow: ellipsis; }

.twisty {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex: none;
  color: var(--text-muted);
  transition: transform .15s;
}

.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }

.storage {
  margin: 20px 12px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-size: 13px;
}

.meter {
  height: 4px;
  margin: 10px 0 8px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.meter > div { height: 100%; background: var(--accent); }

/* ------------------------------------------------------------------- main */

.main {
  grid-area: main;
  background: var(--bg);
  border-radius: var(--radius-lg) 0 0 0;
  border-top: 1px solid var(--border-soft);
  border-left: 1px solid var(--border-soft);
  padding: 20px 24px;
  overflow-y: auto;
  position: relative;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  font-size: 22px;
  font-weight: 400;
  flex-wrap: wrap;
}

.crumbs button {
  padding: 4px 8px;
  border-radius: var(--radius);
  color: var(--text);
}

.crumbs button:hover { background: var(--bg-hover); }
.crumbs .sep { color: var(--text-faint); }
.crumbs .current { color: var(--text); cursor: default; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.chip:hover { background: var(--bg-hover); }
.chip.on { background: var(--bg-selected); border-color: transparent; color: var(--accent); }
.chip.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.spacer { flex: 1; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-muted);
}

.icon-btn:hover { background: var(--bg-hover); }
.icon-btn.on { background: var(--bg-selected); color: var(--accent); }

.section-label {
  margin: 18px 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg-raised);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: background .1s, box-shadow .1s;
}

.card:hover { background: var(--bg-hover); }
.card.selected { background: var(--bg-selected); border-color: var(--accent); }
.card.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  font-weight: 500;
  overflow: hidden;
}

.card-head .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  height: 112px;
  display: grid;
  place-items: center;
  background: var(--bg-sunken);
  border-top: 1px solid var(--border-soft);
  color: var(--text-faint);
  position: relative;
}

.card-body .big { width: 44px; height: 44px; opacity: .55; }

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.badge.ready { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.busy { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge.fail { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ------------------------------------------------------------------ list */

.list { width: 100%; border-collapse: collapse; }

.list th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
}

.list td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}

.list tr { cursor: pointer; user-select: none; }
.list tbody tr:hover { background: var(--bg-hover); }
.list tr.selected { background: var(--bg-selected); }
.list tr.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

.list .cell-name { display: flex; align-items: center; gap: 12px; }
.list .num { text-align: right; color: var(--text-muted); width: 120px; }
.list .when { color: var(--text-muted); width: 180px; }
.list .state { width: 140px; }

.empty {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 80px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty .big { width: 56px; height: 56px; opacity: .4; }

/* ---------------------------------------------------------------- dialogs */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(32, 33, 36, .5);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}

.dialog {
  width: 100%;
  max-width: 440px;
  background: var(--bg-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 24px;
}

.dialog h2 { margin: 0 0 16px; font-size: 18px; font-weight: 400; }
.dialog p { margin: 0 0 16px; color: var(--text-muted); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.btn-text {
  padding: 9px 20px;
  border-radius: 18px;
  color: var(--accent);
  font-weight: 500;
}

.btn-text:hover { background: var(--accent-soft); }
.btn-text.danger { color: var(--danger); }
.btn-text.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.menu {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: 8px 0;
  background: var(--bg-raised);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 9px 18px;
  text-align: left;
  color: var(--text);
}

.menu button:hover { background: var(--bg-hover); }
.menu button.danger { color: var(--danger); }
.menu .divider { height: 1px; margin: 6px 0; background: var(--border-soft); }

/* ---------------------------------------------------------------- dropzone */

.dropzone {
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  display: grid;
  place-items: center;
  gap: 8px;
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  z-index: 30;
}

/* ---------------------------------------------------------------- activity */

.activity {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow-2);
  z-index: 35;
  overflow: hidden;
}

.activity header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-hover);
  font-weight: 500;
}

.activity .rows { overflow-y: auto; }

.activity-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.activity-row .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-row .sub {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 12px;
}

.bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.bar > div {
  height: 100%;
  background: var(--accent);
  transition: width .3s;
}

.bar.fail > div { background: var(--danger); }
.bar.ok > div { background: var(--success); }

/* ------------------------------------------------------------------ toast */

.toasts {
  position: fixed;
  left: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  padding: 14px 18px;
  border-radius: var(--radius);
  background: #323232;
  color: #fff;
  box-shadow: var(--shadow-2);
  max-width: 420px;
}

.toast.error { background: var(--danger); }

/* ----------------------------------------------------------------- player */

.player-page {
  min-height: 100%;
  background: #0d0d0f;
  color: #e8eaed;
  display: flex;
  flex-direction: column;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
}

.player-bar .title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar a { color: #8ab4f8; text-decoration: none; display: flex; align-items: center; gap: 6px; }

.player-wrap { flex: 1; display: grid; place-items: center; padding: 0 20px 24px; }
.player-wrap video { width: 100%; max-width: 1280px; max-height: 78vh; background: #000; border-radius: 10px; }

.quality {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 16px;
  background: #ffffff14;
  font-size: 13px;
}

.quality select { background: none; border: none; color: inherit; outline: none; }
.quality select option { background: #2a2a2a; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .brand, .sidebar { display: none; }
  .activity { right: 0; left: 0; width: auto; }
}

/* ------------------------------------------------------------------ admin */

.admin-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.admin-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 6px;
}

.admin-head h1 { margin: 0; font-size: 24px; font-weight: 400; }
.admin-head a { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }

.admin-sub { margin: 0 0 24px; color: var(--text-muted); }

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 500;
}

.keys { width: 100%; border-collapse: collapse; }

.keys th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.keys td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.keys tr:last-child td { border-bottom: none; }

.keys .label-cell { font-weight: 500; }
.keys .muted { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

.keyval {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  max-width: 260px;
}

.keyval code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex: none;
  color: var(--text-muted);
}

.mini:hover { background: var(--bg-hover); color: var(--text); }
.mini.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  background: var(--bg-hover);
  color: var(--text-muted);
  white-space: nowrap;
}

.pill.live { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.pill.dead { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.hint {
  margin: 18px 0 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  word-break: break-all;
}

.field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
}

.share-url {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
