/* ═══════════════════════════════════════════
   HQ Base Styles
   Reset, fonts, body defaults, scrollbar,
   selection, grain overlay, animations, utilities.
   Depends on tokens.css.
   ═══════════════════════════════════════════ */

/* ── Google Fonts ──────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;900&family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

/* ── Touch / tap behavior ──────────────────── */
/* Suppress the default blue/grey tap-highlight flash on all interactive
   elements. We provide our own :active styles per component. */
button,
a,
input,
textarea,
select,
[role="button"],
[role="tab"],
.agent-item,
.team-card,
.task-card,
.project-card,
.server-card,
.tab-nav__tab,
.filter-btn,
.tasks-filter-btn,
.roadmap-project-btn {
  -webkit-tap-highlight-color: transparent;
}

/* ── Body defaults ─────────────────────────── */
html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Custom scrollbar ──────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-muted);
}

/* ── Selection ─────────────────────────────── */
::selection {
  background: var(--color-amber);
  color: var(--color-bg);
}

/* ── Placeholder ───────────────────────────── */
::placeholder {
  color: var(--color-muted);
}

/* ── Grain texture overlay ─────────────────── */
/* SVG noise at low opacity creates the warm, industrial film-grain feel */
#grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* ── Animations ────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 4px currentColor; }
  50%       { box-shadow: 0 0 10px currentColor; }
}

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

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

@keyframes slide-in {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

/* ── Utility classes ───────────────────────── */
.mono    { font-family: var(--font-mono); }
.display { font-family: var(--font-display); }
.dim     { color: var(--color-dim); }
.muted   { color: var(--color-muted); }
.text    { color: var(--color-text); }
.amber   { color: var(--color-amber); }
.green   { color: var(--color-green); }
.red     { color: var(--color-red); }
.orange  { color: var(--color-orange); }

.uppercase    { text-transform: uppercase; }
.truncate     {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1        { gap: var(--space-1); }
.gap-2        { gap: var(--space-2); }
.gap-3        { gap: var(--space-3); }
.flex-1       { flex: 1; }

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

/* ═══════════════════════════════════════════
   Phone-size defaults (≤480px)
   - Bump input/textarea base size to 16px so iOS
     Safari does NOT auto-zoom when focusing a field.
   - Bump body min size to 14px for readability.
   - Contain overscroll to prevent rubber-band of parent
     scrollers (chat messages, feed list, etc.).
   ═══════════════════════════════════════════ */
@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  /* iOS auto-zooms focused inputs when their font-size is < 16px.
     Apply the minimum here so every future form control inherits it. */
  input,
  textarea,
  select {
    font-size: 16px;
  }
}

/* Any scrollable view inside the app shell should contain its
   overscroll so the whole page doesn't bounce on iOS. Each view
   sets overflow:auto; this centralizes the behavior. */
.dashboard-view,
.feed-view,
.tasks-view,
.team-view,
.servers-view,
.roadmap-view,
.chat-messages,
.chat-directory,
.chief-messages {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════
   Global :focus-visible ring (audit Tier 1 #5, a11y WCAG 2.4.7)
   Many components set `outline: none` on :focus to avoid the default
   browser dotted ring (~25 sites across css/). The replacement was
   inconsistent — some components added border-color or box-shadow,
   others left focus invisible. Keyboard users couldn't tell which
   element was focused. This rule provides a single, brand-consistent
   amber focus ring on ANY focusable element navigated to by keyboard
   (Tab/Shift+Tab/arrow). It uses :focus-visible (not :focus) so mouse
   clicks don't paint the ring — preserving the design intent of
   suppressing :focus on click-driven interactions.

   Per-component overrides that set their own :focus-visible (e.g.
   .task-drawer__close, .task-drawer__doc-expand-summary) win via
   selector specificity — this is the universal fallback.
   ═══════════════════════════════════════════ */
:focus-visible {
  outline: 2px solid var(--color-amber);
  outline-offset: 2px;
  /* Slight glow so it reads on dark + light surfaces both */
  box-shadow: 0 0 0 1px var(--color-bg);
}

/* Suppress the visible ring on :focus when not :focus-visible
   (mouse / touch clicks). Browsers that don't support :focus-visible
   (very old) keep their default :focus ring — a degraded but
   acceptable fallback. */
:focus:not(:focus-visible) {
  outline: none;
}

/* ═══════════════════════════════════════════
   Mobile horizontal-overflow safety net (≤768px)
   - Each top-level view gets `overflow-x: hidden` so a child with an
     unbounded width can never push the whole viewport sideways. Vertical
     scroll continues to work via the existing per-view `overflow: auto`.
   - Long unbroken strings (URLs, file paths, code spans) inside content
     surfaces wrap instead of forcing horizontal scroll. `anywhere` is
     used over `break-word` because it also breaks inside long tokens
     (URLs without spaces, /path/to/file/like/this), which `break-word`
     leaves alone.
   - Components that intentionally use horizontal scroll (kanban scroll,
     log streams, code blocks, tab nav, server-top__table-wrap, the
     org-chart, etc.) opt out via `overflow-x: auto` set on their own
     wrapper — they remain unaffected because hidden on the parent only
     clips content that wasn't already in its own scrollable container.
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  .dashboard-view,
  .feed-view,
  .tasks-view,
  .team-view,
  .servers-view,
  .roadmap-view,
  .floor-view,
  .settings-view {
    overflow-x: hidden;
  }

  /* Word-wrap for content surfaces. Restricted to 768px so desktop can
     keep `nowrap+ellipsis` truncation in tight grid rows where wrapping
     would visually break the layout. */
  .feed-event__msg,
  .chief-message,
  .activity-item__msg,
  .profile-markdown p,
  .profile-markdown li,
  .activity-row__content {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
