/* ==========================================================================
   Base reset + typography
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4, p { margin: 0; }

h1, h2, h3, .font-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

::selection { background: var(--signal-tint); color: var(--signal-ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }

/* -- Layout primitives -- */
.container { max-width: 1180px; margin: 0 auto; padding: 0 24px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* -- Buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-md); padding: 11px 20px;
  font-weight: 600; font-size: 14.5px; line-height: 1; white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--signal); color: var(--signal-text, #fff); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { box-shadow: var(--shadow-md); }
.btn-ring { background: var(--ring); color: #fff; box-shadow: var(--shadow-sm); }
.btn-ring:hover:not(:disabled) { box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--ink); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-icon { padding: 9px; border-radius: var(--radius-pill); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* -- Forms -- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, .textarea, select.input {
  border: 1.5px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14.5px; color: var(--ink);
  transition: border-color 0.12s ease, box-shadow 0.12s ease; width: 100%;
}
.input:focus, .textarea:focus, select.input:focus {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-tint);
}
.textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 12.5px; color: var(--faint); }
.field-error { font-size: 12.5px; color: var(--danger); }

/* -- Avatars & presence dot -- */
.avatar { border-radius: var(--radius-pill); object-fit: cover; background: var(--surface-alt); flex-shrink: 0; }
.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; border: 2px solid var(--surface); background: var(--offline);
}
.presence-dot.online { background: var(--signal); }
.presence-dot.away { background: var(--away); }
.presence-dot.hidden { display: none; }

/* -- Cards / surfaces -- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 600; }
.pill-signal { background: var(--signal-tint); color: var(--signal-ink); }
.pill-ring { background: var(--ring-tint); color: var(--ring-ink); }
.pill-muted { background: var(--surface-alt); color: var(--muted); }

.text-link { color: var(--signal-ink); font-weight: 600; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

/* -- Cookie notice banner -- */
.cookie-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9500;
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow-lg);
  padding: 16px 20px; display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap;
}
.cookie-banner-text { max-width: 640px; font-size: 13.5px; color: var(--muted); }
.cookie-banner-text strong { color: var(--ink); }
.cookie-banner-text a { color: var(--signal-ink); font-weight: 600; }
.cookie-banner-actions { display: flex; gap: 10px; flex-shrink: 0; }
@media (max-width: 640px) { .cookie-banner { flex-direction: column; text-align: center; } }

/* -- Toasts -- */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 9000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 14px; box-shadow: var(--shadow-lg); animation: toast-in 0.18s ease;
  max-width: 320px;
}
[data-theme="dark"] .toast, [data-theme="system"] .toast { background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* -- Modal -- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18, 20, 43, 0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 8000; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 88vh; max-height: 88dvh; overflow-y: auto; padding: 28px;
  -webkit-overflow-scrolling: touch;
}
.modal-title { font-size: 19px; margin-bottom: 4px; }
.modal-sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* -- Empty states -- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 60px 24px; color: var(--muted); gap: 8px; }
.empty-state svg { opacity: 0.5; margin-bottom: 8px; }

/* -- Loading -- */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-top-color: transparent; animation: spin 0.7s linear infinite; opacity: 0.7; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-alt) 25%, var(--surface-hover) 37%, var(--surface-alt) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (max-width: 720px) {
  .container { padding: 0 16px; }
  .toast {
    left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    transform: none; text-align: center; justify-content: center;
  }
}

@media (max-width: 540px) {
  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: calc(90dvh - 20px);
    padding: 20px 16px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-actions .btn {
    width: 100%;
  }
  .btn {
    min-height: 42px;
  }
  input.input, select.input, textarea.input {
    min-height: 42px;
    font-size: 15px; /* Prevents iOS auto-zoom on input focus */
  }
}

/* -- Logos & Branding -- */
.brand-logo {
  height: 38px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}
.brand-logo-sm {
  height: 28px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  display: block;
}
.rail-logo-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-sm);
}
