/* Fiper Terminal — Phase A · UX Excellence
 * Loaded after fiper.css/tokens.css; overrides where intentional.
 * A1 a11y, A2 trust, A3 color refinement, A4 micro-interactions,
 * A5 search palette, A6 editorial brief, A7 loading/error states.
 */

/* =====================================================
 * A1 — A11y Hardening
 * ===================================================== */

/* Keyboard focus indicator (brand red) */
*:focus-visible {
  outline: 2px solid var(--text-fiper, #e63946);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Suppress focus outline for mouse interactions */
*:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Smooth scroll for in-page anchors (overridden by reduced-motion above) */
html { scroll-behavior: smooth; }

/* Cursor pointer on clickable affordances */
a, button, [role="button"], [tabindex="0"] {
  cursor: pointer;
}

/* Skip-to-content link, visible only on keyboard focus */
.skip-to-content {
  position: absolute;
  top: -48px;
  left: 12px;
  background: var(--text-fiper, #e63946);
  color: #ffffff;
  padding: 10px 16px;
  z-index: 100000;
  text-decoration: none;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 4px;
  transition: top 0.2s ease;
}
.skip-to-content:focus,
.skip-to-content:focus-visible {
  top: 12px;
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}
[dir="rtl"] .skip-to-content { left: auto; right: 12px; }

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

/* Contrast tuning — bumping #6b7280 territory slightly lighter for body usage.
 * Existing var(--text-tertiary) = #6b7280 ≈ 3.13:1 on #0a0a0a (fails AA body).
 * Bump it to #8a93a1 for ≥4.5:1 while keeping the same role. */
:root {
  --text-tertiary: #8a93a1;
  --text-muted:    #a0a8b3;
}

/* =====================================================
 * A2 — Trust Signals
 * ===================================================== */

.disclaimer-bar {
  background: rgba(120, 53, 15, 0.18);
  border-bottom: 1px solid rgba(180, 83, 9, 0.32);
  padding: 6px 16px;
  font-size: 12px;
}
.disclaimer-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.disclaimer-bar-msg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #fcd9a1;
  font-family: var(--font-sans, system-ui);
}
.disclaimer-bar-msg svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
}
.disclaimer-bar a {
  color: #fde6c0;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.disclaimer-bar a:hover { color: #ffffff; }

/* Methodology page */
.method-wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 0 64px;
}
.method-hero {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 22px;
  margin-bottom: 28px;
}
.method-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-fiper);
  margin-bottom: 10px;
}
.method-title {
  font-family: var(--font-serif);
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.18;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  margin: 0 0 10px;
  font-weight: 500;
}
.method-lede {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-secondary);
  max-width: 70ch;
}
.method-section {
  margin: 26px 0;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--border-subtle);
}
.method-section:last-child { border-bottom: none; }
.method-section h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
.method-section p,
.method-section li {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}
.method-section p { margin: 0 0 10px; }
.method-section ul {
  margin: 0; padding: 0;
  list-style: none;
}
.method-section li {
  position: relative;
  padding-left: 18px;
  margin-bottom: 6px;
}
[dir="rtl"] .method-section li { padding-left: 0; padding-right: 18px; }
.method-section li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--text-fiper);
  font-weight: 700;
}
[dir="rtl"] .method-section li::before { left: auto; right: 4px; }
.method-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 18px;
}

/* Inline last-updated badge near price */
.updated-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: 12px;
  white-space: nowrap;
}
[dir="rtl"] .updated-badge { margin-left: 0; margin-right: 12px; }

/* Data attribution row in footer */
.footer-attribution {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 10px;
  align-items: center;
  justify-content: center;
}
.footer-attribution a {
  color: var(--text-tertiary);
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,0.18);
}
.footer-attribution a:hover { color: var(--text-primary); border-bottom-color: currentColor; }
.footer-attribution .footer-sep { opacity: 0.45; }

/* Bias chip tooltip cue — explicit title used; just upgrade affordance */
.et-bias-chip[title] { cursor: help; }

/* =====================================================
 * A3 — Color Refinement Tokens
 * (extends tokens.css with semantic names already used by Phase A)
 * ===================================================== */
:root {
  /* Already in tokens.css: --text-primary: #f5f5f5 */
  --surface-base:     #0a0a0a;
  --surface-elevated: #141414;
  --surface-raised:   #1a1a1a;
  --accent-brand:     #e63946;
  --accent-bullish:   #1d9e75;
  --accent-bearish:   #e24b4a;
  --accent-neutral:   #999999;
  --border-visible:   rgba(255, 255, 255, 0.12);
}

/* =====================================================
 * A4 — Micro-interactions
 * ===================================================== */

/* Sidebar instrument hover lift (LTR) */
.sb-item {
  transition: background 180ms ease, transform 160ms ease, color 160ms ease;
}
.sb-item:hover {
  transform: translateX(2px);
}
[dir="rtl"] .sb-item:hover {
  transform: translateX(-2px);
}

/* Active state — gentle press for any button */
.cta-btn,
.btn,
.locale-toggle-btn,
.drawer-cta {
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease, transform 100ms ease;
}
.cta-btn:active,
.btn:active,
.locale-toggle-btn:active,
.drawer-cta:active {
  transform: scale(0.98);
}

/* Price flash demo — pairs with priceWatch() Alpine.js component.
 * Phase C will wire this to WebSocket; today it's keyboard/test-event driven. */
.price-flash {
  transition: background-color 600ms ease;
  border-radius: 3px;
}
.price-flash[data-flash="up"] {
  animation: pa-flash-up 600ms ease;
}
.price-flash[data-flash="down"] {
  animation: pa-flash-down 600ms ease;
}
@keyframes pa-flash-up {
  0%   { background: rgba(29, 158, 117, 0.30); }
  100% { background: transparent; }
}
@keyframes pa-flash-down {
  0%   { background: rgba(226, 75, 74, 0.30); }
  100% { background: transparent; }
}

/* =====================================================
 * A5 — Search Palette (Cmd+K)
 * ===================================================== */

/* Hotfix: harden .nav-cta so the search trigger never crowds out
 * the locale toggle. Each direct child gets flex-shrink: 0 so they
 * keep their content width; gap replaces ad-hoc margins. */
.nav-cta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-cta > * { flex-shrink: 0; }
.nav-cta .locale-toggle { margin: 0; }
[dir="rtl"] .nav-cta .locale-toggle { margin: 0; }
.search-palette-root { display: inline-flex; flex-shrink: 0; }

.sp-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 0.5px solid var(--border-mid);
  border-radius: 4px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 150ms, border-color 150ms, color 150ms;
}
.sp-trigger:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.sp-trigger svg { width: 14px; height: 14px; stroke: currentColor; }
.sp-trigger kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid var(--border-mid);
  border-radius: 3px;
  color: var(--text-tertiary);
}
.sp-trigger-label { display: inline; }
@media (max-width: 768px) {
  .sp-trigger-label, .sp-trigger kbd { display: none; }
}

.sp-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.sp-modal {
  background: var(--surface-elevated, #141414);
  border: 1px solid var(--border-visible, rgba(255,255,255,0.12));
  border-radius: 8px;
  width: min(92vw, 620px);
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.sp-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.sp-input-row svg.sp-search-icon {
  width: 16px; height: 16px;
  stroke: var(--text-tertiary);
  flex-shrink: 0;
}
.sp-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 4px 0;
}
.sp-esc-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid var(--border-mid);
  border-radius: 3px;
  color: var(--text-tertiary);
}
.sp-results {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}
.sp-group-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  padding: 8px 14px 4px;
}
.sp-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  border-left: 2px solid transparent;
}
[dir="rtl"] .sp-result { border-left: none; border-right: 2px solid transparent; }
.sp-result:hover,
.sp-result.is-selected {
  background: rgba(230, 57, 70, 0.08);
  border-left-color: var(--accent-brand);
  color: var(--text-primary);
}
[dir="rtl"] .sp-result:hover,
[dir="rtl"] .sp-result.is-selected {
  border-left-color: transparent;
  border-right-color: var(--accent-brand);
}
.sp-result-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.sp-result-sym {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}
.sp-result-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-result-type {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 12px;
}
[dir="rtl"] .sp-result-type { margin-left: 0; margin-right: 12px; }
.sp-empty {
  padding: 26px 16px;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-tertiary);
}
.sp-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.sp-footer kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 4px;
  margin-right: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid var(--border-mid);
  border-radius: 3px;
}

/* =====================================================
 * A6 — Editorial Brief Styling
 * (extends existing .aw-brief in fiper.css)
 * ===================================================== */
.aw-brief {
  background: var(--bg-card);
  border-left: 3px solid var(--accent-brand);
}
[dir="rtl"] .aw-brief {
  border-left: none;
  border-right: 3px solid var(--accent-brand);
}
.aw-brief-title {
  font-family: var(--font-serif);
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.18;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  max-width: 32ch;
}
.aw-brief-body p {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  max-width: 70ch;
  margin-bottom: 0.9em;
}
.aw-brief-body p:last-child { margin-bottom: 0; }
.aw-brief-byline {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-top: 16px;
  text-transform: uppercase;
}

/* Pullquote reserved for future auto-extraction (Iter 16) */
.brief-pullquote {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(22px, 2.6vw, 32px);
  line-height: 1.25;
  border-left: 3px solid var(--accent-brand);
  padding: 4px 0 4px 22px;
  margin: 22px 0;
  color: var(--text-primary);
}
[dir="rtl"] .brief-pullquote {
  border-left: none;
  border-right: 3px solid var(--accent-brand);
  padding-left: 0;
  padding-right: 22px;
}

/* =====================================================
 * A7 — Loading & Error States
 * ===================================================== */
.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skeleton-line {
  height: 10px;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.10) 50%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 200% 100%;
  border-radius: 3px;
  animation: pa-skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes pa-skel-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.stale-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(120, 53, 15, 0.20);
  border: 1px solid rgba(180, 83, 9, 0.36);
  color: #fcd9a1;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  margin: 12px 0;
}
.stale-warning svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
}

.brief-fallback {
  padding: 22px;
  border: 1px dashed var(--border-mid);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: var(--bg-card);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.6;
}
.brief-fallback .brief-fallback-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Branded error pages */
.err-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  padding: 24px;
}
.err-card {
  max-width: 520px;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
}
.err-code {
  font-family: var(--font-serif);
  font-size: 84px;
  line-height: 1;
  font-weight: 600;
  color: var(--accent-brand);
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}
.err-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 10px;
}
.err-body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 22px;
}
.err-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.err-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent-brand);
  color: #ffffff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.err-btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-mid);
}
.err-btn:hover { filter: brightness(1.05); }

/* =====================================================
 * Iter 21 H3 — hide drawer/hamburger and the desktop sidebar
 * on small screens. The bottom-nav component is the only
 * primary navigation on mobile; the sidebar's 41-instrument
 * list lives at /markets and is reachable via Cmd+K search.
 * Single breakpoint at 767px matches the existing mobile-bottom-nav
 * media query in responsive.css.
 * ===================================================== */
@media (max-width: 767px) {
  .mobile-hamburger,
  .mobile-drawer,
  .mobile-drawer-backdrop {
    display: none !important;
  }
  .sidebar,
  .desktop-sidebar {
    display: none !important;
  }
  .shell {
    grid-template-columns: 1fr !important;
  }
  .content {
    grid-column: 1 / -1;
    padding-left: 16px;
    padding-right: 16px;
  }
  /* Trim the top nav to logo + search + locale + CTA only */
  .top-nav .nav-status { display: none; }
}
