/**
 * hud.css — Clean cockpit layout utilities.
 * No neon. No scan lines. No rotating rings. No Jarvis.
 * Just functional tokens for borders, depth, glass, tabs, and focus.
 */

/* ─── Layout Tokens ─── */
:root {
  --hud-surface: rgba(255, 255, 255, 0.03);
  --hud-border: rgba(0, 0, 0, 0.08);
  --hud-text: rgba(0, 0, 0, 0.85);
  --hud-text-dim: rgba(0, 0, 0, 0.55);
  --hud-text-muted: rgba(0, 0, 0, 0.32);
  --hud-dim: rgba(0, 0, 0, 0.06);
}

.dark {
  --hud-surface: rgba(255, 248, 230, 0.03);
  --hud-border: rgba(255, 248, 230, 0.07);
  --hud-text: #d4d0c8;
  --hud-text-dim: #a8a49a;
  --hud-text-muted: rgba(212, 208, 200, 0.28);
  --hud-dim: rgba(255, 248, 230, 0.05);
}

/* ─── Borders ─── */
.hud-border   { border: 1px solid var(--hud-border); }
.hud-border-t { border-top: 1px solid var(--hud-border); }
.hud-border-b { border-bottom: 1px solid var(--hud-border); }
.hud-border-r { border-right: 1px solid var(--hud-border); }
.hud-border-l { border-left: 1px solid var(--hud-border); }

/* ─── Depth Shadows ─── */
.hud-depth-top    { box-shadow: 0 1px 2px rgba(0,0,0,0.04); z-index: 10; position: relative; }
.hud-depth-right  { box-shadow: 1px 0 2px rgba(0,0,0,0.03); z-index: 10; position: relative; }
.hud-depth-bottom { box-shadow: 0 -1px 2px rgba(0,0,0,0.04); z-index: 10; position: relative; }
.hud-depth-left   { box-shadow: -1px 0 2px rgba(0,0,0,0.03); z-index: 10; position: relative; }

.dark .hud-depth-top    { box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.dark .hud-depth-right  { box-shadow: 1px 0 3px rgba(0,0,0,0.2); }
.dark .hud-depth-bottom { box-shadow: 0 -1px 3px rgba(0,0,0,0.25); }
.dark .hud-depth-left   { box-shadow: -1px 0 3px rgba(0,0,0,0.2); }

/* ─── Glass Surface ─── */
.hud-glass {
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(12px);
}
.dark .hud-glass {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
}

/* Mobile: strip glass blur for GPU performance */
@media (max-width: 1279px) {
  .hud-glass {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(26, 26, 46, 0.95);
  }
  .dark .hud-glass {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(10, 10, 20, 0.95);
  }
}

/* ─── Surface ─── */
.hud-surface { background: var(--hud-surface); }

/* ─── Tab ─── */
.hud-tab {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  height: 32px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--hud-text-dim);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
  border-top: none;
  border-left: none;
  border-right: none;
  background: transparent;
  white-space: nowrap;
}
.hud-tab:hover { color: var(--hud-text); }
.hud-tab[data-active="true"] {
  color: var(--hud-text);
  border-bottom-color: var(--accent-primary, #d97757);
  font-weight: 600;
}

/* ─── Tab Strip Fade Mask ─── */
.hud-tab-strip {
  mask-image: linear-gradient(to right, black calc(100% - 32px), transparent);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 32px), transparent);
}

/* ─── Mobile Tab ─── */
.hud-mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  padding: 4px 0;
  border-radius: 8px;
  color: var(--hud-text-dim);
  transition: color 0.15s, background 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.hud-mobile-tab:hover { background: var(--hud-dim); }
.hud-mobile-tab[data-active="true"] { color: var(--hud-text); background: var(--hud-dim); }

/* ─── Mode Button ─── */
.hud-mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--hud-text-dim);
  transition: color 0.15s, background 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  position: relative;
}
.hud-mode-btn:hover { color: var(--hud-text); background: var(--hud-dim); }
.hud-mode-btn[data-active="true"] {
  color: var(--hud-text);
  background: var(--hud-dim);
  box-shadow: inset 2px 0 0 currentColor;
}

/* ─── Badge ─── */
.hud-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 13px;
  height: 13px;
  padding: 0 3px;
  border-radius: 7px;
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 13px;
  text-align: center;
  color: #fff;
  pointer-events: none;
}
.dark .hud-badge { color: rgba(0,0,0,0.85); }

.hud-mobile-badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 18px);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
}

/* ─── Label ─── */
.hud-label {
  font-size: 0.6875rem;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hud-text-dim);
}
.hud-label-active { color: var(--hud-text); }

/* ─── Mono ─── */
.hud-mono { font-family: ui-monospace, "SF Mono", monospace; }

/* ─── Resize Handle ─── */
.hud-resize-handle:hover { background: var(--accent-primary, #d97757); }

/* ─── Focus Rings ─── */
.hud-mode-btn:focus-visible,
.hud-tab:focus-visible,
.hud-mobile-tab:focus-visible {
  outline: 2px solid var(--accent-primary, #d97757);
  outline-offset: 2px;
}
.hud-resize-handle:focus-visible {
  outline: 2px solid var(--accent-primary, #d97757);
  outline-offset: 2px;
}

/* ─── Focal Area Containment ─── */
.hud-focal-area {
  contain: layout style paint;
  content-visibility: auto;
  contain-intrinsic-block-size: auto 800px;
}

/* ─── Scroll Fade ─── */
.scroll-fade {
  mask-image: linear-gradient(to bottom, transparent 0%, black 8%, black 92%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 8%, black 92%, transparent 100%);
}

/* ─── Pause animations when tab hidden ─── */
.hud-tab-hidden .hud-dot-pulse { animation-play-state: paused; }

/* ─── View Transitions ─── */
::view-transition-old(root) { animation-duration: 0.12s; animation-timing-function: ease-out; }
::view-transition-new(root) { animation-duration: 0.12s; animation-timing-function: ease-out; }

/* ─── Containment for lists ─── */
.document-card--hybrid,
.feed-card-grid > *,
[role="listbox"] > *,
[role="list"] > * {
  contain: layout style paint;
}

/* ─── 3-Dot Typing Indicator (iMessage/WhatsApp pattern) ─── */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.typing-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ─── Skeleton Stagger Loading ─── */
.skeleton-stagger > * {
  animation: skeleton-fade-in 0.3s ease-out both;
}
.skeleton-stagger > *:nth-child(1) { animation-delay: 0ms; }
.skeleton-stagger > *:nth-child(2) { animation-delay: 100ms; }
.skeleton-stagger > *:nth-child(3) { animation-delay: 200ms; }
.skeleton-stagger > *:nth-child(4) { animation-delay: 300ms; }
.skeleton-stagger > *:nth-child(5) { animation-delay: 400ms; }
.skeleton-stagger > *:nth-child(6) { animation-delay: 500ms; }

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

/* ─── Reduced Motion ─── */
.reduce-motion .hud-dot-pulse { animation: none; }
.reduce-motion .typing-dots .dot { animation: none; opacity: 0.5; }
.reduce-motion .skeleton-stagger > * { animation: none; opacity: 1; }

/* ─── Mobile Bottom Sheet ─── */
/* 3-state agent panel: peek (80px), half (60vh), full (95vh) */

.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.4);
  transition: opacity 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}
.bottom-sheet-backdrop.backdrop-visible { opacity: 1; pointer-events: auto; }
.bottom-sheet-backdrop.backdrop-hidden { opacity: 0; pointer-events: none; }

.bottom-sheet-container {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 95vh;
  z-index: 50;
  border-radius: 16px 16px 0 0;
  background: var(--hud-surface, rgba(21, 20, 19, 0.97));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: none;
  backdrop-filter: blur(24px);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Disable transition during active drag for immediate feedback */
.bottom-sheet-container.dragging {
  transition: none;
}

/* State positions — translateY from top of 95vh container */
.bottom-sheet-container.sheet-closed {
  transform: translateY(100%);
  pointer-events: none;
}
.bottom-sheet-container.sheet-peek {
  /* Show only 80px from the bottom */
  transform: translateY(calc(95vh - 80px));
}
.bottom-sheet-container.sheet-half {
  /* Show 60vh */
  transform: translateY(calc(95vh - 60vh));
}
.bottom-sheet-container.sheet-full {
  transform: translateY(0);
}

/* Handle / drag indicator */
.bottom-sheet-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 8px;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* P0 touch target */
}
.bottom-sheet-handle:active { cursor: grabbing; }

.bottom-sheet-handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.15s;
}
.bottom-sheet-handle:hover .bottom-sheet-handle-bar,
.bottom-sheet-handle:active .bottom-sheet-handle-bar {
  background: rgba(255, 255, 255, 0.4);
}

/* Content area below handle */
.bottom-sheet-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-sheet-container {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bottom-sheet-container { transition-duration: 0.01ms; }
  .bottom-sheet-backdrop { transition-duration: 0.01ms; }
}

/* ─── FastAgent Panel Glass Override ─── */
/* Converts the FastAgent panel's internal tokens to match the cockpit glass DNA.
   Applied via the panel's parent container in CockpitLayout. */
.fast-agent-glass {
  --bg-surface: rgba(255, 255, 255, 0.02);
  --bg-surface-secondary: rgba(255, 255, 255, 0.04);
  --border-edge: rgba(255, 255, 255, 0.06);
}
.fast-agent-glass .bg-surface { background: rgba(255, 255, 255, 0.02) !important; }
.fast-agent-glass .bg-surface-secondary { background: rgba(255, 255, 255, 0.04) !important; }
.fast-agent-glass .bg-surface-secondary\/50 { background: rgba(255, 255, 255, 0.03) !important; }
.fast-agent-glass .bg-surface-secondary\/30 { background: rgba(255, 255, 255, 0.02) !important; }
.fast-agent-glass .bg-surface-hover { background: rgba(255, 255, 255, 0.06) !important; }
.fast-agent-glass .border-edge { border-color: rgba(255, 255, 255, 0.06) !important; }
.fast-agent-glass .bg-background { background: rgba(255, 255, 255, 0.01) !important; }

/* Neutralize gradient cards inside FastAgent panel */
.fast-agent-glass [class*="bg-gradient-to"] {
  background-image: none !important;
  background-color: rgba(255, 255, 255, 0.03) !important;
}
/* Kill ALL colored backgrounds inside the fast agent panel */
.fast-agent-glass [class*="bg-purple-"],
.fast-agent-glass [class*="bg-violet-"],
.fast-agent-glass [class*="bg-amber-"],
.fast-agent-glass [class*="from-indigo"],
.fast-agent-glass [class*="from-violet"],
.fast-agent-glass [class*="from-purple"],
.fast-agent-glass [class*="from-blue"],
.fast-agent-glass [class*="from-green"],
.fast-agent-glass [class*="from-emerald"],
.fast-agent-glass [class*="from-sky"],
.fast-agent-glass [class*="from-rose"],
.fast-agent-glass [class*="from-amber"],
.fast-agent-glass [class*="from-teal"],
.fast-agent-glass [class*="from-cyan"],
.fast-agent-glass [class*="from-orange"] {
  background-image: none !important;
  background-color: rgba(255, 248, 230, 0.03) !important;
}
/* Keep warm accent button */
.fast-agent-glass [class*="bg-indigo-6"],
.fast-agent-glass [class*="bg-indigo-5"] {
  background-image: none !important;
  background-color: #d97757 !important;
}

/* ─── Declutter: simplify FastAgent panel to chat-only ─── */
/* Hide colorful gradient cards that survived JS changes */
.fast-agent-glass [class*="grid-cols-2"] [class*="rounded-xl"][class*="shadow"] {
  background: rgba(255, 248, 230, 0.03) !important;
  border-color: rgba(255, 248, 230, 0.06) !important;
  box-shadow: none !important;
}
/* Tone down any remaining colored text in cards */
.fast-agent-glass [class*="text-violet-"],
.fast-agent-glass [class*="text-purple-"],
.fast-agent-glass [class*="text-indigo-6"],
.fast-agent-glass [class*="text-blue-"] {
  color: var(--hud-text-dim) !important;
}
/* Hide "X of 5 free messages remaining" banner */
.fast-agent-glass [class*="free messages"],
.fast-agent-glass div:has(> span:first-child > svg):has(> [class*="Sign"]) {
  display: none !important;
}
/* Hide model selector row (Default/Voice/Qwen dots) */
.fast-agent-glass [class*="Voice"]:has(~ input[type="range"]) {
  display: none !important;
}
/* Simpler: hide by data attribute if present, or by structural position */
.fast-agent-glass > div > div:last-child > div:has(input[type="range"]) {
  display: none !important;
}
/* Hide generic starter grid (Brainstorm ideas, Analyze data, etc.) from third-party chat widget */
.fast-agent-glass [class*="grid-cols-2"]:has([class*="rounded-xl"]) {
  display: none !important;
}
/* Hide the "Docs, codebase answers" subtitle bar above the generic grid */
.fast-agent-glass [class*="text-muted"]:has(+ [class*="grid-cols-2"]) {
  display: none !important;
}

/* ─── Mobile Bottom Tab Bar (R3) ─── */
/* Floating Pill Navigation: Brief, Search, Entities, Agent */

.mobile-tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 44px;
  padding: 4px 0;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
}

.mobile-tab-btn:hover {
  filter: brightness(1.2);
}

.mobile-tab-btn[data-active="true"] {
  /* Color override is handled via Tailwind text- color classes */
  transform: translateY(-2px);
}

.mobile-tab-label {
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
}

/* Active indicator background shape */
.mobile-tab-btn[data-active="true"]::before {
  content: "";
  position: absolute;
  inset: -2px 6px;
  top: 0;
  bottom: 0px;
  border-radius: 12px;
  background: currentColor;
  opacity: 0.12;
  z-index: 0;
}

/* Reduce motion: skip swipe transition animations */
@media (prefers-reduced-motion: reduce) {
  .mobile-tab-btn { transition: none; }
  .mobile-tab-btn[data-active="true"] { transform: none; }
}
