/* ═══════════════════════════════════════════════════════════════════════════
   AIO_Bot SPA — polish layer
   ─────────────────────────────────────────────────────────────────────────
   Additive cascade on top of style.css + ui-components.css. Only colors,
   hover, focus, transitions, spacing, and cross-tab consistency. No layout
   changes, no selector overrides that alter width/position/display.

   Load order: style.css → ui-components.css → polish.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ═══ Grid tokens ═════════════════════════════════════════════════════════
   Unified responsive grids: repeat(auto-fill, minmax(CARD_MIN, 1fr)) gives
   same-width cards at any viewport — 1 col on mobile, grows naturally on
   desktop, capped by --grid-max-width so cards don't balloon on 21:9. */
:root {
  --card-min-sm:    200px;  /* dense compact grids (stats, chips) */
  --card-min-md:    260px;  /* default feature cards */
  --card-min-lg:    320px;  /* spacious hero grids */
  --card-min-wide:  380px;  /* two-column request grids */
  --grid-gap:       16px;
  --grid-gap-sm:    12px;
  --grid-max-width: 1800px; /* soft cap for ultrawide (21:9) */
}

/* ═══ Global ═══════════════════════════════════════════════════════════════ */

/* Unified focus ring — applies everywhere unless an element explicitly opts
   out with :focus:not(:focus-visible). Matches public.css. */
:where(.tab-btn, .btn, .icon-btn, button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Button press feedback — tiny translate-Y for a tactile click. */
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn { transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .08s ease; }

/* Consistent disabled state across every button flavor. */
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: .5; cursor: not-allowed; transform: none !important;
}

/* Scrollbar — single look across the whole SPA, tokenized. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-hov) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-hov);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--purple); background-clip: padding-box; border: 2px solid transparent; }

/* Selection color matches the brand. */
::selection { background: var(--purple); color: #fff; }

/* ═══ Cards ════════════════════════════════════════════════════════════════ */

/* Subtle hover lift on cards that aren't otherwise interactive. Excludes
   cards with role="button"/<a> wrappers which handle their own states. */
.card {
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.card:hover:not(.card-static):not(.bot-card) {
  border-color: var(--border-hov);
}

/* Bot cards: stronger hover signature — they are clickable tiles. */
.bot-card {
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.bot-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
  border-color: var(--border-hov);
}

/* Card header line-weight alignment. */
.card-hdr, .card-title {
  letter-spacing: -.01em;
}

/* ═══ Tables ═══════════════════════════════════════════════════════════════ */

/* Shared row hover + sticky-header polish. Uses :where() so we never
   bump specificity over page-specific rules. */
:where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) table {
  border-collapse: separate;
  border-spacing: 0;
}
:where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg4);
  color: var(--text2);
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
:where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) tbody tr {
  transition: background-color .12s ease;
}
:where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) tbody tr:hover td {
  background: var(--bg4);
}
:where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) td {
  border-bottom: 1px solid var(--border);
}

/* Tabular numerals wherever numbers are displayed — math code, counters,
   table cells of numeric nature. */
code, kbd, .mono, .num, .tabular, td[data-num],
.sc-chatlog-time, .mc-time, .log-time {
  font-variant-numeric: tabular-nums;
}

/* ═══ Forms ════════════════════════════════════════════════════════════════ */

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select, textarea {
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purp-glow);
}
input::placeholder, textarea::placeholder { color: var(--text3); opacity: 1; }

/* Disabled form controls — muted but still legible. */
input:disabled, select:disabled, textarea:disabled {
  opacity: .55; cursor: not-allowed;
}

/* Checkbox/radio accent color follows theme. */
input[type="checkbox"], input[type="radio"] { accent-color: var(--purple); }

/* ═══ Modals ═══════════════════════════════════════════════════════════════ */

.modal-backdrop {
  backdrop-filter: blur(8px) saturate(1.2);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
}
.modal {
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow-hover);
}

/* ═══ Badges ═══════════════════════════════════════════════════════════════ */

.badge {
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

/* ═══ Empty states ════════════════════════════════════════════════════════ */

.empty-state,
.list-empty,
.no-results,
[class*="empty"] {
  color: var(--text3);
  text-align: center;
  padding: var(--s-6, 32px) var(--s-4, 16px);
  font-size: 14px;
  line-height: 1.6;
}

/* ═══ Tab panels — consistent enter transition ═════════════════════════════ */

.tab-panel { opacity: 0; transition: opacity .15s ease; }
.tab-panel.active { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .tab-panel { opacity: 1; transition: none; }
}

/* ═══ Per-tab refinements ═════════════════════════════════════════════════ */

/* ── Dashboard ── */
#tab-dashboard .bot-card h3,
#tab-dashboard .card-title { letter-spacing: -.015em; }

/* ── Modules ── */
#tab-modules .mod-card {
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
#tab-modules .mod-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
}
#tab-modules .mod-filter-pill {
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

/* ── Channels ── */
#tab-channels .channel-item,
#tab-channels [class*="channel"]:where(li, .card) {
  transition: background-color .15s ease, border-color .15s ease;
}

/* ── Logs ── */
#tab-logs .log-list { font-variant-numeric: tabular-nums; }
#tab-logs .log-list > * { transition: background-color .12s ease; }
#tab-logs .log-list > :hover { background: var(--bg4); }

/* ── Settings ── */
#tab-settings .card + .card { margin-top: 16px; }
#tab-settings label { color: var(--text2); font-weight: 500; }
#tab-settings .form-group { display: flex; flex-direction: column; gap: 6px; }

/* ── Chat (Lounge) ── */
#tab-chat .chat-message,
#tab-chat [class*="message"] {
  transition: background-color .1s ease;
}

/* ── Sniper ── */
#tab-sniper .sc-card,
#tab-sniper .card {
  transition: border-color .2s ease, box-shadow .2s ease;
}
#tab-sniper .sc-chatlog-entry {
  border-left: 2px solid transparent;
  transition: border-color .12s ease, background-color .12s ease;
}
#tab-sniper .sc-chatlog-entry:hover {
  border-left-color: var(--purple);
  background: var(--bg4);
}
#tab-sniper .sc-server-name {
  font-weight: 600;
  letter-spacing: -.005em;
}

/* Donator tier accents are handled in style.css (.donator-tier-card::before
   per-tier rules: purple/gold/green hairlines). */

/* ── Subathon ── */
#tab-subathon .timer-preview,
#tab-subathon [id*="preview"] {
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

/* ── Multi-Chat ── */
#tab-multichat .mc-auth-card,
#tab-multichat .mc-channels-card,
#tab-multichat .mc-monitor-card,
#tab-multichat .mc-activity-card {
  transition: border-color .2s ease, box-shadow .2s ease;
}
#tab-multichat .mc-auth-card:hover,
#tab-multichat .mc-channels-card:hover,
#tab-multichat .mc-monitor-card:hover {
  border-color: var(--border-hov);
}
#tab-multichat .mc-activity-feed { font-variant-numeric: tabular-nums; }

/* Multichat alert items — subtle entry transition. Caller sets opacity via JS. */
#tab-multichat .mc-alerts-feed > *,
#tab-multichat .mc-activity-feed > * {
  transition: background-color .12s ease;
}

/* ═══ Mobile refinements ═══════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Give card grids some breathing room on small screens. */
  .card { padding-block: 16px; }
  /* Reduce table sticky-header side-padding for thumbable reach. */
  :where(.tbl-wrap, .data-table) thead th {
    padding-inline: 10px;
  }
  /* Make sure modals don't clip under the mobile bottom-nav. */
  body.has-mobile-nav .modal {
    max-height: calc(100dvh - 64px - env(safe-area-inset-bottom, 0px) - 32px);
    overflow-y: auto;
  }
}

/* ═══ Light-theme specific micro-adjustments ═══════════════════════════════ */

html[data-theme="light"] .modal-backdrop {
  background: var(--overlay);
}
html[data-theme="light"] :where(.tbl-wrap, .data-table, #tab-logs, #tab-sniper) thead th {
  background: var(--bg4);
  color: var(--text2);
}
html[data-theme="light"] #tab-sniper .sc-chatlog-entry:hover,
html[data-theme="light"] #tab-logs .log-list > :hover,
html[data-theme="light"] :where(.tbl-wrap, .data-table) tbody tr:hover td {
  background: var(--bg4);
}

/* ═══ Unified grid layout (responsive + ultrawide cap) ═══════════════════
   Converts existing grids — without touching HTML — into a single
   coherent pattern:
     • Below --card-min-* ≈ 1 column (mobile).
     • Mid-range ≈ 2–4 columns (16:9 laptop → 16:9 desktop).
     • Ultra-wide (21:9) capped by --grid-max-width so cards keep a
       humane width instead of stretching to 500px+.
   ───────────────────────────────────────────────────────────────────────── */

/* Compact grids (stats, small chips) */
:where(.stats, .dash-stats-grid) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-sm), 1fr));
  gap: var(--grid-gap-sm);
}

/* Default feature-card grids — modules, channel lists, multichat lists.
   Donator tier-grid and perks-grid are intentionally excluded: they carry
   their own bespoke layouts (comparison-table tier columns, 2-col perk
   index) defined in style.css. */
:where(#module-grid, .module-grid,
       .mc-channel-list, .dash-channel-grid) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-md), 1fr));
  gap: var(--grid-gap);
}

/* Wider pair grids — requests, 2-column info panels */
:where(.dash-requests-grid, .dash-sc-grid) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-wide), 1fr));
  gap: var(--grid-gap);
}

/* ═══ Unified tab-panel content width ═══════════════════════════════════
   Cap the tab-panel itself so every section inside (headers, cards,
   grids, tables) shares the same visual column. Excludes full-bleed
   tabs (chat has its own centered layout; multichat + sniper need
   full tab-panel width for their scrollable viewers). */
.tab-panel.active:not(#tab-chat):not(#tab-multichat) {
  max-width: var(--grid-max-width);
  margin-inline: auto;
  padding-inline: clamp(16px, 2vw, 32px);
  box-sizing: border-box;
  width: 100%;
}
/* Direct children also center. This fixes tabs whose content is a stack
   of narrow cards (Subathon: ~530px timer card, Settings forms) — without
   this they'd be left-aligned inside the much wider 1800px tab-panel. */
.tab-panel.active:not(#tab-chat):not(#tab-multichat) > * {
  margin-inline: auto;
}

/* Public pages (landing + legal): align with same pattern so / → /app has
   visual continuity. Overrides the fixed 3-col in public.css above 900px. */
@media (min-width: 640px) {
  .grid.grid--3 {
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min-md, 260px), 1fr));
    max-width: var(--grid-max-width, 1800px);
    margin-inline: auto;
  }
  .grid.grid--2,
  .grid.grid--2\@lg {
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min-wide, 380px), 1fr));
    max-width: var(--grid-max-width, 1800px);
    margin-inline: auto;
  }
}

/* Equal-height assurance — all known card classes fill their grid track.
   Donator grids excluded: tier columns equalize via their own grid track
   sizing, perk rows are list items and shouldn't be stretched. */
.mod-card, .bot-card, .card-link,
.mc-channels-card, .mc-monitor-card, .mc-activity-card,
.mc-channel-list > *, .dash-channel-grid > * {
  height: 100%;
  min-width: 0;  /* allow flex/grid children to shrink below content width */
}

/* ═══ Ultra-wide (21:9) — grid cap only ═══════════════════════════════════
   Grid containers already carry their own max-width via --grid-max-width;
   no blanket tab-panel cap, because layouts like Chat, Multi-Chat, and
   Sniper Profile need full width of the tab-panel to breathe on
   ultrawides. */

/* Chat (Lounge): let the chat card occupy the available space instead of
   sitting pinned to one edge on ultrawide. Only applies when the tab is
   the active one — never override display:none on inactive tabs. */
#tab-chat:not(.active) { display: none !important; }
#tab-chat.active {
  display: flex;
  justify-content: center;
}
#tab-chat.active > .chat-layout,
#tab-chat.active > .card,
#tab-chat.active > :first-child:not(.sidebar) {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
}
@media (min-width: 1800px) {
  #tab-chat.active > .chat-layout,
  #tab-chat.active > .card,
  #tab-chat.active > :first-child:not(.sidebar) {
    max-width: 1280px;
  }
}

/* On landscape tablets / 16:9 laptops, slightly tighter max so cards don't
   feel too sparse. */
@media (min-width: 1400px) and (max-width: 1799.98px) {
  .grid.grid--3 { max-width: 1400px; }
}

/* ═══ Guide tab — visual refinement ═══════════════════════════════════════
   Larger search, accent-rail on open accordions, refined item rows with
   hover-indent, kbd-style chips for !commands, empty state. */

#tab-guide .guide-search-wrap { margin-block: 8px 28px; }
#tab-guide .guide-search {
  height: 46px;
  padding: 0 16px 0 44px;
  font-size: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
#tab-guide .guide-search-wrap svg {
  left: 14px;
  width: 18px; height: 18px;
  color: var(--text3);
  transition: color .15s ease;
}
#tab-guide .guide-search:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 4px var(--purp-glow), var(--card-shadow);
}
#tab-guide .guide-search-wrap:focus-within svg { color: var(--purple); }

#tab-guide .guide-acc {
  border-radius: 14px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
/* Left accent rail — fades in when the accordion opens. */
#tab-guide .guide-acc::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(to bottom, var(--purple), var(--purp2));
  opacity: 0;
  transition: opacity .25s ease;
}
#tab-guide .guide-acc.open::before { opacity: 1; }

#tab-guide .guide-acc-header {
  padding: 16px 20px;
  gap: 14px;
  transition: background-color .15s ease;
}
#tab-guide .guide-acc-header:hover { background: var(--bg4); }
#tab-guide .guide-acc.open .guide-acc-header { background: transparent; }
#tab-guide .guide-acc-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  font-size: 16px;
  box-shadow: inset 0 0 0 1px var(--border);
}
#tab-guide .guide-acc-title {
  font-size: 15px;
  letter-spacing: -.01em;
}
#tab-guide .guide-acc-badge {
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
#tab-guide .guide-acc-chevron { transition: transform .25s var(--ease, cubic-bezier(.2,.8,.2,1)); }

#tab-guide .guide-section { padding: 0 20px; }

#tab-guide .guide-item {
  padding: 14px 0;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  transition: padding-left .15s ease;
}
#tab-guide .guide-item:hover { padding-left: 6px; }
#tab-guide .guide-item-dot {
  width: 8px; height: 8px;
  margin-top: 6px;
  background: var(--purple);
  box-shadow: 0 0 0 4px var(--purp-glow);
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}
#tab-guide .guide-item:hover .guide-item-dot {
  transform: scale(1.15);
  box-shadow: 0 0 0 6px var(--purp-glow);
}
#tab-guide .guide-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -.005em;
  margin-bottom: 4px;
}
#tab-guide .guide-desc { font-size: 13px; line-height: 1.65; color: var(--text2); }
#tab-guide .guide-desc em {
  color: var(--text);
  font-style: normal;
  font-weight: 600;
}

/* Inline command / code chips — give `!cmd` references a kbd feel. */
#tab-guide .guide-desc code {
  display: inline-block;
  background: var(--bg4);
  color: var(--purple);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 0 var(--border);
  line-height: 1.5;
}

/* Empty state when search filters everything out. */
#tab-guide .guide-acc.guide-acc-hidden { display: none; }
#tab-guide .guide-section:has(.guide-item:not(.guide-hidden))::after { content: none; }

/* Subtle per-section icon tint variation (already declared in style.css via
   .guide-acc-icon.icon-dashboard etc) — add a soft inset highlight on open
   so the active section feels lifted. */
#tab-guide .guide-acc.open .guide-acc-icon {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 25%, transparent),
              0 2px 8px color-mix(in srgb, currentColor 18%, transparent);
}

/* Respect reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  #tab-guide .guide-acc::before,
  #tab-guide .guide-acc-chevron,
  #tab-guide .guide-item,
  #tab-guide .guide-item-dot { transition: none !important; }
  #tab-guide .guide-item:hover { padding-left: 0; }
}

/* ═══ Print ════════════════════════════════════════════════════════════════ */

@media print {
  #sidebar, #mobile-bottom-nav, .topbar, .modal-backdrop { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; }
}
