/* ═══════════════════════════════════════════════════════════════
   UI components — buttons, cards, tables, forms, badges, modals
   ═══════════════════════════════════════════════════════════════ */

/* ══════════ BUTTONS ══════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 var(--s-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  font-weight: var(--fw-semi);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--fast), border-color var(--fast), color var(--fast);
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

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

.btn-secondary {
  background: var(--bg-raised);
  border-color: var(--line);
  color: var(--tx);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-overlay); border-color: var(--line-strong); }

.btn-ghost { background: transparent; color: var(--tx-2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--tx); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); }

/* Unsaved-changes state */
.btn-warning { background: var(--warn) !important; color: #1a1200 !important; }

.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--t-xs); }
.btn-xs { height: 26px; padding: 0 10px; font-size: var(--t-xs); }
.btn-lg { height: 42px; padding: 0 var(--s-6); font-size: var(--t-md); }

.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }

/* Small square icon button used inside rows/cards */
.icon-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-raised);
  color: var(--tx-2);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--fast);
}

.icon-btn:hover { border-color: var(--line-strong); color: var(--tx); background: var(--bg-overlay); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.primary:hover { background: var(--accent-hover); }

/* ══════════ CARD ══════════ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.card-pad { padding: var(--s-5); }

.card-header {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.card-header h3 {
  font-size: var(--t-md);
  font-weight: var(--fw-semi);
}

.card-body { padding: var(--s-5); }
.card-body.no-pad { padding: 0; }

/* ══════════ STATS ══════════ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}

/* One neutral surface for every tile; the accent is a small icon chip, not a
   full pastel fill. Four different pastel cards read as decoration, not data. */
.stat {
  position: relative;
  padding: var(--s-4);
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--fast);
}

.stat:hover { border-color: var(--line-strong); }

.stat-top {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}

.stat-ico {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  font-size: 13px;
  flex-shrink: 0;
}

.stat-ico.accent { background: var(--accent-soft); color: var(--accent); }
.stat-ico.live   { background: var(--live-soft);   color: var(--live); }
.stat-ico.ok     { background: var(--ok-soft);     color: var(--ok); }
.stat-ico.warn   { background: var(--warn-soft);   color: var(--warn); }

.stat-label {
  font-size: var(--t-xs);
  color: var(--tx-3);
  font-weight: var(--fw-med);
}

.stat-value {
  font-family: var(--font-num);
  font-size: var(--t-2xl);
  font-weight: var(--fw-bold);
  line-height: 1;
  letter-spacing: -0.02em;
}

/* ══════════ BADGES ══════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  font-size: var(--t-xs);
  font-weight: var(--fw-semi);
  white-space: nowrap;
  line-height: 1.5;
}

.badge-live    { background: var(--live-soft);   color: var(--live); }
.badge-success { background: var(--ok-soft);     color: var(--ok); }
.badge-info    { background: var(--info-soft);   color: var(--info); }
.badge-warn    { background: var(--warn-soft);   color: var(--warn); }
.badge-muted   { background: var(--bg-raised);   color: var(--tx-3); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }

/* pulsing dot for a running match */
.badge-live::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--live);
  animation: pulse 1.4s ease-in-out infinite;
}

/* ══════════ SEGMENTED TABS ══════════ */

.tabs-bar {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raised);
}

.tab-btn {
  padding: 6px var(--s-4);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--tx-2);
  font-size: var(--t-sm);
  font-weight: var(--fw-med);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--fast);
}

.tab-btn:hover { color: var(--tx); }

.tab-btn.active {
  background: var(--bg-overlay);
  color: var(--tx);
  font-weight: var(--fw-semi);
  box-shadow: var(--sh-sm);
}

/* Pill filter (chips) */
.chip {
  padding: 5px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--bg-surface);
  color: var(--tx-2);
  font-size: var(--t-xs);
  font-weight: var(--fw-med);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--fast);
}

.chip:hover { border-color: var(--line-strong); color: var(--tx); }

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: var(--fw-semi);
}

/* ══════════ FORMS ══════════ */

.form-group { margin-bottom: var(--s-4); }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: var(--t-xs);
  font-weight: var(--fw-med);
  color: var(--tx-2);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--tx);
  font-size: var(--t-sm);
  transition: border-color var(--fast), box-shadow var(--fast);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--tx-3); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-surface);
}

.form-textarea { min-height: 88px; resize: vertical; line-height: 1.6; }

.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-start: var(--s-8);
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%236d757f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left var(--s-3) center;
}

.form-hint {
  font-size: var(--t-xs);
  color: var(--tx-3);
  margin-top: 5px;
  line-height: 1.6;
}

/* two/three column form rows */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }

@media (max-width: 640px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* switch */
.switch {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  cursor: pointer;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--bg-overlay);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--fast), border-color var(--fast);
}

.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-full);
  background: var(--tx-3);
  transition: transform var(--fast), background var(--fast);
}

.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { background: #fff; transform: translateX(-16px); }

.switch-text b { display: block; font-size: var(--t-sm); font-weight: var(--fw-semi); }
.switch-text small { display: block; font-size: var(--t-xs); color: var(--tx-3); margin-top: 2px; line-height: 1.6; }

/* checkbox */
.check {
  appearance: none;
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--bg-raised);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: all var(--fast);
}

.check:checked { background: var(--accent); border-color: var(--accent); }

.check:checked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: no-repeat center / 11px url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 6.5L4.5 9 10 3.5'/%3E%3C/svg%3E");
}

/* ══════════ TABLE ══════════ */

.table-wrapper { width: 100%; overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: right;
  padding: var(--s-3) var(--s-4);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  font-size: var(--t-xs);
  font-weight: var(--fw-semi);
  color: var(--tx-3);
  white-space: nowrap;
}

.data-table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background var(--fast); }
.data-table tbody tr:hover { background: var(--bg-raised); }

.data-table td:first-child, .data-table th:first-child { text-align: center; }

/* rank pill */
.rank {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--r-sm);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  font-family: var(--font-num);
  font-size: var(--t-xs);
  font-weight: var(--fw-bold);
  color: var(--tx-2);
}

.rank.gold   { background: rgba(245, 165, 36, 0.16); border-color: rgba(245, 165, 36, 0.4); color: #f5a524; }
.rank.silver { background: rgba(163, 171, 184, 0.16); border-color: rgba(163, 171, 184, 0.4); color: #a3abb8; }
.rank.bronze { background: rgba(205, 127, 50, 0.16); border-color: rgba(205, 127, 50, 0.4); color: #cd7f32; }

/* cell with avatar + text */
.cell {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.cell-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.cell-title { font-weight: var(--fw-semi); color: var(--tx); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { font-size: var(--t-xs); color: var(--tx-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  object-fit: cover;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.crest { width: 22px; height: 22px; object-fit: contain; flex-shrink: 0; }

.metric {
  font-family: var(--font-num);
  font-size: var(--t-lg);
  font-weight: var(--fw-bold);
  color: var(--accent);
}

/* ══════════ EMPTY / LOADING ══════════ */

.empty-state {
  text-align: center;
  padding: var(--s-10) var(--s-5);
}

.empty-state-icon { font-size: 2rem; margin-bottom: var(--s-3); opacity: 0.5; }

.empty-state h4 {
  font-size: var(--t-md);
  font-weight: var(--fw-semi);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: var(--t-sm);
  color: var(--tx-3);
  max-width: 380px;
  margin: 0 auto;
  line-height: 1.7;
}

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-raised) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ══════════ NOTE / CALLOUT ══════════ */

.note {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  font-size: var(--t-sm);
  color: var(--tx-2);
  line-height: 1.7;
}

.note b { color: var(--tx); }
.note.warn { border-inline-start-color: var(--warn); }
.note.danger { border-inline-start-color: var(--danger); }
.note.ok { border-inline-start-color: var(--ok); }

/* ══════════ MODAL ══════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--base), visibility var(--base);
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  width: min(94vw, 720px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-overlay);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  transform: scale(0.97) translateY(6px);
  transition: transform var(--base);
}

.modal-overlay.active .modal { transform: none; }

.modal-sm { width: min(92vw, 460px); }
.modal-lg { width: min(96vw, 900px); }
.modal-xl { width: min(97vw, 1120px); }

.modal-header {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: var(--t-md);
  font-weight: var(--fw-semi);
  flex: 1;
  min-width: 0;
}

/* Only the body scrolls, so header and footer buttons stay reachable */
.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-5);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* ══════════ TOASTS ══════════ */

.toast-container {
  position: fixed;
  top: var(--s-5);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg-overlay);
  box-shadow: var(--sh-lg);
  font-size: var(--t-sm);
  font-weight: var(--fw-med);
  animation: toast-in var(--base);
  transition: opacity var(--base), transform var(--base);
}

.toast.success { border-inline-start: 3px solid var(--ok); }
.toast.error   { border-inline-start: 3px solid var(--danger); }
.toast.info    { border-inline-start: 3px solid var(--info); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: none; }
}

/* ══════════ CODE / URL ══════════ */

.code-url {
  display: block;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  color: var(--info);
  font-family: var(--font-num);
  font-size: var(--t-xs);
  direction: ltr;
  text-align: left;
  word-break: break-all;
  line-height: 1.6;
}

.code-url.truncate-url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal; }
