/* ═══ UI Components v2 ══════════════════════════════════════════════════════
   Toast v2 (stacking + undo), Skeleton, Breadcrumbs, Toggle-Switch,
   Mobile Bottom-Nav, A11y focus styles. Theme-aware via :root variables.
   =========================================================================== */

/* ── Theme: light-mode overrides ─────────────────────────────────────────── */
html[data-theme="light"] {
  --bg:     #f5f5f7;
  --bg2:    #ffffff;
  --bg3:    #e7e7eb;
  --bg4:    #eeeef1;
  --text:   #18181b;
  --text2:  #4b4b52;
  --text3:  #77777e;
  --purp-glow: rgba(145,70,255,.10);
  --card-shadow: 0 1px 2px rgba(0,0,0,.04);
  --card-shadow-hover: 0 0 0 1px rgba(145,70,255,.20);
  --glow-purple: 0 0 20px rgba(145,70,255,.04);
}
html[data-theme="light"] body { background: var(--bg); }
html[data-theme="light"] .sidebar { background: rgba(255,255,255,.85); border-right-color: rgba(0,0,0,.08); }

/* ── Toast v2 ─────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100vh - 48px);
  overflow: hidden; pointer-events: none;
}
#toasts .toast {
  pointer-events: auto;
  position: relative;
  display: flex; align-items: center; gap: 8px;
  min-width: 200px; max-width: 360px;
  padding: 8px 32px 8px 12px;
  overflow: hidden;
}
.toast .toast-msg { flex: 1; min-width: 0; line-height: 1.4; }
.toast .toast-ico {
  flex-shrink: 0;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.toast .toast-ico svg {
  width: 12px; height: 12px;
  stroke: currentColor; fill: none;
  stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}
.toast.ok   .toast-ico { background: rgba(0,200,83,.15);  color: var(--green); }
.toast.err  .toast-ico { background: rgba(244,67,54,.15); color: var(--red); }
.toast.info .toast-ico { background: rgba(145,70,255,.15); color: var(--purple); }
.toast .toast-close {
  position: absolute; top: 6px; right: 6px;
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 16px; line-height: 1;
  width: 22px; height: 22px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}
.toast .toast-close:hover { background: var(--bg3); color: var(--text); }
.toast .toast-undo {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 3px;
  background: linear-gradient(180deg, rgba(145,70,255,.18), rgba(145,70,255,.10));
  color: var(--purple);
  border: 1px solid rgba(145,70,255,.35);
  border-radius: 999px;
  padding: 1px 6px 1px 5px;
  font-size: 10px; font-weight: 600;
  line-height: 1.3;
  letter-spacing: .1px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 0 0 0 rgba(145,70,255,0);
  transition: background .15s ease, border-color .15s ease, box-shadow .2s ease, transform .1s ease;
}
.toast .toast-undo .toast-undo-ico {
  width: 9px; height: 9px; flex-shrink: 0;
  stroke: currentColor; fill: none;
  stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}
.toast .toast-undo .toast-undo-count {
  font-variant-numeric: tabular-nums;
  opacity: .65;
  font-size: 9px;
  margin-left: 1px;
}
.toast .toast-undo:hover {
  background: linear-gradient(180deg, rgba(145,70,255,.30), rgba(145,70,255,.18));
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(145,70,255,.15);
}
.toast .toast-undo:hover .toast-undo-ico { transform: rotate(-25deg); transition: transform .25s ease; }
.toast .toast-undo:active { transform: translateY(1px); }
.toast .toast-undo:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(145,70,255,.35);
}
.toast .toast-undo:disabled {
  opacity: .55; cursor: progress;
  background: rgba(145,70,255,.10);
}
html[data-theme="light"] .toast .toast-undo {
  background: linear-gradient(180deg, rgba(145,70,255,.10), rgba(145,70,255,.04));
  border-color: rgba(145,70,255,.35);
}
html[data-theme="light"] .toast .toast-undo:hover {
  background: linear-gradient(180deg, rgba(145,70,255,.18), rgba(145,70,255,.10));
}
.toast .toast-progress {
  position: absolute; left: 0; bottom: 0;
  height: 2px; width: 100%;
  background: rgba(145,70,255,.35);
  transform-origin: left center;
  transform: scaleX(1);
}
.toast.ok   .toast-progress { background: rgba(0,200,83,.5); }
.toast.err  .toast-progress { background: rgba(244,67,54,.5); }
.toast .toast-progress.running { animation: toastProgress var(--toast-duration, 3500ms) linear forwards; }
@keyframes toastProgress { from { transform: scaleX(1);} to { transform: scaleX(0);} }
.toast.toast-out { animation: toastOut .2s ease forwards; }
@keyframes toastOut { to { opacity:0; transform: translateX(30px) scale(.96); } }

/* ── Skeleton loaders ─────────────────────────────────────────────────────── */
@keyframes skShimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.sk-wrap { display: flex; flex-direction: column; gap: 10px; }
.sk-line, .sk-cell, .sk-card {
  background: linear-gradient(90deg, var(--bg3) 0%, var(--bg4) 50%, var(--bg3) 100%);
  background-size: 800px 100%;
  animation: skShimmer 1.2s linear infinite;
  border-radius: 6px;
}
.sk-line { height: 12px; }
.sk-row td { padding: 10px 8px; }
.sk-cell { height: 12px; border-radius: 4px; }
.sk-card { height: 80px; border-radius: 10px; margin-bottom: 10px; }

/* ── Breadcrumbs ──────────────────────────────────────────────────────────── */
.breadcrumbs { font-size: 12px; color: var(--text3); margin-bottom: 10px; }
.breadcrumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.breadcrumbs .crumb { display: inline-flex; align-items: center; }
.breadcrumbs .crumb-btn {
  background: none; border: none;
  color: var(--text3); cursor: pointer;
  padding: 2px 6px; border-radius: 4px;
  font-family: inherit; font-size: 12px;
  transition: color .15s, background .15s;
}
.breadcrumbs .crumb-btn:hover { color: var(--purple); background: rgba(145,70,255,.06); }
.breadcrumbs .crumb-sep { color: var(--text3); padding: 0 4px; opacity: .6; }
.breadcrumbs .crumb.current { color: var(--text); font-weight: 600; padding: 2px 6px; }

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.toggle {
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none;
  font-size: 13px;
}
.toggle input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.toggle .toggle-track {
  position: relative;
  width: 38px; height: 22px;
  background: var(--bg3);
  border-radius: 11px;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle .toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: var(--text2);
  border-radius: 50%;
  transition: left .2s cubic-bezier(.4,.0,.2,1), background .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked ~ .toggle-track { background: var(--purple); }
.toggle input:checked ~ .toggle-track .toggle-thumb { left: 18px; background: #fff; }
.toggle input:focus-visible ~ .toggle-track { box-shadow: 0 0 0 3px rgba(145,70,255,.3); }
.toggle.is-disabled { opacity: .5; cursor: not-allowed; }
.toggle.is-disabled input { pointer-events: none; }
.toggle .toggle-dirty {
  display: none;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--yellow);
  margin-left: 2px;
  box-shadow: 0 0 0 0 rgba(255,167,38,.6);
  animation: dirtyPulse 1.4s infinite;
}
.toggle.is-dirty .toggle-dirty { display: inline-block; }
@keyframes dirtyPulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,167,38,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(255,167,38,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,167,38,0); }
}
.toggle.is-saved .toggle-label::after {
  content: '✓'; color: var(--green);
  margin-left: 6px; font-weight: 700;
  animation: savedFade 1.4s ease forwards;
}
@keyframes savedFade { from { opacity:0; transform: translateY(-4px);} to { opacity:1; transform:none;} 100%{opacity:0;} }
.toggle .toggle-label { color: var(--text); }

/* ── Mobile Bottom-Nav ────────────────────────────────────────────────────── */
#mobile-bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 200;
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.35);
  padding: 4px 0 max(4px, env(safe-area-inset-bottom));
  width: 100vw;
  max-width: 100vw;
  overflow: hidden;
  box-sizing: border-box;
}
/* Fade-hint on the right edge so the user sees there are more tabs to scroll to. */
#mobile-bottom-nav::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 28px;
  pointer-events: none;
  background: linear-gradient(to right,
    color-mix(in srgb, var(--bg2) 0%, transparent),
    color-mix(in srgb, var(--bg2) 92%, transparent));
}
#mobile-bottom-nav .mbn-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hov) var(--border);
  scroll-snap-type: x proximity;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
}
#mobile-bottom-nav .mbn-row::-webkit-scrollbar {
  height: 4px;
}
#mobile-bottom-nav .mbn-row::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 2px;
}
#mobile-bottom-nav .mbn-row::-webkit-scrollbar-thumb {
  background: var(--border-hov);
  border-radius: 2px;
}
#mobile-bottom-nav .mbn-row::-webkit-scrollbar-thumb:hover {
  background: var(--purple);
}
#mobile-bottom-nav .mbn-btn {
  background: none; border: none;
  color: var(--text3);
  padding: 6px 4px;
  font-size: 10px; font-weight: 500;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  transition: color .15s, background-color .15s;
  font-family: inherit;
  flex: 0 0 auto;
  min-width: 68px;
  border-radius: 8px;
}
#mobile-bottom-nav .mbn-btn svg { width: 20px; height: 20px; }
#mobile-bottom-nav .mbn-btn.active,
#mobile-bottom-nav .mbn-btn[aria-current="page"] { color: var(--purple); }
#mobile-bottom-nav .mbn-btn:active { background: var(--purp-glow); }

@media (max-width: 768px) {
  #mobile-bottom-nav { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.mobile-open { transform: translateX(0); }
  body.has-mobile-nav #page-app { padding-left: 0 !important; padding-bottom: 62px; }
  body.has-mobile-nav .site-footer.has-sidebar { margin-left: 0; margin-bottom: 62px; }
  body.has-mobile-nav .modal-backdrop:not(.modal-inline) { left: 0 !important; }
  body.has-mobile-nav #page-app > .site-footer,
  body.has-mobile-nav .site-footer { padding-bottom: calc(8px + 62px); }
  /* Fixed-position tab panels (e.g. Multichat, Sniper profile) must stop above the bottom nav
     and span the full viewport width since the sidebar is off-canvas on mobile. */
  body.has-mobile-nav .mc-tab-panel { bottom: 62px !important; }
  body.has-mobile-nav #sc-profile { left: 0 !important; bottom: 62px !important; }
  /* Viewport-height layouts need to account for the 62px nav. */
  body.has-mobile-nav .chat-layout { height: calc(100vh - 56px - 62px); }
}

/* ── A11y focus styles ───────────────────────────────────────────────────── */
:focus:not(:focus-visible) { outline: none; }
:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, .btn:focus-visible, .tab-btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}
/* Skip-link for keyboard users */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--purple); color: #fff;
  padding: 8px 16px; border-radius: 0 0 8px 0;
  z-index: 100000; font-weight: 600;
}
.skip-link:focus { left: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Theme toggle button ──────────────────────────────────────────────────── */
.theme-toggle {
  background: none; border: 1px solid var(--bg3);
  border-radius: 8px;
  padding: 6px; cursor: pointer;
  color: var(--text2);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}
.theme-toggle:hover { color: var(--purple); border-color: var(--purple); background: rgba(145,70,255,.06); }
.theme-toggle .sun { display: none; }
html[data-theme="light"] .theme-toggle .sun { display: block; }
html[data-theme="light"] .theme-toggle .moon { display: none; }

/* ── Virtual scroll ──────────────────────────────────────────────────────── */
.vscroll-wrap { position: relative; overflow-y: auto; }
.vscroll-spacer { width: 1px; pointer-events: none; }
.vscroll-rows { position: absolute; top: 0; left: 0; right: 0; will-change: transform; }
