/**
 * YouTube miniaturas — fullscreen studio shell (like extrair-frames).
 * Light default; follows html[data-theme="dark"].
 */

/* ---- Workspace ---- */
body.is-fullscreen .fs-workspace.ytm-fs {
  --ytm-bg: #eef1f6;
  --ytm-app: #ffffff;
  --ytm-line: #e2e8f0;
  --ytm-text: var(--dica-ink, #0f172a);
  --ytm-muted: var(--dica-muted, #64748b);
  --ytm-faint: #94a3b8;
  --ytm-side: #f8fafc;
  --ytm-stage: #e8edf5;
  --ytm-accent: #1b4f9c;
  --ytm-accent-hover: #163f7d;
  --ytm-accent-soft: rgba(27, 79, 156, 0.12);
  --ytm-yt: #ff0033;
  --ytm-good: #079455;
  --ytm-bad: #d92d20;
  --ytm-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 32px rgba(15, 23, 42, 0.07);

  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 12px 14px 16px !important;
  box-sizing: border-box;
  background: var(--ytm-bg) !important;
  border-color: var(--ytm-line) !important;
  color: var(--ytm-text);
  min-height: min(78vh, 900px) !important;
  height: min(calc(100vh - 120px), 920px);
  overflow: hidden;
}

html[data-theme="dark"] body.is-fullscreen .fs-workspace.ytm-fs {
  --ytm-bg: #0b0e14;
  --ytm-app: #151922;
  --ytm-line: #2a3140;
  --ytm-text: #e8eef6;
  --ytm-muted: rgba(232, 238, 246, 0.62);
  --ytm-faint: rgba(232, 238, 246, 0.42);
  --ytm-side: #1a2030;
  --ytm-stage: #0f141c;
  --ytm-accent: #5b8fd9;
  --ytm-accent-hover: #7aa6e6;
  --ytm-accent-soft: rgba(91, 143, 217, 0.18);
  --ytm-shadow: none;
  background: var(--ytm-bg) !important;
  border-color: #0a0e14 !important;
}

.ytm-app {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  width: 100%;
  background: var(--ytm-app);
  color: var(--ytm-text);
  border-radius: 18px;
  border: 1px solid var(--ytm-line);
  box-shadow: var(--ytm-shadow);
  /* Keep overflow hidden so the stage clips; sticky-bar must not override this */
  overflow: hidden !important;
}

.ytm-app *,
.ytm-app *::before,
.ytm-app *::after {
  box-sizing: border-box;
}

.ytm-app p {
  margin: 0;
}

.ytm-app button,
.ytm-app input {
  font: inherit;
  color: inherit;
}

/* Body: sidebar + main (Pilko-like) */
.ytm-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ---- Left rail ---- */
.ytm-sidebar {
  flex: 0 0 360px;
  width: 360px;
  max-width: 400px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ytm-line);
  background: var(--ytm-side);
  overflow: auto;
  overscroll-behavior: contain;
}

.ytm-side-head {
  padding: 14px 16px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ytm-faint);
}

.ytm-mode {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--ytm-line);
  background: var(--ytm-app);
}

.ytm-mode-btn {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ytm-muted);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 0.82rem;
  font-weight: 750;
  cursor: pointer;
}

.ytm-mode-btn.is-active {
  background: var(--ytm-accent);
  color: #fff;
}

.ytm-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.ytm-kind-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  background: var(--ytm-accent-soft);
  color: var(--ytm-accent);
}

/* History */
.ytm-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.article .ytm-app .ytm-history {
  list-style: none;
  margin: 0;
  padding: 0;
}

.article .ytm-app .ytm-history li::before {
  display: none !important;
  content: none !important;
}

.ytm-history-btn {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--ytm-line);
  background: var(--ytm-app);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  color: inherit;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.ytm-history-btn:hover {
  border-color: var(--ytm-accent);
  background: var(--ytm-accent-soft);
}

.ytm-history-thumb {
  width: 56px;
  height: 32px;
  object-fit: cover;
  border-radius: 6px;
  background: #0f1115;
  flex: 0 0 auto;
}

.ytm-history-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ytm-history-title {
  font-size: 0.78rem;
  font-weight: 750;
  color: var(--ytm-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ytm-history-sub {
  font-size: 0.7rem;
  color: var(--ytm-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hero best thumb */
.ytm-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(200px, 0.9fr);
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--ytm-line);
  background: var(--ytm-side);
  flex: 0 0 auto;
}

.ytm-hero[hidden] {
  display: none !important;
}

.ytm-hero-preview {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--ytm-line);
  background: #0f1115;
  aspect-ratio: 16 / 9;
  min-height: 140px;
}

.ytm-hero-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ytm-hero-badge {
  top: 10px;
  left: 10px;
}

.ytm-hero-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  justify-content: center;
}

.ytm-hero-title {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--ytm-text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ytm-hero-meta {
  font-size: 0.82rem;
  color: var(--ytm-muted);
  line-height: 1.35;
}

.ytm-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ytm-next {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--ytm-line);
  font-size: 0.78rem;
}

.ytm-next-label {
  font-weight: 800;
  color: var(--ytm-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
}

.ytm-next a {
  color: var(--ytm-accent) !important;
  font-weight: 700;
  text-decoration: none !important;
}

.ytm-next a:hover {
  text-decoration: underline !important;
}

.ytm-side-block {
  padding: 0 16px 14px;
  border-bottom: 1px solid var(--ytm-line);
}

.ytm-side-block:last-of-type {
  border-bottom: 0;
}

.ytm-label {
  display: block;
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ytm-text);
}

.ytm-hint {
  margin-top: 8px;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--ytm-muted);
}

.ytm-input {
  width: 100%;
  border: 1px solid var(--ytm-line);
  border-radius: 12px;
  background: var(--ytm-app);
  color: var(--ytm-text);
  padding: 12px 14px;
  line-height: 1.35;
}

.ytm-input:focus {
  outline: none;
  border-color: var(--ytm-accent);
  box-shadow: 0 0 0 3px var(--ytm-accent-soft);
}

.ytm-input::placeholder {
  color: var(--ytm-faint);
}

.ytm-format {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--ytm-line);
  background: var(--ytm-app);
}

.ytm-format-btn {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ytm-muted);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 750;
  cursor: pointer;
}

.ytm-format-btn:hover {
  color: var(--ytm-text);
}

.ytm-format-btn.is-active {
  background: var(--ytm-accent);
  color: #fff;
}

.ytm-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--ytm-muted);
  cursor: pointer;
  user-select: none;
}

.ytm-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--ytm-accent);
  margin: 0;
}

.ytm-side-actions {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--ytm-line);
}

.ytm-side-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ytm-side-row .ytm-btn {
  flex: 1 1 auto;
}

.ytm-btn {
  appearance: none;
  border: 1px solid var(--ytm-line);
  background: var(--ytm-app);
  color: var(--ytm-text) !important;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
  white-space: nowrap;
}

.ytm-btn:hover:not(:disabled) {
  border-color: var(--ytm-accent);
  background: var(--ytm-accent-soft);
}

.ytm-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ytm-btn:focus-visible {
  outline: 2px solid var(--ytm-accent);
  outline-offset: 2px;
}

.ytm-btn-primary {
  background: var(--ytm-accent) !important;
  border-color: var(--ytm-accent) !important;
  color: #fff !important;
}

.ytm-btn-primary:hover:not(:disabled) {
  background: var(--ytm-accent-hover) !important;
  border-color: var(--ytm-accent-hover) !important;
  color: #fff !important;
}

.ytm-btn-block {
  width: 100%;
  min-width: 0;
}

.ytm-btn-sm {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.ytm-status {
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--ytm-muted);
  line-height: 1.35;
}

.ytm-status.is-ok {
  color: var(--ytm-good);
  font-weight: 700;
}

.ytm-status.is-error {
  color: var(--ytm-bad);
  font-weight: 700;
}

.ytm-status.is-loading {
  color: var(--ytm-accent);
  font-weight: 700;
}

.ytm-meta-block {
  margin-top: auto;
}

.ytm-card-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ytm-faint);
  margin-bottom: 10px;
}

.ytm-meta {
  display: grid;
  gap: 8px;
}

.ytm-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.84rem;
}

.ytm-meta-label {
  color: var(--ytm-muted);
  font-weight: 600;
  flex: 0 0 auto;
}

.ytm-meta-value {
  font-weight: 750;
  color: var(--ytm-text);
  text-align: right;
  word-break: break-word;
  min-width: 0;
}

.ytm-meta-value a {
  color: var(--ytm-accent) !important;
  text-decoration: none !important;
  font-weight: 750;
}

.ytm-meta-value a:hover {
  text-decoration: underline !important;
}

.ytm-meta-value.is-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Main gallery ---- */
.ytm-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--ytm-stage);
  overflow: hidden;
}

.ytm-gallery {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--ytm-app);
  margin: 12px;
  border-radius: 14px;
  border: 1px solid var(--ytm-line);
  overflow: hidden;
}

.ytm-gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ytm-line);
  background: var(--ytm-side);
  flex: 0 0 auto;
}

.ytm-gallery-title {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ytm-faint);
}

.ytm-results-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ytm-muted);
  font-variant-numeric: tabular-nums;
}

.ytm-empty {
  margin: 16px;
  padding: 36px 20px;
  text-align: center;
  font-size: 0.92rem;
  color: var(--ytm-muted);
  line-height: 1.45;
  border: 2px dashed var(--ytm-line);
  border-radius: 14px;
  background: var(--ytm-side);
}

.ytm-empty[hidden] {
  display: none !important;
}

.ytm-grid {
  list-style: none;
  margin: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  /* Size rows to content and scroll — never compress cards to fit viewport */
  grid-auto-rows: min-content;
  align-content: start;
  align-items: start;
  gap: 12px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior: contain;
}

.article .ytm-app .ytm-grid {
  list-style: none;
  margin: 0;
  padding: 12px;
}

.article .ytm-app .ytm-grid li::before {
  display: none !important;
  content: none !important;
}

.ytm-item {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--ytm-line);
  border-radius: 14px;
  background: var(--ytm-app);
  /* overflow:hidden makes grid min-size 0 and compresses rows — clip only the thumb */
  overflow: visible;
  min-width: 0;
  min-height: min-content;
  height: auto;
  align-self: start;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.ytm-item.is-missing {
  opacity: 0.55;
}

.ytm-item.is-best {
  border-color: color-mix(in srgb, var(--ytm-accent) 50%, var(--ytm-line));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ytm-accent) 28%, transparent);
}

/*
 * Grid thumbs: natural image height (width 100% + height auto).
 * Card overflow must stay visible so CSS Grid does not treat min-size as 0
 * and squash every row to ~74px under the fixed gallery height.
 */
.ytm-thumb-wrap {
  position: relative;
  width: 100%;
  flex: 0 0 auto;
  min-height: 124px;
  overflow: hidden;
  border-radius: 14px 14px 0 0;
  line-height: 0;
  background: #0f1115;
}

html[data-theme="dark"] .ytm-thumb-wrap {
  background-color: #0f1115;
}

.ytm-thumb {
  display: block;
  width: 100% !important;
  max-width: none !important;
  height: auto !important;
  max-height: none !important;
  min-height: 124px;
  object-fit: contain;
  object-position: center;
  background: #0f1115;
  vertical-align: top;
}

.ytm-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(15, 17, 21, 0.82);
  color: #fff;
}

.ytm-badge.is-best {
  background: var(--ytm-accent);
}

.ytm-badge.is-missing {
  background: rgba(217, 45, 32, 0.9);
}

.ytm-item-body {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.ytm-item-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ytm-text);
  line-height: 1.25;
}

.ytm-item-meta {
  font-size: 0.78rem;
  color: var(--ytm-muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.ytm-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ytm-item-actions .ytm-btn {
  flex: 1 1 auto;
}

/* Toast */
.ytm-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  z-index: 9999;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(90vw, 380px);
  text-align: center;
}

.ytm-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media screen and (max-width: 900px) {
  body.is-fullscreen .fs-workspace.ytm-fs {
    height: auto !important;
    min-height: min(88vh, 1100px) !important;
    overflow: auto;
  }

  .ytm-body {
    flex-direction: column;
    overflow: auto;
  }

  .ytm-sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--ytm-line);
    max-height: none;
  }

  .ytm-main {
    min-height: 420px;
  }

  .ytm-gallery {
    margin: 10px;
  }

  .ytm-hero {
    grid-template-columns: 1fr;
  }
}

@media screen and (max-width: 560px) {
  body.is-fullscreen .fs-workspace.ytm-fs {
    padding: 8px !important;
  }

  .ytm-grid {
    grid-template-columns: 1fr;
  }

  .ytm-side-row {
    flex-direction: column;
  }
}
