/* ─────────────────────────────────────────────────────────────────────────────
   global.css — Design tokens, resets, base styles, utility classes
   zeni.gg · Rosé Tournament Theme
   ───────────────────────────────────────────────────────────────────────────── */

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  /* Core Palette */
  --color-bg:           #0d0a0e;
  --color-surface:      #1a1118;
  --color-surface-2:    #241820;
  --color-border:       #3a2535;
  --color-accent:       #e8547a;
  --color-accent-soft:  #c43d62;
  --color-accent-glow:  rgba(232, 84, 122, 0.18);
  --color-gold:         #d4a843;
  --color-text:         #f0e8ed;
  --color-text-muted:   #9a7d8a;
  --color-text-dim:     #5c4452;
  --color-success:      #4ecb8d;
  --color-error:        #e85454;
  --color-warning:      #e8a054;

  /* Typography */
  --font-display: 'Rajdhani', sans-serif;
  --font-body:    'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Spacing Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;

  /* Radius */
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-card:  0 2px 16px rgba(0, 0, 0, 0.4);
  --shadow-glow:  0 0 24px var(--color-accent-glow);
  --shadow-float: 0 8px 32px rgba(0, 0, 0, 0.6);

  /* Z-Index Scale */
  --z-base:   0;
  --z-card:   10;
  --z-sticky: 100;
  --z-navbar: 200;
  --z-drawer: 300;
  --z-modal:  400;
  --z-toast:  500;

  /* Layout */
  --navbar-height:     60px;
  --player-bar-height: 72px;
  --drawer-width:      280px;

  /* Cover Art Sizes */
  --cover-sm: 40px;
  --cover-md: 56px;
  --cover-lg: 200px;
}

/* ─── Box Model Reset ─────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
input, textarea, select { font: inherit; color: inherit; background: none; border: none; outline: none; }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-dim); }

/* ─── Selection ──────────────────────────────────────────────────────────── */
::selection { background: var(--color-accent); color: #fff; }

/* ─── Focus Visible ──────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ─── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.display-font { font-family: var(--font-display); }
.mono-font    { font-family: var(--font-mono); }

.text-accent  { color: var(--color-accent); }
.text-muted   { color: var(--color-text-muted); }
.text-dim     { color: var(--color-text-dim); }
.text-gold    { color: var(--color-gold); }
.text-success { color: var(--color-success); }
.text-error   { color: var(--color-error); }

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Flex Utilities ─────────────────────────────────────────────────────── */
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between{ justify-content: space-between; }
.flex-1         { flex: 1; }
.flex-shrink-0  { flex-shrink: 0; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }

/* ─── Divider ────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-3) 0;
  flex-shrink: 0;
}

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease, opacity 0.15s;
  user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-accent-soft);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
  border-color: var(--color-text-dim);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}
.btn-icon:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-full { width: 100%; }

/* ─── Live Dot ───────────────────────────────────────────────────────────── */
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-error);
  flex-shrink: 0;
  animation: pulse-live 1.8s ease-in-out infinite;
}

.offline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-dim);
  flex-shrink: 0;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(232, 84, 84, 0.4); }
  50%       { opacity: 0.7; transform: scale(0.9); box-shadow: 0 0 0 4px rgba(232, 84, 84, 0); }
}

/* ─── Cover Art ──────────────────────────────────────────────────────────── */
.cover-art {
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-surface-2);
  flex-shrink: 0;
}

.cover-art--sm { width: var(--cover-sm); height: var(--cover-sm); }
.cover-art--md { width: var(--cover-md); height: var(--cover-md); }
.cover-art--lg { width: var(--cover-lg); height: var(--cover-lg); border-radius: var(--radius-md); }

/* Fallback when no image */
.cover-art--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-dim);
  font-size: 1.4em;
}

/* ─── Offline State ──────────────────────────────────────────────────────── */
.offline-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}

.offline-state__icon {
  width: 44px;
  height: 44px;
  color: var(--color-text-dim);
  opacity: 0.5;
}

.offline-state__title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.offline-state__desc {
  font-size: 0.82rem;
  color: var(--color-text-dim);
  line-height: 1.6;
  max-width: 240px;
}

/* ─── Badge ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-live {
  background: rgba(232, 84, 84, 0.15);
  color: var(--color-error);
  border: 1px solid rgba(232, 84, 84, 0.3);
}

.badge-offline {
  background: var(--color-surface-2);
  color: var(--color-text-dim);
  border: 1px solid var(--color-border);
}

/* ─── Input ──────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.input::placeholder { color: var(--color-text-dim); }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  bottom: calc(var(--player-bar-height) + var(--space-4));
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: 320px;
}

.toast {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-float);
  font-size: 0.85rem;
  animation: toast-in 0.22s ease-out;
}

.toast--tip   { border-left: 3px solid var(--color-gold); }
.toast--error { border-left: 3px solid var(--color-error); }
.toast--info  { border-left: 3px solid var(--color-accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Loader Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Page Fade ──────────────────────────────────────────────────────────── */
.page-enter {
  animation: page-fade 0.2s ease-out;
}

@keyframes page-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── F30 Polish ─────────────────────────────────────────────────────────────
   Mobile refinements, better empty states, edge cases
   ───────────────────────────────────────────────────────────────────────────── */

/* Prevent tap highlight on interactive elements */
button, a, [role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* Smoother touch scrolling */
.main-content,
.queue-panel__body,
.drawer {
  -webkit-overflow-scrolling: touch;
}

/* Ensure modals don't overflow on small screens */
@media (max-width: 520px) {
  .modal {
    max-width: 100% !important;
    margin: var(--space-2);
    border-radius: var(--radius-md);
  }

  .modal-root {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
}

/* Admin table mobile scroll */
@media (max-width: 640px) {
  .dashboard-page { padding: var(--space-3); }
  .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
  .dashboard-header { flex-wrap: wrap; gap: var(--space-3); }
  .dashboard-header > div:last-child { width: 100%; justify-content: flex-start; }
}

/* Better focus states for keyboard nav */
.navbar__link:focus-visible,
.drawer__nav-link:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Error boundary — full page error */
.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-9) var(--space-5);
  text-align: center;
  min-height: 300px;
}

.page-error__code {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 500;
  color: var(--color-text-dim);
  line-height: 1;
}

.page-error__title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.page-error__desc {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  max-width: 300px;
  line-height: 1.6;
}

/* Smooth drawer open/close for iOS */
.drawer {
  will-change: transform;
}

/* Prevent body scroll when drawer is open */
body.drawer-open {
  overflow: hidden;
}

/* Improve offline state on very small screens */
@media (max-width: 360px) {
  .offline-state { padding: var(--space-5) var(--space-3); }
  .offline-state__icon { width: 36px; height: 36px; }
}

/* Toast container — ensure not covered by player bar */
.toast-root {
  bottom: calc(var(--player-bar-height) + var(--space-3));
}

/* Smooth page transitions */
.main-content > * {
  animation: page-fade 0.18s ease-out;
}

/* Table base styles for admin */
table { border-collapse: collapse; }
th, td { vertical-align: middle; }

/* ─── Toaster ────────────────────────────────────────────────────────────────
   Replaces the old basic toast styles. All toasts use .toast--visible /
   .toast--hiding for enter/exit animations.
   ───────────────────────────────────────────────────────────────────────────── */

/* Reset old toast styles */
.toast-root {
  position: fixed;
  bottom: calc(var(--player-bar-height) + var(--space-4));
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: 340px;
  width: calc(100vw - var(--space-8));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3);
  box-shadow: var(--shadow-float);
  font-size: 0.85rem;
  line-height: 1.4;
  pointer-events: all;
  cursor: pointer;
  user-select: none;

  /* Entry state — starts translated + invisible */
  opacity: 0;
  transform: translateX(calc(100% + var(--space-4)));
  transition:
    opacity   280ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Visible — slides in */
.toast--visible {
  opacity: 1;
  transform: translateX(0);
}

/* Hiding — slides out */
.toast--hiding {
  opacity: 0;
  transform: translateX(calc(100% + var(--space-4)));
  pointer-events: none;
}

/* Icon */
.toast__icon {
  flex-shrink: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Message */
.toast__message {
  flex: 1;
  color: var(--color-text);
  word-break: break-word;
}

/* Close button */
.toast__close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--color-text-dim);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  padding: 0;
  line-height: 1;
  margin-left: var(--space-1);
}

.toast__close:hover {
  color: var(--color-text);
  background: rgba(255,255,255,0.06);
}

/* Type accent strips */
.toast--info    { border-left: 3px solid var(--color-accent); }
.toast--success { border-left: 3px solid var(--color-success); }
.toast--tip     { border-left: 3px solid var(--color-gold); }
.toast--error   { border-left: 3px solid var(--color-error); }
.toast--warn    { border-left: 3px solid var(--color-warning); }

.toast--info    .toast__icon { color: var(--color-accent); }
.toast--success .toast__icon { color: var(--color-success); }
.toast--tip     .toast__icon { color: var(--color-gold); }
.toast--error   .toast__icon { color: var(--color-error); }
.toast--warn    .toast__icon { color: var(--color-warning); }

/* Mobile: full width, bottom sheet feel */
@media (max-width: 480px) {
  .toast-root {
    left: var(--space-3);
    right: var(--space-3);
    width: auto;
    max-width: none;
  }

  .toast {
    transform: translateY(calc(100% + var(--space-4)));
  }

  .toast--visible  { transform: translateY(0); }
  .toast--hiding   { transform: translateY(calc(100% + var(--space-4))); }
}

/* ─── Guard / Access Denied page ─────────────────────────────────────────────
   Rendered by router.js when a guarded route is accessed without permission.
   ───────────────────────────────────────────────────────────────────────────── */

.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-9) var(--space-5);
  text-align: center;
  min-height: 60vh;
}

.page-error__code {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 500;
  color: var(--color-border);
  line-height: 1;
}

.page-error__title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text);
}

.page-error__desc {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  max-width: 320px;
  line-height: 1.6;
}
