/* Pico CSS (vendored at static/vendor/pico.min.css) is loaded before this
   file; its light-theme variables are re-themed below. */
/* Theme tokens (§13.26). The active theme is chosen with
   <html data-theme="dark|light"> (Pico v2's own mechanism); the app-level --*
   tokens below are re-defined per theme so every surface generalizes. */
:root {
  /* Layout-only tokens (theme-independent). */
  --sidebar-w: 15rem;
  --sidebar-w-collapsed: 5rem;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171b22;
  --panel-2: #1a2130;
  --text: #e6e8ee;
  --muted: #9aa4b2;
  --accent: #4f8cff;
  --border: #232936;
  --border-strong: #3a4258;
  --hover: #202733;
  --active: #232b3a;
  --input-bg: #0d1016;
  --input-border: #2a3242;
  --bar-bg: #222a38;
  --btn-ghost-bg: #1e2533;
  --btn-ghost-hover: #252f40;
  --overlay: #12161f;
  --log-bg: #0a0c10;
  --warn-fg: #ffd479;
  --log-info: #9aa4b2;
  --log-debug: #6b7280;
  --log-warn: #fbbf24;
  --log-error: #f87171;
  --flash-success-bg: #12351f; --flash-success-fg: #8ef0a0;
  --flash-error-bg: #3a1518;  --flash-error-fg: #ff9a9a;
  --flash-info-bg: #12233a;   --flash-info-fg: #9cc3ff;
  /* Message-notification red dot (§21): chip + panel rows. */
  --notify-dot: #ff6b6b;
  /* Pico dark-theme overrides */
  --pico-background-color: #0f1115;
  --pico-card-background-color: #171b22;
  --pico-primary: #4f8cff;
  --pico-form-element-background-color: #0d1016;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #eaeef4;
  --text: #1b2330;
  --muted: #5a6472;
  --accent: #2f6fe0;
  --border: #d6dce6;
  --border-strong: #aab4c5;
  --hover: #e7ebf2;
  --active: #d3e0f5;
  --input-bg: #ffffff;
  --input-border: #c2cad6;
  --bar-bg: #dfe4ec;
  --btn-ghost-bg: #eef1f6;
  --btn-ghost-hover: #dde3ee;
  --overlay: #ffffff;
  --log-bg: #f4f6f9;
  --warn-fg: #a8720a;
  --log-info: #5a6472;
  --log-debug: #8a94a3;
  --log-warn: #b45309;
  --log-error: #dc2626;
  --flash-success-bg: #d7f2e2; --flash-success-fg: #157347;
  --flash-error-bg: #fbe0e4;  --flash-error-fg: #b4232f;
  --flash-info-bg: #dbe8fb;   --flash-info-fg: #1d5fc0;
  /* Message-notification red dot (§21): chip + panel rows. */
  --notify-dot: #dc2626;
  /* Pico light-theme overrides */
  --pico-background-color: #eef1f6;
  --pico-card-background-color: #ffffff;
  --pico-primary: #2f6fe0;
  --pico-form-element-background-color: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Pico's default type scale is too large for this app — shrink it. */
/* Proportional sizing (§13.26): the root font scales with viewport width so the
   whole rem-based UI (Pico + this app) grows on high-resolution screens. */
html { font-size: clamp(13px, 0.2vw + 12px, 22px); }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
/* Watch-page video title: larger than a generic h1 for readability (§13.33). */
.watch-title { font-size: 1.6rem; font-weight: 700; line-height: 1.25; margin: 0 0 14px; }
/* Watch page: the video's tag pills under the title (§16.17). Reuses the home
   card pill (.card__tag) for a consistent look; the negative top margin tightens
   the gap so the pills read as a subtitle. */
.watch-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: -8px 0 14px; }
p { font-size: 0.95rem; }
input, select, textarea { font-size: 0.9rem; padding: 0.45em 0.7em; }
input[type="file"] { font-size: 0.85rem; }
button, .btn { font-size: 0.85rem; }
table { font-size: 0.88rem; }
.table td { padding: 0.5em 0.7em; }
.table th { padding: 0.5em 0.7em; }

/* ===== Layout: fixed sidebar (desktop) / off-canvas drawer (mobile) ===== */
.topbar { display: none; }
.topbar__menu {
  background: none; border: none; color: var(--text);
  font-size: 1.4rem; line-height: 1; padding: 6px 10px; cursor: pointer;
}
.topbar__menu svg { width: 22px; height: 22px; display: block; }
.brand { color: var(--text); text-decoration: none; font-weight: 700; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 8px 10px;
  overflow-y: auto;
  z-index: 50;
  transition: width 0.2s ease;
  display: flex;
  flex-direction: column;
}
.sidebar__toggle {
  display: block; width: 100%;
  background: none; border: none; color: var(--muted);
  font-size: 1.1rem; padding: 8px 12px; margin-bottom: 4px;
  border-radius: 8px; cursor: pointer;
}
.sidebar__toggle svg { width: 1.125rem; height: 1.125rem; display: block; margin: 0 auto; }
.sidebar__toggle:hover { background: var(--hover); color: var(--text); }
.sidebar__brand { padding: 14px 12px 10px; font-size: 1rem; }
.sidebar__brand a { color: var(--text); text-decoration: none; font-weight: 700; }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }
.sidebar__item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem;
}
.sidebar__item .icon { flex: 0 0 1.5rem; display: inline-flex; align-items: center; justify-content: center; }
.sidebar__item .icon svg { width: 1.5rem; height: 1.5rem; display: block; }
.sidebar__item:hover { background: var(--hover); color: var(--text); }
.sidebar__item.is-active { background: var(--active); color: var(--text); font-weight: 600; }
.sidebar__item--out { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
/* Sidebar theme toggle (§13.26): a nav-style button that flips light/dark. */
.sidebar__theme-toggle {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem;
  background: none; border: none; cursor: pointer;
  width: 100%; font-family: inherit; text-align: left;
}
.sidebar__theme-toggle .icon { flex: 0 0 1.5rem; display: inline-flex; align-items: center; justify-content: center; }
.sidebar__theme-toggle .icon svg { width: 1.5rem; height: 1.5rem; display: block; }
.sidebar__theme-toggle:hover { background: var(--hover); color: var(--text); }
/* Bottom-left account + logout group (the avatar replaces the Account icon). */
.sidebar__footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__avatar {
  width: 2.5rem; height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
/* The Account item's icon slot widens to match the larger avatar. */
.sidebar__item:has(.sidebar__avatar) .icon { flex: 0 0 2.5rem; }

/* Collapsed (icon-only) state, YouTube-style. */
.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); padding: 8px 6px; }
.sidebar-collapsed .sidebar__brand,
.sidebar-collapsed .sidebar__item .label,
.sidebar-collapsed .sidebar__theme-toggle .label { display: none; }
.sidebar-collapsed .sidebar__item,
.sidebar-collapsed .sidebar__theme-toggle { justify-content: center; padding: 9px 0; }
.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.sidebar-overlay { display: none; }

@media (max-width: 860px) {
  .topbar {
    display: flex; align-items: center; gap: 6px;
    position: sticky; top: 0; z-index: 60;
    background: var(--panel); border-bottom: 1px solid var(--border);
    padding: 6px 10px;
  }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay {
    display: block; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5); z-index: 45;
  }
  .main { margin-left: 0; }
  /* The collapsed-rail state is a desktop concept; the mobile drawer stays wide. */
  .sidebar-collapsed .main { margin-left: 0; }
  .sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  .sidebar-collapsed .sidebar__brand,
  .sidebar-collapsed .sidebar__item .label,
  .sidebar-collapsed .sidebar__theme-toggle .label { display: block; }
  .sidebar-collapsed .sidebar__item,
  .sidebar-collapsed .sidebar__theme-toggle { justify-content: flex-start; padding: 9px 12px; }
}

.container { max-width: 92rem; width: 100%; margin: 0 auto; padding: 1.25rem; flex: 1 1 auto; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.hidden { display: none; }
/* The `hidden` attribute must win over any author `display` (pin badge, home
   filter, etc.), so it is force-hidden regardless of element display. */
[hidden] { display: none !important; }

/* Avatar borders (§16.5): a thin visible frame on every user avatar, so faces
   read clearly on any background. Applied to all avatar <img> selectors.
   (.card__avatar is excluded — §20 gives it its own 3 px border + shadow.) */
.sidebar__avatar,
.comment__avatar,
.avatar-lg,
.video-author__avatar,
.live-view__avatar,
.notify-row__avatar {
  border: 1.5px solid var(--border-strong);
}

.auth-card {
  max-width: 360px; margin: 40px auto; background: var(--panel);
  padding: 24px; border-radius: 10px;
}
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; }
input, button, select {
  font: inherit; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text);
}
button { background: var(--accent); color: #fff; cursor: pointer; }
button:hover { filter: brightness(1.1); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.flash--success { background: var(--flash-success-bg); color: var(--flash-success-fg); }
.flash--error { background: var(--flash-error-bg); color: var(--flash-error-fg); }
.flash--info { background: var(--flash-info-bg); color: var(--flash-info-fg); }

/* Waterfall (masonry): a CSS grid so cards fill left-to-right, top-to-bottom
   (row-major). CSS multi-column (the previous `column-count`) filled
   top-to-bottom then left-to-right (column-major), which is not the reading
   order users expect and also scrambled the server-side pinned-first order.
   Cards are uniform height (16:9 cover + 1-line title + 1-line meta), so a grid
   is visually equivalent to masonry while preserving DOM order. */
.waterfall {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 900px) { .waterfall { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .waterfall { grid-template-columns: repeat(2, 1fr); } }
.card {
  display: block;
  background: var(--panel); border-radius: 8px; overflow: hidden;
  text-decoration: none; color: var(--text);
  position: relative;
}
.card__cover {
  width: 100%; display: block; aspect-ratio: 16 / 9; object-fit: cover;
  /* Data-first (§15.7): a neutral placeholder shows the instant the card's data
     paints; the cover fades in (.is-loaded on onload) once it is decoded. The
     fixed 16/9 box means the waterfall never reflows as covers arrive. */
  background: var(--panel-2); opacity: 0; transition: opacity 0.3s ease;
}
.card__cover.is-loaded { opacity: 1; }
/* Cover wrapper (§20.2): the containing block for the comment badge, so the
   badge's right/bottom offsets mean the *cover's* bottom-right corner (not
   the card's) on every home/folder video card. */
.card__cover-wrap { position: relative; }
.card__title { padding: 4px 10px 0; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 10px 0; }
.card__tag {
  font-size: 0.68rem; padding: 1px 7px; border-radius: 999px;
  background: var(--color-surface-2, #e7e9f1); color: var(--color-text-muted, #5b6472);
}
/* Shared tag chip input (§16.14 follow-up). Selected tags show as accent pills
   with a remove control; a trailing text field adds more (taginput.js). */
.tag-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-input__chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 0.8rem; color: var(--text);
}
.tag-input__label { white-space: nowrap; }
.tag-input__remove {
  border: none; cursor: pointer; font-size: 1rem; line-height: 1;
  padding: 0 7px; border-radius: 999px;
  background: transparent; color: var(--text);
}
.tag-input__remove:hover { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.tag-input__field {
  flex: 1 1 140px; min-width: 120px;
  border: none; outline: none; background: transparent;
  font-size: 0.8rem; color: var(--text); padding: 3px 2px;
}
.tag-input__field::placeholder { color: var(--muted); }
/* Uploader row (§20 follow-up): the 64 px avatar is pulled up over the cover's
   bottom edge (its lower half overlaps the cover). The name is aligned to the
   row's bottom (align-items: flex-end) so it sits entirely below the cover's
   bottom edge and never covers the cover. */
.card__author {
  position: relative;
  z-index: 2;
  margin-top: -32px;
  padding: 0 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.card__avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
  border: 3px solid var(--border-strong);
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.card__owner { font-size: 1rem; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__meta {
  padding: 4px 10px 8px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.card__date { flex: 0 0 auto; }

/* Pinned badge (§16.6): a small pin marker over a pinned video card's cover. */
.card__pin {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #ffd24d;
  font-size: 0.72rem;
  font-weight: 600;
  z-index: 1;
}
.card__pin svg { width: 12px; height: 12px; }
/* Remote badge (§16.4): marks a home card whose video is NOT cached locally
   (it lives on Google Drive and must be downloaded before it can play). */
.card__remote {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #9cc3ff;
  font-size: 0.72rem;
  font-weight: 600;
  z-index: 1;
}
.card__remote svg { width: 12px; height: 12px; }
/* Comment-count badge (§20.2): same capsule as the Remote badge, anchored to
   the bottom-right of the cover image on every card (its containing block is
   the .card__cover-wrap, not the card); Pinned (top-left) and Remote
   (top-right) never collide with it, so no pinned-card fallback is needed.
   Hidden for 0-comment videos. */
.card__comments {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #e6e8ee;
  font-size: 0.72rem;
  font-weight: 600;
  z-index: 1;
}
.card__comments svg { width: 12px; height: 12px; }
/* Inline "Pinned" pill, reused anywhere a pinned video is listed (e.g. admin). */
.pin-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #4d3a10;
  color: #ffd24d;
  font-size: 0.72rem;
  font-weight: 600;
}

/* Home filter/sort toolbar (§16.4). */
.home-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--panel);
  border-radius: 10px;
}
.home-toolbar__search { flex: 1 1 220px; }
.home-toolbar input, .home-toolbar select { height: 40px; }
.home-toolbar .field { margin-bottom: 0; flex: 0 1 auto; }
.home-toolbar__label { font-size: 0.82rem; color: var(--muted); }

/* Folder cards on the home page (§13.26): a folder is a full-size cell in the
   waterfall, the same size as a video card — the cover area is a folder glyph
   and the title is the folder name. The base card layout comes from .card
   (applied via the template's class="card folder-card"). */
.folder-card:hover { background: var(--hover); }
.folder-card__cover {
  width: 100%; aspect-ratio: 16 / 9;
  display: flex; align-items: center; justify-content: center;
  background: var(--active); color: var(--accent);
}
.folder-card__cover svg { width: 44px; height: 44px; }
.folder-card__title {
  padding: 8px 10px 58px; font-size: 1rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* The 58 px bottom padding keeps a folder cell the same total height as a
   tag-less video cell (§20 follow-up): the redesigned video body now
   contributes 32 px (64 px avatar minus its 32 px cover overlap, up from 24 px
   at the 48 px era) + title line + date row. The 8 px growth over the
   48 px-era value keeps folder cells level with tag-less video cells.
   X = 58 px is a best-fit: the root font size is still the viewport clamp
   (13–22 px), so no single X is exact for every viewport and the owner's
   browser pass is the final check. */

/* Breadcrumb trail (§13.26). */
.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-bottom: 14px; font-size: 0.88rem;
}
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb__sep { color: var(--muted); }
.breadcrumb__current { color: var(--text); font-weight: 600; }

/* Nested folder tree on the My Videos page (§13.26). Each folder is a row with
   an inline rename form, a delete form, and an add-subfolder form. */
.folder-tree, .folder-tree ul { list-style: none; margin: 0; }
.folder-tree ul { padding-left: 22px; }
.folder-tree .folder-tree__row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.folder-tree form { display: flex; align-items: center; gap: 6px; }
.folder-tree .folder-rename { flex: 1; }
.folder-tree .folder-rename input { flex: 1; }
.folder-tree .folder-add-sub input { width: 120px; }
.folder-tree .btn { width: auto; flex: 0 0 auto; }

.bar { background: var(--bar-bg); border-radius: 6px; overflow: hidden; height: 14px; }
.bar__fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.table { border-collapse: collapse; width: 100%; }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; }
/* Horizontal scroll wrapper so wide tables stay usable on mobile. */
.table-wrap { overflow-x: auto; }

/* Player wrapper: rounded corners + shadow live here so the fullscreen button
   can overlay the video without clipping. */
.player-wrap {
  position: relative;
  margin: 0 0 12px;
  /* Carry the aspect ratio on this NON-REPLACED wrapper, not on the <video>.
     width:100% + aspect-ratio gives the wrapper a definite height for ANY ratio
     (16/9 is the pre-metadata fallback), so the box is never 0px tall while the
     media's metadata loads. The player fills it via width/height:100%, so the box
     always matches the video with no left/right bars (§13.32). applyRatio() in
     watch.html updates this to the exact videoWidth/videoHeight on loadedmetadata. */
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
/* DPlayer container (§13.39): fills .player-wrap (which carries the
   aspect-ratio). DPlayer builds .dplayer > .dplayer-video-wrap > <video>, each
   width/height:100%, so a definite height on #dplayer is all it needs. */
#dplayer {
  width: 100%;
  height: 100%;
  background: #000;
}
#caching-status { color: var(--warn-fg); font-weight: 600; margin: 8px 0; }

/* Non-cached video: confirmation + download progress panel (§13.33). */
.cache-panel {
  margin: 0 0 12px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
.cache-panel__body { max-width: 560px; }
.cache-panel__msg { margin: 0 0 16px; line-height: 1.5; }
.cache-panel__actions { display: flex; gap: 10px; }
.cache-panel__bar {
  height: 10px;
  border-radius: 6px;
  background: var(--border);
  overflow: hidden;
  margin: 10px 0;
}
.cache-panel__fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.cache-panel__error { color: #e05a5a; margin: 8px 0 0; }

/* (video.js player + custom in-page fullscreen button CSS removed — the watch
   page now uses DPlayer with its built-in controls and native fullscreen, §13.39.) */

/* ===== In-page fullscreen overlay (§13.26) ===== */
/* A fixed, page-level overlay used by the watch page and the upload clip panel.
   Unlike the Fullscreen API it keeps the browser chrome visible, so it is a
   simple fixed element covering the viewport. inpage.js moves the player
   element into the stage and back. */
.inpage-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--overlay);
  display: none;
}
.inpage-overlay.is-active { display: block; }
.inpage-overlay__stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Applied to the player element while it lives in the overlay. */
.inpage-overlay__fill {
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: auto !important;
  border-radius: 0 !important;
}
.inpage-overlay__fill:not(.upload-timeline) video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  background: #000;
}
.inpage-overlay__exit {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  z-index: 2001;
}
.inpage-overlay__exit:hover { background: rgba(0, 0, 0, 0.8); }
.inpage-overlay__exit svg { width: 22px; height: 22px; }

/* ===== Upload page ===== */
.upload-page { max-width: none; }
.upload-page h1 { font-size: 1.5rem; margin-bottom: 20px; }
.upload-input--narrow { max-width: 120px; }

.upload-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 60px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 20px;
}
.upload-dropzone:hover { border-color: var(--accent); background: var(--hover); }
.upload-dropzone.drag-over { border-color: var(--accent); background: var(--active); }
.upload-dropzone.has-file { border-style: solid; border-color: #2a5a3a; }

.upload-dropzone__icon { color: var(--muted); margin-bottom: 4px; }
.upload-dropzone__text { font-size: 1.05rem; margin: 0; }
.upload-dropzone__hint { font-size: 0.9rem; color: var(--muted); margin: 0; }
.upload-dropzone__btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 999px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}
.upload-dropzone__btn:hover { filter: brightness(1.15); }
.upload-dropzone__filename { font-size: 0.9rem; color: var(--text); margin-top: 8px; }
.upload-dropzone__meta { font-size: 0.8rem; color: var(--muted); }

.upload-section { margin-bottom: 18px; }
.upload-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.upload-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
}
.upload-input:focus { outline: none; border-color: var(--accent); }

.upload-cover {
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-cover__img {
  max-height: 72px;
  max-width: 128px;
  border-radius: 6px;
  object-fit: cover;
}
.upload-cover__btn {
  background: var(--btn-ghost-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
.upload-cover__btn:hover { background: var(--btn-ghost-hover); }

.upload-clip {
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-clip__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upload-clip__field span { font-size: 0.8rem; color: var(--muted); }
.upload-clip__input {
  width: 80px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  text-align: center;
}
.upload-clip__apply {
  background: var(--input-border);
  color: var(--text);
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}
.upload-clip__apply:hover { background: var(--btn-ghost-hover); }

.upload-progress-bar { height: 10px; border-radius: 6px; }
.upload-progress-status { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.upload-progress-speed {
  font-size: 0.85rem;
  color: var(--text);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
/* Multi-file queue (main upload page). Each row shows a video's name, size,
   and live status; the shared progress panel above shows the current file's bar. */
.upload-queue { display: flex; flex-direction: column; gap: 6px; }
.upload-queue:empty { display: none; }
.upload-queue__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--bar-bg, rgba(127, 127, 127, 0.3));
  border-radius: 6px;
}
.upload-queue__name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-queue__meta { flex: 0 0 auto; font-size: 0.85rem; }
.upload-queue__status { flex: 0 0 auto; text-align: right; min-width: 130px; font-size: 0.85rem; }
.upload-queue__status--error { color: var(--log-error, #c0392b); }
.upload-warning {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.5);
  color: var(--log-warn);
  font-size: 0.85rem;
  line-height: 1.4;
}
.upload-warning.upload-warning--error {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.5);
  color: var(--log-error);
}

/* Success screen (§13.18): full-page overlay shown after the server has the
   file, while the background worker uploads it to Google Drive. */
.upload-success {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.upload-success__card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.upload-success__icon { color: #34d399; }
.upload-success__icon svg { width: 56px; height: 56px; }
.upload-success__title { font-size: 1.25rem; margin: 0; }
.upload-success__text {
  font-size: 0.95rem;
  color: var(--text);
  margin: 0;
  line-height: 1.5;
}
.upload-success__count {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.upload-success__btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.upload-success__btn:hover { filter: brightness(1.15); }
/* Must beat .hidden (earlier in the file) — the overlay is hidden by default. */
.upload-success.hidden { display: none; }

.upload-log-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.upload-log-panel__clear {
  background: var(--btn-ghost-hover);
  color: var(--muted);
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.upload-log-panel__clear:hover {
  background: var(--active);
  color: var(--text);
}
.upload-log {
  max-height: 220px;
  overflow-y: auto;
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
}
.upload-log__line {
  white-space: pre-wrap;
  word-break: break-word;
}
.upload-log__line--info { color: var(--log-info); }
.upload-log__line--debug { color: var(--log-debug); }
.upload-log__line--warn { color: var(--log-warn); }
.upload-log__line--error { color: var(--log-error); }

/* Admin log viewer (admin page): a taller monospace log box with per-level
   coloring, mirroring .upload-log and reusing the --log-* theme vars. */
.admin-log-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.admin-log {
  max-height: 420px;
  overflow-y: auto;
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--log-info);
}
.admin-log__line {
  white-space: pre-wrap;
  word-break: break-word;
}
.admin-log__line--info { color: var(--log-info); }
.admin-log__line--debug { color: var(--log-debug); }
.admin-log__line--warn { color: var(--log-warn); }
.admin-log__line--error { color: var(--log-error); }

.upload-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 32px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: block;
  margin: 24px auto 0;
}
.upload-submit:hover { filter: brightness(1.15); }
.upload-retry-btn {
  margin-top: 12px;
  padding: 10px 20px;
  font-size: 0.9rem;
  border-radius: 999px;
  display: inline-block;
}
.upload-queue__retry {
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  display: inline-block;
}

/* Prominent CTA: the clip-editor entry (upload page) and back-to-upload button
   (clip editor). A big pill button so both are obvious (bugs.md L40). */
.upload-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  /* Give the button breathing room from the drop zone directly below it
     (bugs.md L40: the big button was too close to the elements underneath). */
  margin-bottom: 24px;
}
.upload-cta:hover { filter: brightness(1.15); }

.upload-footer { text-align: center; margin-top: 24px; font-size: 0.85rem; }

/* ===== Upload preview + clip (Set Start / Set End buttons) ===== */
.upload-timeline {
  margin-top: 4px;
  position: relative;
}

.upload-timeline__video {
  display: block;
  width: 100%;
  max-height: 75vh;
  border-radius: 8px;
  background: #000;
  margin-bottom: 8px;
}

/* DPlayer clip preview (§bug L64): width-fills, height from the video's aspect
   ratio (DPlayer sets it). No max-height cap — the watch page uses the same. */
.upload-timeline__player {
  width: 100%;
  border-radius: 8px;
  background: #000;
  margin-bottom: 8px;
  overflow: hidden;
}

/* In-page fullscreen state (§13.26): the video fills the screen and the clip
   controls stay pinned at the bottom. The whole timeline is moved into the
   overlay, so the Set Start / Set End controls remain visible. */
.upload-timeline.inpage-overlay__fill {
  display: flex;
  flex-direction: column;
  background: #000;
}
.upload-timeline.inpage-overlay__fill .upload-timeline__video {
  flex: 1 1 auto;
  max-height: none;
  width: 100%;
  border-radius: 0;
  object-fit: contain;
  margin-bottom: 0;
}
.upload-timeline.inpage-overlay__fill .upload-timeline__player {
  flex: 1 1 auto;
  max-height: none;
  width: 100%;
  border-radius: 0;
  margin-bottom: 0;
}
.upload-timeline.inpage-overlay__fill .upload-clip-controls {
  flex: 0 0 auto;
  justify-content: center;
  padding: 14px 0;
  background: rgba(0, 0, 0, 0.7);
  gap: 32px;
}
.upload-timeline.inpage-overlay__fill .upload-clip-controls__btn {
  padding: 10px 28px;
  font-size: 1rem;
}

/* Fullscreen button for the clip panel (hover-reveal, same pattern as the watch page). */
.clip-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}
.upload-timeline:hover .clip-fullscreen-btn { opacity: 1; }
.clip-fullscreen-btn:hover { background: rgba(0, 0, 0, 0.8); }
.clip-fullscreen-btn svg { width: 20px; height: 20px; }

/* One row with two groups: a "Set" button plus the time it captured. */
.upload-clip-controls {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}
.upload-clip-controls__group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-clip-controls__btn {
  padding: 6px 16px;
  font-size: 0.9rem;
}
/* Editable time field: monospace + tabular-nums so the digits line up, with a
   fixed width so the row stays aligned as values change. */
.upload-clip-controls__time {
  width: 74px;
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text);
  background: var(--pico-form-element-background-color, var(--input-bg));
  border: 1px solid var(--input-border);
  border-radius: 6px;
}
.upload-clip-controls__time:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Indeterminate progress bar: shown while no measurable ratio exists
   (Preparing / Extracting cover / Uploading, §13.11). The inline width set by
   JS is cleared in that state so this fixed 30% slide is visible. */
.bar__fill.indeterminate {
  width: 30%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: bar-slide 1.2s ease-in-out infinite;
}
@keyframes bar-slide {
  from { margin-left: -30%; }
  to   { margin-left: 100%; }
}

/* Drop zone is frozen while the upload pipeline runs (§13.11). */
.upload-dropzone.busy { opacity: 0.5; pointer-events: none; }
button:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

/* ===== Account & Admin pages (§13.11) ===== */
.page { max-width: none; }

.panel {
  background: var(--panel);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 14px; font-size: 1.05rem; }

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.panel-grid .panel { margin-bottom: 0; }
@media (max-width: 760px) { .panel-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field--check { display: block; }
.field--check label { font-size: 0.9rem; color: var(--text); font-weight: 400; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn--ghost { background: var(--btn-ghost-bg); color: var(--text); border: 1px solid var(--input-border); }
.btn--ghost:hover { background: var(--btn-ghost-hover); }
.btn--danger { background: #7f2a33; }
.btn--danger:hover { background: #96333f; }
.btn--sm { padding: 5px 12px; font-size: 0.8rem; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--active);
  color: var(--muted);
}
.badge--admin { background: #33264d; color: #c9b3ff; }
.badge--danger { background: #4d2330; color: #ff9db0; }

/* Admin user list: small circular avatar + a truncated password-hash preview. */
.user-row__avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; }
.user-row__hash { font-size: 0.72rem; }
/* Admin Users table: what the Delete button would take with it (§37.3). */
.user-row__owns { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 0; font-size: 0.75rem; }

/* My-videos status column: a compact progress bar while a Drive upload runs. */
.status-cell { min-width: 168px; }
.video-progress { display: flex; align-items: center; gap: 8px; }
.progress {
  flex: 1 1 auto;
  height: 8px;
  background: var(--bar-bg);
  border-radius: 6px;
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s;
}
.progress__label { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }

/* Admin settings helper text under a field. */
.hint { display: block; margin-top: 4px; font-size: 0.78rem; color: var(--muted); }

.avatar-lg {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 12px;
}

.table thead th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline; }
.row-actions form[hidden] { display: none; }
.row-actions form + form { margin-left: 8px; }
/* Pico forces width:100% on button[type=submit]; keep table action buttons inline. */
.row-actions .btn { width: auto; }
.row-title { color: var(--accent); text-decoration: none; }
.row-title:hover { text-decoration: underline; }

/* My Videos table (§16.6): a small cover thumbnail leads each row, plus an
   upload-time column. The cover fades in on load (like the home cards). */
.vt-cover { width: 84px; }
.row-cover {
  width: 84px; height: 47px; object-fit: cover; border-radius: 5px;
  background: var(--panel-2); opacity: 0; transition: opacity 0.3s ease;
  display: block;
}
.row-cover.is-loaded { opacity: 1; }
.vt-uploaded { white-space: nowrap; }
.vt-size { white-space: nowrap; }
/* Admin videos table (§16.13c): owner shown as a small avatar + name in one
   cell, reusing the avatar-border convention. */
.admin-video-row [data-stream-state] {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.admin-owner { display: inline-flex; align-items: center; gap: 6px; }
.admin-owner__avatar {
  width: 20px; height: 20px; border-radius: 50%; object-fit: cover;
  border: 1.5px solid var(--border-strong); flex: 0 0 auto;
}
/* My Videos table (§16.6): fill the full content width so the columns
   spread across the page, and truncate long titles with an ellipsis. */
.table--user { width: 100%; }
/* Keep the per-row Edit/Delete buttons left-aligned (the shared .row-actions
   rule right-aligns them, which looks wrong on the left-packed table). */
.table--user .row-actions { text-align: left; }
.table--user .row-title {
  display: block;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 16px;
}
@media (max-width: 760px) { .settings-grid { grid-template-columns: 1fr; } }

/* ===== Modal dialogs (confirm / edit / avatar-crop) =====
   Pico turns `dialog` into a full-viewport flex overlay and expects the card in
   a child `<article>` (its `dialog article` rule). We keep the `<dialog>` as the
   transparent overlay (the ::backdrop dims the page) and size the <article> card. */
.confirm-dialog, .edit-dialog, .crop-dialog {
  background: transparent;
  padding: 0;
}
.confirm-dialog::backdrop,
.edit-dialog::backdrop,
.crop-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}
.dialog-card {
  width: 420px;
  max-width: calc(100vw - 2rem);
  margin: 0 auto;
  padding: 20px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  overflow: auto;
  max-height: calc(100vh - 2rem);
  box-sizing: border-box;
}
.edit-dialog .dialog-card { width: 640px; }
/* Edit dialog: stack the existing tags as chips above the add-tag field (which
   fills its own full-width line) instead of sitting inline with them. Scoped to
   the edit dialog so the shared .tag-input on upload/clip pages stays inline. */
.edit-dialog .tag-input__field { flex: 1 1 100%; }
.crop-dialog .dialog-card { width: 85vw; max-width: 900px; overflow-x: hidden; overflow-y: auto; }
.confirm-dialog .dialog-card p { margin: 0 0 6px; }
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}
.crop-dialog .cropper-container {
  max-width: 100%;
  overflow: hidden;
}
/* Avatar crop dialog: two-column layout with a live circular preview (§16.2). */
.crop-dialog .crop-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
}
.crop-dialog .crop-row .cropper-container { max-width: 100%; }
.crop-preview-wrap { text-align: center; }
.crop-preview {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-2);
  border: 2px solid var(--border);
  display: block;
}
.crop-preview-cap { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
@media (max-width: 760px) {
  .crop-dialog .crop-row { grid-template-columns: 1fr; }
}

/* ===== Video detail panel (watch page) ===== */
.video-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0 0;
}
.video-meta__item {
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 14px;
}
.video-meta__item dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 4px;
}
.video-meta__item dd {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  overflow-wrap: anywhere;
}
/* Monospace value (used for the Drive filename, which is a long hash). */
.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  font-weight: 400;
}

/* Free-text video description (watch page). */
.video-description {
  margin: 14px 0 0;
  padding: 14px 16px;
  background: var(--panel);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Uploader row (watch page): circular avatar + username, shown above the description. */
.video-author {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0 0;
  padding: 14px 16px;
  background: var(--panel);
  border-radius: 10px;
}
.video-author__avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.video-author__name { font-size: 1.25rem; font-weight: 600; }
/* Watch Together + Download buttons (§17): right-aligned in the uploader row. */
.video-author__together { margin-left: auto; flex: 0 0 auto; }
.video-author__download { flex: 0 0 auto; }

/* ===== Comments (watch page, §13.16) ===== */
.comments {
  margin-top: 24px;
}
.comments__form {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

/* Kaomoji quick-insert bar: one row of buttons that insert at the cursor. */
.kaomoji-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin: 6px 0 8px;
}

/* Generic toast (§16.1): self-dismissing, bottom-center, theme-aware. */
#svs-toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.svs-toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: inherit;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.svs-toast.is-shown { opacity: 1; transform: translateY(0); }
.svs-toast--error { border-color: #e05555; }
.kaomoji-bar__label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 4px;
}
.kaomoji-bar__btn {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
  font-family: inherit;
}
.kaomoji-bar__btn:hover { background: var(--active); }

.comments__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.comment {
  display: flex;
  gap: 12px;
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 14px;
}
.comment__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.comment__main { flex: 1; min-width: 0; }
.comment__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.comment__author { font-weight: 600; }
.comment__time { font-size: 0.8rem; }
.comment__delete { margin-left: auto; }
/* Plain text (kaomoji welcome): keep line breaks, wrap long unbroken strings. */
.comment__body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-size: 0.95rem;
}

/* ===== Two-level replies (§13.20) ===== */
.comment__actions { margin-top: 6px; }

/* Reply form: hidden by default, shown when .is-visible is present. */
.comment__reply-form { display: none; margin-top: 10px; }
.comment__reply-form.is-visible { display: block; }

/* Replies are indented beneath their parent comment. */
.comment__replies {
  list-style: none;
  margin: 10px 0 0 28px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.comment--reply {
  padding: 8px 12px;
  background: var(--panel-2);
}
.comment--reply .comment__avatar {
  width: 28px;
  height: 28px;
}

/* ===== Folders (§13.21) ===== */
/* My Videos: one row per folder — an inline rename form + a delete form. */
#folder-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.folder-row .folder-rename {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.folder-row .folder-rename input {
  flex: 1;
}
.folder-create {
  display: flex;
  align-items: center;
  gap: 8px;
}
.folder-create input {
  flex: 1;
}
/* Pico forces width:100% on button[type=submit]; inside the flex folder forms
   that makes the action button swallow the whole row. Keep it content-sized. */
.folder-create .btn,
.folder-rename .btn {
  width: auto;
  flex: 0 0 auto;
}
/* Per-row folder-move select in the My Videos table (auto-submits on change). */
.folder-move {
  display: inline-block;
  margin: 0;
}
.folder-move__select {
  font-size: 0.9em;
  padding: 4px 6px;
}

/* ===== Live streaming (§13.41, per-user rooms §14.8) ===== */
/* List page: 16:9 cover tile + an "ON AIR" badge (server-side probe, §14.7) +
   an owner row (avatar + username) matching the home video cells (§14.8). */
.live-card { position: relative; }
/* §20 sync: live cards end with the title (no date row), so its bottom
   padding matches the home cards' date-row bottom padding. */
.live-card .card__title, .together-card .card__title { padding-bottom: 8px; }
.live-badge {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 8px; border-radius: 4px;
  background: #e53935; color: #fff;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
  display: none; pointer-events: none;
}
.live-badge.is-onair { display: inline-block; }
/* Viewer count on a live card (§19.2): mirrors .together-badge but sits top-left
   so it never overlaps the ON AIR badge (top-right); always visible (0 when empty). */
.live-online {
  position: absolute; top: 8px; left: 8px;
  padding: 2px 8px; border-radius: 4px;
  background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  pointer-events: none;
}

/* Live view page (§14.8): the streamer's avatar + username and the room
   description sit between the title and the player. */
.live-view__author { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.live-view__avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.live-view__name { font-size: 1.05rem; font-weight: 600; }
.live-view__description { margin: 0 0 16px; color: var(--muted); font-size: 0.92rem; line-height: 1.5; }

/* Admin: live-room cards (delete-only — rooms are managed by their owner). */
.live-room-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.live-room-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.live-room-card__cover { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: #000; display: block; margin-bottom: 10px; }
.live-room-card__title { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 2px; }
.live-room-card__owner { font-size: 0.8rem; margin-bottom: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Admin hub cards + subpage back-to-hub button (§16.3). */
.admin-back { margin: 0 0 18px; }
.admin-back__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
}
.admin-back__btn:hover { border-color: var(--accent); }
.admin-hub {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.admin-hub__card {
  display: block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px 22px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease;
}
.admin-hub__card:hover { border-color: var(--accent); }
.admin-hub__count {
  display: block;
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.2;
}
.admin-hub__label { color: var(--muted); font-size: 1rem; }
/* Hub card whose "count" is a word (Settings, Logs) instead of a number. */
.admin-hub__count--text { font-size: 1.4rem; line-height: 2.2rem; }

/* Admin Data & diagnostics panel (§16.7, §16.8): two stacked feature sections
   (Export, then Import). Each has its own description and a natural-width
   action row — buttons are content-sized with centered text, not full-row. */
.admin-data { display: flex; flex-direction: column; gap: 20px; }
.admin-data__section { display: flex; flex-direction: column; gap: 8px; }
.admin-data__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Pico forces width:100% on button[type=submit]; keep these buttons content-sized. */
.admin-data__actions .btn { width: auto; text-align: center; }
.admin-data__import { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-data__import input[type="file"] { flex: 0 1 auto; min-width: 0; }

/* ===== Live room page: player + right panel (§16.8) ===== */
/* Two columns: a big player (1fr) and a fixed 24rem side panel. The row is
   sized by the player's 16:9 aspect ratio; the side panel's flex layout lives
   in an absolutely-positioned inner box, so the panel's content height never
   stretches the row — the feed scrolls inside it instead. */
.live-page { display: grid; grid-template-columns: minmax(0, 1fr) 24rem; gap: 12px; }
.live-player { min-width: 0; }
.live-player .player-wrap { margin-bottom: 0; }
.live-side {
  position: relative;
  min-height: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.live-side__inner { position: absolute; inset: 0; display: flex; flex-direction: column; }
.live-side__header { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); }
.live-side__title { font-size: 1.05rem; font-weight: 700; line-height: 1.3; margin: 0 0 10px; overflow-wrap: anywhere; }
.live-side__header .live-view__author { margin-bottom: 0; }
.live-side__header .live-view__avatar { width: 32px; height: 32px; }
.live-side__header .live-view__name { font-size: 0.95rem; }
.live-side__header .live-view__description { margin: 8px 0 0; }
.live-side__online { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.live-side__online strong { color: var(--text); font-weight: 700; }
/* Room member avatar stack (§17.10): shown below the room title on the live
   and watch-together sidebars. Avatars overlap; a "+N" chip caps the row and
   shows how many more users are present. Shared by both pages. */
.room-members { display: flex; align-items: center; min-height: 28px; margin: 10px 0 0; }
.room-members__avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  border: 2px solid var(--panel-2); margin-right: -8px; background: var(--panel-2);
}
.room-members__more {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  background: var(--panel); border: 2px solid var(--panel-2);
  color: var(--muted); font-size: 0.65rem; font-weight: 700; margin-right: -8px;
}
.live-feed { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.live-feed__empty { color: var(--muted); font-size: 0.85rem; }
.live-feed__notice { font-size: 0.8rem; color: var(--muted); }
.live-feed__msg { display: flex; align-items: flex-start; gap: 8px; }
.live-feed__avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.live-feed__body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.live-feed__name { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.live-feed__text { font-size: 0.9rem; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.live-composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }
.live-composer__input { flex: 1; min-width: 0; }
.live-composer button { flex: 0 0 auto; }
@media (max-width: 768px) {
  .live-page { grid-template-columns: 1fr; }
  .live-side { height: 70vh; }
}

/* ===== Live page: full-screen letterboxed layout (§16.9) ===== */
/* On desktop the whole content area becomes the player. .main (min-height:100vh,
   a flex column) is pinned to the viewport height, and .container — its flex
   child — drops its max-width/padding and becomes a flex column, so .live-page
   fills the space below the breadcrumb. The player fills its grid column
   edge-to-edge and the video letterboxes (object-fit: contain); the right panel
   keeps its 24rem width and fills the column height. Mobile keeps the stacked
   layout from the §16.8 media query above. */
@media (min-width: 769px) {
  body.page--live .main { height: 100vh; overflow: hidden; }
  body.page--live .container {
    max-width: none;
    padding: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  body.page--live .breadcrumb { padding: 10px 16px; margin-bottom: 8px; }
  body.page--live .live-page { flex: 1 1 auto; min-height: 0; grid-template-rows: 1fr; }
  body.page--live .live-player { min-height: 0; }
  body.page--live .player-wrap {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.page--live #dplayer video { object-fit: contain; background: #000; }
}
/* Composer send button (§16.9): Pico forces width:100% on submit buttons (via a
   :where() rule, specificity 0), which locked the Send button at full width and
   squeezed the input. Keep the button auto-sized so the input (flex:1) expands
   to fill the row. Applies on all viewports. */
.live-composer button[type="submit"] { flex: 0 0 auto; width: auto; }

/* ===== Watch Together (§17) ===== */
/* List page: reuses the home/live card grid (.waterfall + .card). */
.together-card { position: relative; }
.together-badge {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 8px; border-radius: 4px;
  background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  pointer-events: none;
}

/* Room page: two-column grid mirroring .live-page (§16.8). */
.together-page { display: grid; grid-template-columns: minmax(0, 1fr) 24rem; gap: 12px; }
.together-player { min-width: 0; }
.together-player .player-wrap { margin-bottom: 0; }
/* Waiting overlay: shown when the group is paused ("XXX paused") or when we are
   the fast one more than 1 s ahead of the slowest viewer ("Waiting for XXX",
   §17.4). Covers the player; the message text is set by JS. */
.together-waiting {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff; font-size: 1.1rem; font-weight: 600;
  pointer-events: none; z-index: 10;
}
.together-waiting[hidden] { display: none; }
.together-side {
  position: relative;
  min-height: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.together-side__inner { position: absolute; inset: 0; display: flex; flex-direction: column; }
.together-side__header { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); }
.together-side__title { font-size: 1.05rem; font-weight: 700; line-height: 1.3; margin: 0 0 10px; overflow-wrap: anywhere; }
.together-side__online { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.together-side__online strong { color: var(--text); font-weight: 700; }
.together-feed { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.together-feed__empty { color: var(--muted); font-size: 0.85rem; }
.together-feed__notice { font-size: 0.8rem; color: var(--muted); }
.together-feed__msg { display: flex; align-items: flex-start; gap: 8px; }
.together-feed__avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.together-feed__body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.together-feed__name { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.together-feed__text { font-size: 0.9rem; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.together-composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }
.together-composer__input { flex: 1; min-width: 0; }
.together-composer button { flex: 0 0 auto; }
.together-composer button[type="submit"] { flex: 0 0 auto; width: auto; }

@media (max-width: 768px) {
  .together-page { grid-template-columns: 1fr; }
  .together-side { height: 70vh; }
}

/* Full-screen layout for the watch room page (mirrors §16.9 live rules). */
@media (min-width: 769px) {
  body.page--live .together-page { flex: 1 1 auto; min-height: 0; grid-template-rows: 1fr; }
  body.page--live .together-player { min-height: 0; }
}

/* ===== Message notifications (§21): user-chip dot, dropdown, panel, rows ===== */

/* Red dot on the sidebar user chip's avatar: the is-unread class is baked at
   render time from the unread_notifications count and kept in sync by
   notify.js over the per-user SSE feed (notification / unread-cleared). */
.sidebar__userchip { cursor: pointer; }
.userchip__avatar { position: relative; display: inline-block; line-height: 0; }
.userchip__dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--notify-dot); border: 2px solid var(--panel);
  display: none; pointer-events: none;
}
.sidebar__userchip.is-unread .userchip__dot { display: block; }
/* The "Notifications" dropdown entry carries the same dot (inline). */
.userchip-dropdown__dot {
  display: inline-block; flex: 0 0 auto;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--notify-dot);
}

/* Dropdown (Notifications / My Account) + recent-items panel. Both are
   position:fixed on <body> and anchored by notify.js to the chip's current
   rect — to its right, bottom-aligned, clamped to the viewport — so they
   stay fully on-screen in the expanded sidebar, the collapsed icon rail, and
   the mobile drawer alike. z-index above the sidebar (50) and the mobile
   topbar/overlay (60/45). */
.userchip-dropdown {
  position: fixed; z-index: 70;
  min-width: 11rem; padding: 4px;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column;
}
.userchip-dropdown__item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  border: none; border-radius: 6px;
  background: none; color: var(--text);
  font-size: 0.9rem; font-family: inherit;
  text-decoration: none; text-align: left; cursor: pointer;
}
.userchip-dropdown__item:hover { background: var(--hover); }

.notify-panel {
  position: fixed; z-index: 70;
  width: 20rem; max-width: calc(100vw - 16px);
  max-height: min(28rem, calc(100vh - 16px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.notify-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 0.9rem; font-weight: 600;
}
.notify-panel__all {
  color: var(--accent); font-size: 0.8rem; font-weight: 400;
  text-decoration: none;
}
.notify-panel__all:hover { text-decoration: underline; }
.notify-panel__list { overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.notify-panel__empty { padding: 10px; font-size: 0.85rem; }

/* Notification rows: shared by the dropdown panel (built by notify.js) and
   the /notifications page (server-rendered with the same classes), so both
   surfaces render identically for whatever type arrives. */
.notify-row {
  position: relative;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
}
.notify-row--link { cursor: pointer; }
.notify-row--link:hover { background: var(--hover); }
.notify-row__avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.notify-row__main { min-width: 0; }
.notify-row__text { font-size: 0.85rem; line-height: 1.4; overflow-wrap: anywhere; }
.notify-row__actor { font-weight: 600; }
.notify-row__title { color: var(--muted); }
.notify-row__time { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
/* Unread marker: a small dot at the row's right edge (cleared when the panel
   or /notifications marks everything read). */
.notify-row--unread::after {
  content: ""; position: absolute; top: 12px; right: 10px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--notify-dot);
}

/* /notifications page: the rows in a bordered card list. */
.notify-page__list {
  list-style: none; margin: 0; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px;
}
.notify-page__list .notify-row { border-radius: 0; }

/* Watch page: the notification deep-link (#c<id>) scrolls to the comment and
   flashes this highlight on it (best effort — a deleted comment simply
   lands on the list). */
.comment--flash { animation: comment-flash 2.4s ease-out; }
@keyframes comment-flash {
  0% { background: var(--active); }
  60% { background: var(--active); }
  100% { background: transparent; }
}

/* Admin Videos batch bar (36.2/36.3): the whole-library Rebuild / Repair controls
   and the one place a running batch reports itself. The bar reuses the .progress
   parts the upload and My-Videos tables already use. */
.hls-batch {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}
.hls-batch__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hls-batch__actions .btn { width: auto; }
.hls-batch__bar { margin-top: 10px; flex: none; }
.hls-batch__status { margin: 8px 0 0; font-size: 0.86rem; }
.hls-batch__notes { margin: 6px 0 0; padding-left: 18px; font-size: 0.78rem; color: var(--muted); }
.hls-batch__notes li { margin: 2px 0; }
.hls-batch__note { margin: 10px 0 0; font-size: 0.78rem; color: var(--muted); }

.service-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.service-toolbar h1 { flex: 1; margin: 0; font-size: 1.3rem; }
.service-toolbar .btn { width: auto; margin: 0; }
.service-frame { display: block; width: 100%; height: calc(100dvh - 190px); min-height: 400px; border: 1px solid var(--muted); border-radius: 10px; background: #fff; }
.service-page.is-expanded { position: fixed; inset: 0; z-index: 10000; margin: 0; padding: 14px; background: var(--bg, #101318); display: flex; flex-direction: column; }
.service-page.is-expanded .service-frame { flex: 1; height: 0; min-height: 0; }
.service-page.is-expanded > .muted { display: none; }
@media (max-width: 600px) { .service-frame { min-height: 320px; height: calc(100dvh - 220px); } }
