.sb-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 0.4rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent, #a78bfa) 45%, var(--border, rgba(255, 255, 255, 0.08)));
  background: color-mix(in srgb, var(--accent, #a78bfa) 14%, var(--bg-2, #262b37));
  color: #a78bfa;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sb-help:hover,
.sb-help:focus-visible,
.sb-help.is-open {
  background: color-mix(in srgb, var(--accent, #a78bfa) 22%, var(--bg-1, #1a1d26));
  border-color: #a78bfa;
  color: #ddd6fe;
  transform: translateY(-1px);
  outline: none;
}

.sb-help-popover {
  position: fixed;
  z-index: 11000;
  width: min(360px, calc(100vw - 24px));
  padding: 0.95rem 1rem 1rem;
  border-radius: 16px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg-1, #1a1d26) 94%, #000 6%), color-mix(in srgb, var(--bg-2, #262b37) 94%, #000 6%));
  border: 1px solid color-mix(in srgb, var(--accent, #a78bfa) 32%, var(--border, rgba(255, 255, 255, 0.08)));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(167, 139, 250, 0.08);
  color: var(--text, #f8f9fb);
}

.sb-help-popover[hidden] {
  display: none;
}

.sb-help-popover-title {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sb-help-popover-body {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-secondary, #c7ccd6);
}

.sb-help-popover-body strong {
  color: var(--text, #f8f9fb);
}

.sb-help-popover-body code {
  background: color-mix(in srgb, var(--bg-0, #0f1117) 88%, #000 12%);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: 6px;
  padding: 0.08rem 0.32rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.78rem;
  color: #ddd6fe;
}

.sb-help-popover-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.8rem;
  color: #c4b5fd;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}

.sb-help-popover-link:hover,
.sb-help-popover-link:focus-visible {
  color: #ddd6fe;
  text-decoration: underline;
  outline: none;
}

.sb-help-popover-arrow {
  position: absolute;
  width: 14px;
  height: 14px;
  background: inherit;
  border-left: 1px solid color-mix(in srgb, var(--accent, #a78bfa) 32%, var(--border, rgba(255, 255, 255, 0.08)));
  border-top: 1px solid color-mix(in srgb, var(--accent, #a78bfa) 32%, var(--border, rgba(255, 255, 255, 0.08)));
  transform: rotate(45deg);
}

.sb-help-popover-arrow[data-side="top"] {
  top: -7px;
}

.sb-help-popover-arrow[data-side="bottom"] {
  bottom: -7px;
  transform: rotate(225deg);
}

@media (max-width: 720px) {
  .sb-help {
    width: 20px;
    height: 20px;
    font-size: 0.72rem;
  }

  .sb-help-popover {
    width: min(360px, calc(100vw - 16px));
    padding: 0.9rem 0.95rem 0.95rem;
  }
}

/* ============================================================
   Media on Home — poster rows + *arr stat tiles + requests.
   Lives inside the #home-media bento card. Flat, dark, no
   gradients. Reuses the dashboard design tokens (--bg-1 card
   surface, --border hairline, --accent violet).
   ============================================================ */

/* Inside the Home bento card the tiles/poster frames sit on the
   card surface, so lift them to --bg-2 for contrast against the
   card's own --bg-1 background and trim the last section's margin. */
#home-media .media-section:last-child { margin-bottom: 0; }
#home-media .media-tile { background: var(--bg-2, #262b37); }
#home-media .media-section-title { font-size: 0.92rem; }

.media-empty {
  background: var(--bg-1, #1a1d26);
  border: 1px solid var(--border, #2a2e3a);
  border-radius: 14px;
  padding: 2rem 1.75rem;
  text-align: center;
  max-width: 560px;
  margin: 1.5rem auto;
}
.media-empty p { color: var(--text-secondary, #c7ccd6); margin: 0 0 1.1rem; }

.media-section { margin-bottom: 2rem; }
.media-section-title {
  font-size: 1.02rem;
  font-weight: 650;
  color: var(--text, #f8f9fb);
  margin: 0 0 0.85rem;
}
.media-row-head { display: flex; align-items: baseline; justify-content: space-between; }

/* --- *arr stat tiles --- */
.media-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}
.media-tile {
  background: var(--bg-1, #1a1d26);
  border: 1px solid var(--border, #2a2e3a);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
}
/* Clickable stat tiles (Missing/Monitored/In queue → arr/qBittorrent). */
a.media-tile-link {
  display: block;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 120ms ease-out, transform 120ms ease-out, background 120ms ease-out;
}
a.media-tile-link:hover {
  border-color: rgba(167, 139, 250, 0.45);
  background: var(--bg-2, #262b37);
  transform: translateY(-1px);
}
.media-tile-value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text, #f8f9fb);
  letter-spacing: -0.02em;
}
.media-tile-label {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary, #c7ccd6);
}
.media-tile-detail {
  margin-top: 0.2rem;
  font-size: 0.74rem;
  color: var(--text-muted, #9196a5);
}
.media-tile-skeleton {
  color: var(--text-muted, #9196a5);
  font-size: 0.85rem;
  padding: 1rem 0;
}

/* --- poster rows (horizontal scroll) --- */
.poster-row {
  display: flex;
  gap: 0.85rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0.25rem 0.85rem;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong, #3e4352) transparent;
}
.poster-row::-webkit-scrollbar { height: 8px; }
.poster-row::-webkit-scrollbar-thumb {
  background: var(--border-strong, #3e4352);
  border-radius: 8px;
}
.poster-row::-webkit-scrollbar-track { background: transparent; }

.poster-card {
  flex: 0 0 auto;
  width: 132px;
  scroll-snap-align: start;
}
/* Clickable poster (Jellyfin / Seerr deep-link). The whole card is an
 * anchor; on hover the frame lifts slightly, dims, and reveals an ↗
 * "open" affordance. */
a.poster-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.poster-card-link .poster-frame {
  transition: transform 130ms ease-out, border-color 130ms ease-out;
}
a.poster-card-link:hover .poster-frame {
  transform: translateY(-3px) scale(1.02);
  border-color: rgba(167, 139, 250, 0.55);
}
a.poster-card-link .poster-img {
  transition: filter 130ms ease-out;
}
a.poster-card-link:hover .poster-img {
  filter: brightness(0.62);
}
.poster-open {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent, #8b5cf6);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 130ms ease-out, transform 130ms ease-out;
}
a.poster-card-link:hover .poster-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
a.poster-card-link:hover .poster-title {
  color: var(--accent, #8b5cf6);
}
.poster-frame {
  position: relative;
  width: 132px;
  height: 198px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-2, #262b37);
  border: 1px solid var(--border, #2a2e3a);
}
.poster-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.poster-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-muted, #9196a5);
  background: var(--bg-2, #262b37);
}
.poster-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent, #8b5cf6);
  padding: 0.18rem 0.42rem;
  border-radius: 6px;
}
.poster-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(0, 0, 0, 0.55);
}
.poster-progress-fill {
  height: 100%;
  background: var(--accent, #8b5cf6);
}
.poster-title {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text, #f8f9fb);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.poster-sub {
  font-size: 0.74rem;
  color: var(--text-muted, #9196a5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-row-empty {
  color: var(--text-muted, #9196a5);
  font-size: 0.85rem;
  padding: 1.25rem 0.25rem;
  margin: 0;
}

/* loading skeletons */
.poster-skeleton {
  flex: 0 0 auto;
  width: 132px;
  height: 198px;
  border-radius: 10px;
  background: var(--bg-2, #262b37);
  border: 1px solid var(--border, #2a2e3a);
  opacity: 0.55;
}

/* ============================================================
   Home bento row-1 — right column (System Stats + Recent Activity
   + Latest Release). The three stacked cards in .bento-col-right
   fill the 4-col slot naturally; no extra stretching needed since
   the combined card heights match the 8-col Launcher. The
   activity-list max-height cap is removed so the feed can use
   its full card height instead of scrolling at 260 px.
   ============================================================ */
@media (min-width: 1101px) {
  /* Remove the 260 px scroll cap so the activity list fills the
     full card height available inside the right column. */
  .bento-col-right .bento-activity .activity-list {
    max-height: none;
    overflow-y: auto;
  }
}

/* ============================================================
   CUSTOMIZABLE HOME LAYOUT (GridStack) — v1 prototype
   The "Edit layout" toggle + Save/Reset controls, plus the glue
   that lets the existing .bento-card visuals survive being wrapped
   as GridStack items. Flat, solid colors only (no gradients).
   ============================================================ */

/* --- Header controls --- */
.layout-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  position: relative;   /* anchor for the Add-widget picker popover */
}
#layout-add-widget.is-active {
  background: var(--bg-card-hover, #1c1c24);
  color: var(--text, #fff);
  border-color: var(--accent, #7c3aed);
}
.layout-controls.layout-hidden { display: none; }
.layout-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border, #2a2e3a);
  background: var(--bg-2, #14141a);
  color: var(--text-secondary, #c7c9d1);
  cursor: pointer;
  transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
  white-space: nowrap;
}
.layout-btn:hover {
  background: var(--bg-card-hover, #1c1c24);
  color: var(--text, #fff);
  border-color: var(--accent, #7c3aed);
}
.layout-btn-primary {
  background: var(--accent, #7c3aed);
  color: #fff;
  border-color: var(--accent, #7c3aed);
}
.layout-btn-primary:hover {
  background: var(--accent-hover, #8b5cf6);
  color: #fff;
}
.layout-btn.hidden { display: none; }

/* Hide the whole layout mechanic on narrow viewports — mobile uses
   the plain stacked bento grid (GridStack is never initialised there). */
@media (max-width: 1023px) {
  .layout-controls { display: none !important; }
}

/* --- GridStack <-> bento glue ---
   When .bento-grid becomes .grid-stack, the original 12-col CSS grid
   rules must stand down so GridStack's absolute positioning drives
   layout. The cards themselves keep all their .bento-card styling
   because we add .grid-stack-item-content to the SAME element. */
.bento-grid.grid-stack {
  display: block;       /* GridStack manages positioning, not CSS grid */
}
.bento-grid.grid-stack > .grid-stack-item > .grid-stack-item-content {
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: auto;       /* tall content (launcher etc.) scrolls within its tile */
  margin: 0;
}
/* Kill the per-card entrance slide once inside GridStack — it fights the
   absolute transforms GridStack applies and causes a flash on mount. */
.bento-grid.grid-stack .bento-card {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}

/* --- Edit-mode visual cues --- */
.bento-grid.sb-editing .grid-stack-item-content.bento-card {
  outline: 2px dashed var(--accent, #7c3aed);
  outline-offset: -2px;
  cursor: grab;
}
.bento-grid.sb-editing .grid-stack-item-content.bento-card:active {
  cursor: grabbing;
}
/* Make the header read as a drag handle while editing. */
.bento-grid.sb-editing .bento-card-header {
  cursor: grab;
}
.bento-grid.sb-editing .bento-card-header::after {
  content: "\2630";   /* hamburger — "drag me" affordance */
  margin-left: 8px;
  color: var(--accent, #7c3aed);
  font-size: 13px;
  opacity: 0.8;
}
/* GridStack resize handle — tint it to the brand accent, solid color. */
.bento-grid.sb-editing .ui-resizable-se {
  background: var(--accent, #7c3aed);
  border-radius: 3px;
  width: 12px;
  height: 12px;
  right: 4px;
  bottom: 4px;
  opacity: 0.85;
}
/* Drop placeholder while dragging — solid translucent accent, no gradient. */
.bento-grid .grid-stack-placeholder > .placeholder-content {
  background: var(--accent-soft, rgba(124,58,237,0.12));
  border: 2px dashed var(--accent, #7c3aed);
  border-radius: 14px;
}

/* ============================================================
   ADD-WIDGET picker + added widgets (Money Saved, etc.)
   Flat, solid colors only — matches the bento card surface.
   ============================================================ */

/* --- Picker popover --- */
.sb-widget-picker {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: 260px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border, #2a2e3a);
  background: var(--bg-1, #14141a);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.sb-widget-picker-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted, #8a8d98);
  padding: 4px 6px 8px;
}
.sb-widget-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sb-widget-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  font: inherit;
  text-align: left;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--bg-2, #1c1c24);
  color: var(--text, #fff);
  cursor: pointer;
  transition: background 120ms ease-out, border-color 120ms ease-out;
}
.sb-widget-opt:hover {
  background: var(--bg-card-hover, #232331);
  border-color: var(--accent, #7c3aed);
}
.sb-widget-opt-name { font-size: 14px; font-weight: 600; }
.sb-widget-opt-add {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent, #7c3aed);
}
.sb-widget-opt.is-soon {
  cursor: default;
  opacity: 0.45;
  background: var(--bg-2, #1c1c24);
  border-color: transparent;
}
.sb-widget-opt.is-soon:hover { background: var(--bg-2, #1c1c24); border-color: transparent; }
.sb-widget-opt-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #8a8d98);
  border: 1px solid var(--border, #2a2e3a);
  border-radius: 999px;
  padding: 2px 8px;
}

/* --- Added widget card: remove button (edit mode only) --- */
.sb-added-card { position: relative; }
.sb-widget-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: none;             /* shown only while editing */
  width: 24px;
  height: 24px;
  line-height: 1;
  font-size: 12px;
  border-radius: 7px;
  border: 1px solid var(--border, #2a2e3a);
  background: var(--bg-2, #1c1c24);
  color: var(--text-secondary, #c7c9d1);
  cursor: pointer;
  transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
}
.bento-grid.sb-editing .sb-added-card .sb-widget-remove { display: inline-flex; align-items: center; justify-content: center; }
.sb-widget-remove:hover {
  background: #3a1c1c;
  color: #ff6b6b;
  border-color: #ff6b6b;
}

/* --- Money Saved widget content --- */
.sb-money-body { display: flex; flex-direction: column; gap: 6px; }
.sb-money-figure {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text, #fff);
  letter-spacing: -0.02em;
}
.sb-money-per {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary, #c7c9d1);
  margin-left: 6px;
  letter-spacing: 0;
}
.sb-money-year {
  font-size: 12.5px;
  color: var(--text-secondary, #c7c9d1);
}
.sb-money-breakdown {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted, #8a8d98);
}
.sb-money-item { color: var(--text-secondary, #c7c9d1); white-space: nowrap; }
.sb-money-amt { color: var(--accent, #7c3aed); font-weight: 600; }
.sb-money-dot { color: var(--text-muted, #555); }
.sb-money-more {
  color: var(--text-muted, #8a8d98);
  font-weight: 600;
}
.sb-money-note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted, #8a8d98);
}
.sb-money-empty {
  font-size: 13px;
  color: var(--text-secondary, #c7c9d1);
  line-height: 1.5;
}
