:root {
  --tg-bg: #14191f;
  --tg-secondary-bg: #1c232b;
  --tg-card-bg: #1c232b;
  --tg-text: #eef1f4;
  --tg-hint: #7c8792;
  --tg-link: #5aa4ec;
  --tg-button: #4d8ef0;
  --tg-button-text: #ffffff;
  --tg-separator: #262e37;
  --danger: #ef5464;
  --ok: #3fbf74;
  --warn: #dda63f;

  --radius-lg: 14px;
  --radius-md: 12px;
  --radius-sm: 8px;

  /* Plyr's own documented CSS custom properties - mapped onto the same
     tokens the rest of the app already themes from, so the player matches
     whatever Telegram theme (light/dark) applyThemeParams() sets these to,
     not a hardcoded look of its own. */
  --plyr-color-main: var(--tg-button);
  --plyr-video-control-color: var(--tg-text);
  --plyr-video-control-color-hover: var(--tg-button-text);
  --plyr-video-background: #000;
  --plyr-menu-background: var(--tg-card-bg);
  --plyr-menu-color: var(--tg-text);
  --plyr-tooltip-background: var(--tg-card-bg);
  --plyr-tooltip-color: var(--tg-text);
  --plyr-font-family: inherit;
  --plyr-border-radius: var(--radius-md);
}

/* Plyr wraps the <video> in its own container div and resets margin on
   the video element itself internally - the app's own spacing rules
   below target the wrapper (.plyr) instead of video.preview-player so
   they still take effect once Plyr initializes. */
.plyr { border-radius: var(--radius-md); overflow: hidden; margin-top: 12px; }

/* Plyr hides bare .plyr__time by default (display:none - only its own
   --current/--duration variants opt back in via a breakpoint) - the live
   player's custom elapsed-time readout (see openLivePlayer in app.js)
   needs its own explicit override to actually show up. */
.live-elapsed-time { display: inline-block; color: var(--plyr-video-control-color, var(--tg-text)); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100vw;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 46px;
  padding: 0 10px;
  background: color-mix(in srgb, var(--tg-bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--tg-separator);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--tg-link);
  font-size: 17px;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.icon-btn:active { background: var(--tg-secondary-bg); }
.back-btn { font-size: 22px; font-weight: 400; }

main {
  flex: 1;
  padding: 10px 12px 24px;
  max-width: 100%;
  min-width: 0;
}

/* ---------- grouped list (native-settings style) ---------- */

.list-group {
  background: var(--tg-card-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  cursor: pointer;
  min-width: 0;
}
.list-row:not(:last-child) { border-bottom: 1px solid var(--tg-separator); }
.list-row:active { background: var(--tg-secondary-bg); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
  text-transform: uppercase;
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.avatar .status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--tg-hint);
  border: 2px solid var(--tg-card-bg);
}
.avatar .status-dot.live {
  background: var(--danger);
  animation: pulse 1.8s infinite;
}
.avatar .status-dot.streaming {
  background: var(--ok);
  animation: pulse-ok 1.8s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,84,100,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(239,84,100,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,84,100,0); }
}
@keyframes pulse-ok {
  0%   { box-shadow: 0 0 0 0 rgba(63,191,116,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(63,191,116,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,191,116,0); }
}

.row-info { flex: 1; min-width: 0; }
.row-title {
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  font-size: 12px;
  color: var(--tg-hint);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub.live-sub { color: var(--danger); }
.row-sub.streaming-sub { color: var(--ok); }
.chevron { color: var(--tg-hint); font-size: 15px; flex-shrink: 0; opacity: .7; }
.row-delete-btn, .row-retry-btn {
  flex-shrink: 0;
  border: none;
  background: none;
  font-size: 16px;
  line-height: 1;
  padding: 6px;
  margin-left: 4px;
  opacity: .6;
  cursor: pointer;
}
.row-delete-btn:active, .row-retry-btn:active { opacity: 1; }

.empty-state {
  text-align: center;
  color: var(--tg-hint);
  padding: 40px 20px;
  font-size: 13.5px;
}

/* ---------- status strip (disk / app / server / gdrive) ---------- */

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.status-tile {
  background: var(--tg-card-bg);
  border-radius: var(--radius-md);
  padding: 9px 6px;
  text-align: center;
  /* Grid items default to min-width:auto, which blocks the child's own
     overflow:hidden/ellipsis from ever kicking in - without this, a long
     value (e.g. the Google Drive quota tile) just spills past the tile
     instead of truncating. */
  min-width: 0;
}
.status-dot-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 10px;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.status-dot-row .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tg-hint);
  flex-shrink: 0;
}
.status-dot-row .status-dot.live { background: var(--danger); }
.status-dot-row .status-dot.streaming { background: var(--ok); }
.status-tile-value {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--tg-text);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- action row (icon strip) ---------- */

.action-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.action-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 11px 4px;
  background: var(--tg-card-bg);
  border: none;
  border-radius: var(--radius-md);
  color: var(--tg-text);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  min-width: 0;
}
.action-tile:active { background: var(--tg-secondary-bg); }
.action-tile .emoji { font-size: 19px; line-height: 1; }
.action-tile.danger .emoji { filter: saturate(1.1); }
.action-tile:disabled { opacity: .35; pointer-events: none; }
.action-tile.selected { background: var(--tg-button); color: var(--tg-button-text); }

.section-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--tg-hint);
  margin: 18px 4px 6px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 2px; }

/* ---------- trim slider ---------- */

.trim-wrap {
  background: var(--tg-card-bg);
  border-radius: var(--radius-lg);
  padding: 18px 16px 20px;
}

.trim-wrap video.preview-player, .trim-wrap .plyr { margin-top: 0; margin-bottom: 12px; }

#videoSlot { position: relative; }
.blur-region-box {
  position: absolute;
  border: 2px solid var(--tg-link);
  background: rgba(0, 0, 0, .35);
  box-sizing: border-box;
  touch-action: none;
  cursor: move;
}
.blur-region-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px;
  border-radius: 50%;
  background: var(--tg-link);
  border: 2px solid var(--tg-card-bg);
  touch-action: none;
}
.blur-region-handle[data-corner="nw"] { top: 0; left: 0; cursor: nwse-resize; }
.blur-region-handle[data-corner="ne"] { top: 0; right: 0; cursor: nesw-resize; }
.blur-region-handle[data-corner="sw"] { bottom: 0; left: 0; cursor: nesw-resize; }
.blur-region-handle[data-corner="se"] { bottom: 0; right: 0; cursor: nwse-resize; }

.trim-range-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}
.trim-range-labels .label { text-align: center; min-width: 0; }
.trim-range-labels .label .time {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.trim-range-labels .label .tag {
  font-size: 10px;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 1px;
}
.trim-range-labels .label .time-input {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--tg-text);
  text-align: center;
  width: 8ch;
  padding: 0 0 1px;
  font-family: inherit;
}
.trim-range-labels .label .time-input:focus {
  outline: none;
  border-bottom-color: var(--tg-link);
}
.trim-range-labels .dash { color: var(--tg-hint); font-size: 16px; align-self: center; opacity: .6; }

.category-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.category-chip {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--tg-secondary-bg);
  border: 1px solid var(--tg-separator);
  color: var(--tg-hint);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.category-chip.selected {
  background: var(--tg-button);
  border-color: var(--tg-button);
  color: var(--tg-button-text);
}

/* ---------- publish form (ТГК / YouTube) ---------- */

.publish-log-row {
  font-size: 12.5px;
  color: var(--tg-hint);
  padding: 6px 2px;
}
.publish-log-row a { color: var(--tg-link); }

.publish-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.calendar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.calendar-search .rename-input { font-weight: 400; font-size: 14px; }
.rename-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.rename-input {
  flex: 1;
  min-width: 0;
  background: var(--tg-secondary-bg);
  border: 1px solid var(--tg-separator);
  border-radius: var(--radius-md);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 9px 12px;
}
.rename-input:focus {
  outline: none;
  border-color: var(--tg-link);
}
.publish-input, .publish-textarea {
  background: var(--tg-secondary-bg);
  border: 1px solid var(--tg-separator);
  border-radius: var(--radius-md);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
}
.publish-input:focus, .publish-textarea:focus {
  outline: none;
  border-color: var(--tg-link);
}
.publish-textarea {
  resize: vertical;
  min-height: 70px;
}
.thumb-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--tg-separator);
  color: var(--tg-hint);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}

/* ---------- 3-way choice overlay (dev-browser fallback for confirmChoice) ---------- */

.choice-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: color-mix(in srgb, black 55%, transparent);
}
.choice-box {
  width: 100%;
  max-width: 320px;
  background: var(--tg-card-bg);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.choice-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.choice-message { font-size: 13px; color: var(--tg-hint); margin-bottom: 14px; line-height: 1.4; }
.choice-buttons { display: flex; flex-direction: column; gap: 8px; }

.slider-track {
  position: relative;
  height: 36px;
  margin: 0 2px;
}
.slider-rail {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--tg-separator);
  border-radius: 3px;
  transform: translateY(-50%);
}
.slider-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  background: var(--tg-button);
  border-radius: 3px;
  transform: translateY(-50%);
}
.slider-handle {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 50%;
  background: var(--tg-button-text);
  border: 2.5px solid var(--tg-button);
  transform: translateY(-50%);
  touch-action: none;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.slider-handle:active { cursor: grabbing; transform: translateY(-50%) scale(1.08); }

.trim-duration-hint {
  text-align: center;
  color: var(--tg-hint);
  font-size: 11.5px;
  margin-top: 8px;
}
.file-size-hint {
  text-align: center;
  color: var(--tg-hint);
  font-size: 12.5px;
  margin-top: 2px;
}

.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:active { opacity: .82; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.secondary { background: var(--tg-secondary-bg); color: var(--tg-text); }
.btn.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.btn-stack { display: flex; flex-direction: column; gap: 8px; }
.trim-wrap + .btn { margin-top: 14px; }

/* ---------- result / job status ---------- */

.result-card {
  background: var(--tg-card-bg);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
}
.result-status-icon { font-size: 32px; margin-bottom: 6px; }
.result-label { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.result-sub { font-size: 12.5px; color: var(--tg-hint); line-height: 1.5; }

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2.5px solid var(--tg-separator);
  border-top-color: var(--tg-button);
  animation: spin 0.8s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

video.preview-player {
  width: 100%;
  border-radius: var(--radius-md);
  margin-top: 12px;
  background: #000;
  display: block;
}

.warn-list {
  margin-top: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: 12.5px;
  text-align: left;
}

/* ---------- queue screen ---------- */

.status-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  vertical-align: 1px;
}
.status-badge.queued { background: color-mix(in srgb, var(--tg-hint) 20%, transparent); color: var(--tg-hint); }
.status-badge.running { background: color-mix(in srgb, var(--tg-button) 20%, transparent); color: var(--tg-button); }
.status-badge.done { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.status-badge.error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.row-btn {
  border: none;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 8px;
}
.row-btn.danger { color: var(--danger); }
.row-btn:active { opacity: .7; }
.row-btn:disabled { opacity: .4; pointer-events: none; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--tg-card-bg);
  color: var(--tg-text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  z-index: 100;
  max-width: 88%;
  text-align: center;
  border: 1px solid var(--tg-separator);
}

/* ---------- misc ---------- */

.spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 5px;
}
