/* =============================================================
   QuakBox — shared components
   Phase 2 of the interface work.

   None of these exist in the application today: every one of the
   45 screens defines its own button, its own card, its own dialog.
   This file is what stops that. It depends only on tokens.css.
   ============================================================= */

/* ---------- 1. Button ---------------------------------------- */

.q-btn {
  --_bg: var(--q-accent);
  --_fg: var(--q-accent-ink);
  --_bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--q-2);
  height: 38px;
  padding: 0 var(--q-4);
  border: 1px solid var(--_bd);
  border-radius: var(--q-r-full);
  background: var(--_bg);
  color: var(--_fg);
  font: 600 var(--q-t-body)/1 var(--q-font);
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--q-fast) var(--q-ease),
              color var(--q-fast) var(--q-ease),
              border-color var(--q-fast) var(--q-ease),
              transform var(--q-fast) var(--q-ease);
}
.q-btn:hover   { --_bg: var(--q-accent-hover); }
.q-btn:active  { transform: translateY(1px); }
.q-btn:disabled,
.q-btn[aria-disabled="true"] {
  --_bg: var(--q-surface-sunk);
  --_fg: var(--q-ink-4);
  cursor: not-allowed;
  transform: none;
}

.q-btn--quiet {
  --_bg: transparent;
  --_fg: var(--q-ink-2);
  --_bd: var(--q-line-strong);
}
.q-btn--quiet:hover {
  --_bg: var(--q-surface-sunk);
  --_fg: var(--q-ink);
  --_bd: var(--q-line-strong);
}

.q-btn--ghost {
  --_bg: transparent;
  --_fg: var(--q-ink-2);
  --_bd: transparent;
  padding: 0 var(--q-3);
}
.q-btn--ghost:hover { --_bg: var(--q-surface-sunk); --_fg: var(--q-ink); }

/* Leaving is a quiet action, not a destructive one. The old
   screens used red for "Join" and green for "Joined"; both were
   ordinary actions wearing alarm colours. */
.q-btn--on {
  --_bg: var(--q-accent-wash);
  --_fg: var(--q-accent);
  --_bd: var(--q-accent-line);
}
.q-btn--on:hover { --_bg: #DCE9EB; }

.q-btn--sm { height: 30px; padding: 0 var(--q-3); font-size: var(--q-t-small); }
.q-btn--lg { height: 44px; padding: 0 var(--q-5); }
.q-btn--block { width: 100%; }

/* ---------- 2. Icon button ----------------------------------- */

.q-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--q-r-full);
  background: transparent;
  color: var(--q-ink-3);
  cursor: pointer;
  transition: background var(--q-fast) var(--q-ease),
              color var(--q-fast) var(--q-ease);
}
.q-icon-btn:hover { background: var(--q-surface-sunk); color: var(--q-ink); }
.q-icon-btn svg   { width: 20px; height: 20px; display: block; }
.q-icon-btn--onslate         { color: var(--q-slate-ink); }
.q-icon-btn--onslate:hover   { background: rgba(255,255,255,.10); color: #fff; }
.q-icon-btn[aria-current="page"] { color: var(--q-accent); background: var(--q-accent-wash); }

/* ---------- 3. Avatar ---------------------------------------- */

.q-avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--q-r-full);
  background: var(--_av, var(--q-accent));
  color: #fff;
  font: 600 var(--q-t-body)/1 var(--q-font);
  letter-spacing: -0.01em;
  user-select: none;
}
.q-avatar--xs { width: 22px; height: 22px; font-size: 10px; }
.q-avatar--sm { width: 30px; height: 30px; font-size: var(--q-t-small); }
.q-avatar--lg { width: 56px; height: 56px; font-size: var(--q-t-title); }
.q-avatar--xl { width: 104px; height: 104px; font-size: 2.25rem; }

/* presence reads as a physical dot cut out of the avatar edge */
.q-avatar[data-online="1"]::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 30%;
  height: 30%;
  min-width: 8px;
  min-height: 8px;
  border-radius: var(--q-r-full);
  background: var(--q-online);
  box-shadow: 0 0 0 2.5px var(--q-ground);
}

.q-avatar-stack { display: inline-flex; align-items: center; }
.q-avatar-stack .q-avatar { box-shadow: 0 0 0 2.5px var(--q-ground); }
.q-avatar-stack .q-avatar + .q-avatar { margin-left: -10px; }
.q-avatar-stack__more {
  margin-left: -10px;
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: var(--q-r-full);
  background: var(--q-surface-sunk);
  box-shadow: 0 0 0 2.5px var(--q-ground);
  color: var(--q-ink-3);
  font: 600 11px/1 var(--q-font);
}

/* ---------- 4. Badge / pill ---------------------------------- */

.q-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--q-r-full);
  background: var(--q-surface-sunk);
  color: var(--q-ink-2);
  font: 600 var(--q-t-micro)/1.4 var(--q-font);
  letter-spacing: var(--q-track-label);
  text-transform: uppercase;
  white-space: nowrap;
}
.q-badge--live { background: var(--q-live-wash); color: var(--q-live); }
.q-badge--live::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: var(--q-r-full);
  background: currentColor;
  animation: q-pulse 2s var(--q-ease) infinite;
}
@keyframes q-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.8); }
}
.q-badge--accent { background: var(--q-accent-wash); color: var(--q-accent); }

/* meta text, not a badge: no chip around a plain number */
.q-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--q-ink-3);
  font-size: var(--q-t-small);
}
.q-meta svg { width: 15px; height: 15px; opacity: .8; }
.q-dot { color: var(--q-ink-4); }

/* ---------- 5. Field ----------------------------------------- */

.q-field {
  display: flex;
  align-items: center;
  gap: var(--q-2);
  height: 40px;
  padding: 0 var(--q-4);
  border: 1px solid var(--q-line);
  border-radius: var(--q-r-full);
  background: var(--q-surface);
  transition: border-color var(--q-fast) var(--q-ease),
              box-shadow var(--q-fast) var(--q-ease);
}
.q-field:focus-within {
  border-color: var(--q-accent-line);
  box-shadow: 0 0 0 3px var(--q-accent-wash);
}
.q-field svg { width: 17px; height: 17px; color: var(--q-ink-3); flex: none; }
.q-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--q-ink);
  font: 400 var(--q-t-body)/1 var(--q-font);
}
.q-field input::placeholder { color: var(--q-ink-3); }

/* ---------- 6. Tabs ------------------------------------------ */

.q-tabs {
  display: flex;
  gap: var(--q-5);
  border-bottom: 1px solid var(--q-line);
  overflow-x: auto;
  scrollbar-width: none;
}
.q-tabs::-webkit-scrollbar { display: none; }
.q-tab {
  position: relative;
  padding: var(--q-3) 0 var(--q-4);
  border: 0;
  background: none;
  color: var(--q-ink-3);
  font: 600 var(--q-t-body)/1 var(--q-font);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--q-fast) var(--q-ease);
}
.q-tab:hover { color: var(--q-ink); }
.q-tab[aria-selected="true"] { color: var(--q-ink); }
.q-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--q-accent);
}

/* ---------- 7. Sheet ----------------------------------------- */

.q-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(18, 23, 30, .38);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: start center;
  padding: 6vh var(--q-4) var(--q-4);
  opacity: 0;
  animation: q-fade var(--q-mid) var(--q-ease) forwards;
}
.q-sheet {
  width: min(680px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--q-r-lg);
  background: var(--q-surface);
  box-shadow: var(--q-e-3);
  transform: translateY(10px);
  animation: q-rise var(--q-mid) var(--q-ease) forwards;
}
.q-sheet__head {
  display: flex;
  align-items: center;
  gap: var(--q-3);
  padding: var(--q-4) var(--q-5);
  border-bottom: 1px solid var(--q-line);
}
.q-sheet__title {
  flex: 1;
  font: 600 var(--q-t-title)/1.2 var(--q-font);
  letter-spacing: var(--q-track-title);
  color: var(--q-ink);
}
.q-sheet__body { padding: var(--q-4) var(--q-5) var(--q-5); overflow-y: auto; }

@keyframes q-fade { to { opacity: 1; } }
@keyframes q-rise { to { transform: translateY(0); } }

/* ---------- 8. Empty state ----------------------------------- */

.q-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--q-3);
  padding: var(--q-8) var(--q-5);
  text-align: center;
}
.q-empty svg { width: 34px; height: 34px; color: var(--q-ink-3); }
.q-empty__title {
  font: 600 var(--q-t-title)/1.25 var(--q-font);
  letter-spacing: var(--q-track-title);
  color: var(--q-ink);
}
.q-empty__text {
  max-width: 42ch;
  color: var(--q-ink-3);
  font-size: var(--q-t-body);
  line-height: var(--q-lh-body);
}

/* ---------- 9. Stat ------------------------------------------ */

.q-stat__value {
  font: 600 var(--q-t-display)/1 var(--q-font);
  letter-spacing: var(--q-track-display);
  color: var(--q-ink);
  font-variant-numeric: tabular-nums;
}
.q-stat__label {
  margin-top: 3px;
  color: var(--q-ink-3);
  font-size: var(--q-t-small);
}

/* ---------- 10. Row ------------------------------------------ */

.q-row {
  display: flex;
  align-items: center;
  gap: var(--q-3);
  width: 100%;
  padding: var(--q-2) var(--q-2);
  border: 0;
  border-radius: var(--q-r-md);
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--q-fast) var(--q-ease);
}
.q-row:hover { background: var(--q-surface-sunk); }
.q-row__body { flex: 1; min-width: 0; }
.q-row__title {
  font: 600 var(--q-t-body)/1.3 var(--q-font);
  color: var(--q-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.q-row__sub {
  margin-top: 1px;
  font-size: var(--q-t-small);
  color: var(--q-ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 11. Flag ----------------------------------------- */

.q-flag {
  display: block;
  flex: none;
  width: 24px;
  height: 16px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(18, 23, 30, .10);
  object-fit: cover;
}
.q-flag--lg { width: 48px; height: 32px; border-radius: 3px; }
.q-flag--xl { width: 76px; height: 51px; border-radius: 4px; }

/* ---------- 12. Section head --------------------------------- */

.q-head {
  display: flex;
  align-items: baseline;
  gap: var(--q-3);
  margin-bottom: var(--q-4);
}
.q-head__title {
  font: 600 var(--q-t-title)/1.2 var(--q-font);
  letter-spacing: var(--q-track-title);
  color: var(--q-ink);
}
.q-head__aside { margin-left: auto; }

/* ---------- shared behaviour --------------------------------- */

:where(a, button, [tabindex]):focus-visible {
  outline: 2px solid var(--q-accent);
  outline-offset: 2px;
  border-radius: var(--q-r-sm);
}
