/**
 * Scout v4 Styles
 *
 * Design tokens + custom CSS for Scout v4.
 * Easy-read mode overrides are in scout-easy-read.css
 */

/* Dynamic viewport height fallback (Tailwind 3.4+) */
.h-dvh { height: 100dvh; }

/* ============================================
   DESIGN TOKENS (CSS Custom Properties)
   
   These define the color palette for Scout.
   Easy-read mode overrides these values.
   ============================================ */

:root {
  /* Background colors */
  --color-bg-primary: #0d1117;      /* Main page background */
  --color-bg-secondary: #1a1f26;    /* Cards, panels */
  --color-bg-tertiary: #2d2d2d;     /* Inputs, elevated elements */
  --color-bg-hover: rgba(254, 253, 251, 0.05);
  
  /* Text colors */
  --color-text-primary: #FEFDFB;    /* Main text */
  --color-text-secondary: rgba(254, 253, 251, 0.7);
  --color-text-tertiary: rgba(254, 253, 251, 0.5);
  --color-text-muted: rgba(254, 253, 251, 0.4);
  
  /* Brand colors */
  --color-accent: #FFCC33;          /* Gold - primary accent */
  --color-accent-hover: #9E7700;    /* Gold dark */
  --color-ocean: #1e75bb;           /* Ocean blue */
  --color-ocean-hover: #1a5a8f;
  
  /* Semantic colors */
  --color-success: #34D399;         /* Green */
  --color-success-dark: #047857;    /* Darker green for contrast */
  --color-error: #F87171;           /* Red */
  --color-error-dark: #DC2626;
  --color-warning: #FBBF24;         /* Amber */
  
  /* Border colors */
  --color-border: rgba(254, 253, 251, 0.1);
  --color-border-hover: rgba(254, 253, 251, 0.2);
  
  /* Component-specific */
  --color-input-bg: rgba(254, 253, 251, 0.05);
  --color-input-border: rgba(254, 253, 251, 0.2);
  --color-input-placeholder: rgba(254, 253, 251, 0.4);
  --color-button-secondary-border: rgba(254, 253, 251, 0.3);
  
  /* Shadows */
  --shadow-glow: 0 0 20px 4px rgba(255, 204, 51, 0.25);
  
  /* Focus ring */
  --color-focus-ring: var(--color-accent);
}

/* ============================================
   Welcome Screen Animations
   ============================================ */

/* Staggered entrance for welcome elements */
@keyframes welcome-fade-in {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes icon-entrance {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes subtle-glow {
  0%, 100% {
    box-shadow: 0 0 12px 2px rgba(255, 204, 51, 0.2);
  }
  50% {
    box-shadow: 0 0 24px 6px rgba(255, 204, 51, 0.35);
  }
}

/* Shuffle button spin animation */
@keyframes spin-once {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.animate-spin-once {
  animation: spin-once 0.3s ease-out;
}

.welcome-icon {
  animation: icon-entrance 0.6s ease-out forwards;
  box-shadow: 0 0 20px 4px rgba(255, 204, 51, 0.25);
}

.welcome-greeting {
  opacity: 0;
  animation: welcome-fade-in 0.5s ease-out 0.2s forwards;
}

.welcome-headline {
  opacity: 0;
  animation: welcome-fade-in 0.5s ease-out 0.35s forwards;
}

.welcome-subtitle {
  opacity: 0;
  animation: welcome-fade-in 0.5s ease-out 0.45s forwards;
}

.welcome-input {
  opacity: 0;
  animation: welcome-fade-in 0.5s ease-out 0.55s forwards;
}

.welcome-actions {
  opacity: 0;
  animation: welcome-fade-in 0.5s ease-out 0.65s forwards;
}

/* ============================================
   Other Animations
   ============================================ */

@keyframes cursor-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.animate-cursor {
  animation: cursor-blink 1s infinite;
}

/* ============================================
   Voice Recording Animations
   ============================================ */

@keyframes recording-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(212, 168, 75, 0.7);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(212, 168, 75, 0);
  }
}

.mic-recording {
  animation: recording-pulse 1.5s ease-in-out infinite;
}

/* Bounce animation for processing dots */
@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.animate-bounce {
  animation: bounce 0.6s ease-in-out infinite;
}

/* ============================================
   Prose Styling (Dark Theme)
   ============================================ */

.prose-invert {
  color: rgba(254, 253, 251, 0.9); /* paper/90 */
  line-height: 1.6;
}

.prose-invert p {
  margin: 0 0 0.75em;
}

.prose-invert p:last-child {
  margin-bottom: 0;
}

.prose-invert strong {
  font-weight: 600;
  color: #FEFDFB; /* paper */
}

.prose-invert em {
  font-style: italic;
}

.prose-invert ul, 
.prose-invert ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.prose-invert li {
  margin: 0.25em 0;
}

.prose-invert code {
  background: rgba(254, 253, 251, 0.1);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.9em;
  color: #FFCC33; /* gold */
}

.prose-invert pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75em 1em;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.75em 0;
  border: 1px solid rgba(254, 253, 251, 0.1);
}

.prose-invert pre code {
  background: none;
  padding: 0;
  color: #FEFDFB;
}

.prose-invert h1, 
.prose-invert h2, 
.prose-invert h3 {
  font-weight: 600;
  color: #FEFDFB; /* paper */
  margin: 1em 0 0.5em;
}

.prose-invert h1:first-child,
.prose-invert h2:first-child,
.prose-invert h3:first-child {
  margin-top: 0;
}

.prose-invert h1 { font-size: 1.25em; }
.prose-invert h2 { font-size: 1.1em; }
.prose-invert h3 { font-size: 1em; }

.prose-invert blockquote {
  border-left: 3px solid #FFCC33; /* gold */
  margin: 0.75em 0;
  padding-left: 1em;
  color: rgba(254, 253, 251, 0.7);
  font-style: italic;
}

.prose-invert a {
  color: #FFCC33; /* gold */
  text-decoration: underline;
}

.prose-invert a:hover {
  color: #FFD966; /* lighter gold */
}

/* Tables */
.prose-invert table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.9em;
}

.prose-invert th,
.prose-invert td {
  border: 1px solid rgba(254, 253, 251, 0.15);
  padding: 0.5em 0.75em;
  text-align: left;
}

.prose-invert th {
  background: rgba(254, 253, 251, 0.1);
  color: #FEFDFB;
  font-weight: 600;
}

.prose-invert tr:nth-child(even) {
  background: rgba(254, 253, 251, 0.03);
}

/* ============================================
   Scrollbar Styling (Dark Theme)
   ============================================ */

.overflow-y-auto::-webkit-scrollbar {
  width: 8px;
}

.overflow-y-auto::-webkit-scrollbar-track {
  background: transparent;
}

.overflow-y-auto::-webkit-scrollbar-thumb {
  background: rgba(254, 253, 251, 0.15);
  border-radius: 4px;
}

.overflow-y-auto::-webkit-scrollbar-thumb:hover {
  background: rgba(254, 253, 251, 0.25);
}

/* Thin scrollbar for thinking panel */
.scrollbar-thin {
  contain: content; /* Limit repaint scope for streaming text */
}

.scrollbar-thin::-webkit-scrollbar {
  width: 4px;
}

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

.scrollbar-thin::-webkit-scrollbar-thumb {
  background: rgba(255, 204, 51, 0.2);
  border-radius: 2px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 204, 51, 0.4);
}

/* ============================================
   Textarea Auto-resize
   ============================================ */

textarea {
  field-sizing: content; /* Modern browsers */
}

@supports not (field-sizing: content) {
  textarea {
    overflow-y: auto;
  }
}

/* ============================================
   Focus States - Keyboard Accessibility
   ============================================ */

/* Universal focus ring for keyboard users */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible,
[role="menuitem"]:focus-visible,
[role="switch"]:focus-visible {
  outline: 2px solid #1e75bb;
  outline-offset: 2px;
}

/* Hide focus ring for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Checkbox specific */
input[type="checkbox"] {
  accent-color: #FFCC33; /* gold */
}

input[type="checkbox"]:focus-visible {
  outline: 2px solid #FFCC33;
  outline-offset: 2px;
}

/* Radio buttons */
input[type="radio"]:focus-visible + div,
input[type="radio"]:focus-visible + label {
  outline: 2px solid #1e75bb;
  outline-offset: 2px;
}

/* Screen reader: uses Tailwind native sr-only / not-sr-only utilities */

/* ============================================
   Custom Selection Color
   ============================================ */

::selection {
  background: rgba(255, 204, 51, 0.3); /* gold/30 */
  color: #FEFDFB;
}

/* ============================================
   Smooth transitions for state changes
   ============================================ */

main {
  transition: opacity 0.15s ease-out;
}

/* ============================================
   Line Clamp Utility
   ============================================ */

/* Line clamp: uses Tailwind native line-clamp-2 utility */

/* ============================================
   Dropdown Menus
   ============================================ */

.dropdown-glass {
  background: #1e232a !important;
  background-color: #1e232a !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid rgba(254, 253, 251, 0.12);
  box-shadow: 
    0 4px 6px -1px rgba(0, 0, 0, 0.4),
    0 10px 20px -5px rgba(0, 0, 0, 0.5);
}

/* ============================================
   Feedback Buttons (Copy, Thumbs Up/Down)
   ============================================ */

.feedback-btn {
  color: var(--color-text-tertiary);
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.feedback-btn svg {
  pointer-events: none;
}

.feedback-btn:hover:not(:disabled) {
  color: var(--color-text-secondary);
  background-color: var(--color-bg-hover);
}

.feedback-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

.feedback-btn-success {
  color: var(--color-success) !important;
  opacity: 1 !important;
}

/* ============================================
   Thinking Indicator & Typing Animation
   ============================================ */

.thinking-text {
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.5;
}

/* Smooth typing dots animation */
.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--color-accent);
  border-radius: 50%;
  opacity: 0.4;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) {
  animation-delay: 0ms;
}

.typing-dot:nth-child(2) {
  animation-delay: 200ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 400ms;
}

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

/* Smooth fade for "thinking..." text */
.typing-fade {
  animation: typing-fade 2s ease-in-out infinite;
}

@keyframes typing-fade {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
}

/* ============================================
   Citation / SourceLink Styling (CSS-only tooltips)
   ============================================ */

.citation-wrapper {
  position: relative;
  display: inline;
}

.citation-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  vertical-align: super;
  margin: 0 2px;
  background: rgba(30, 117, 187, 0.25);
  color: #1e75bb;
  border-radius: 50%;
  text-decoration: none;
  transition: all 0.15s ease;
}

.citation-badge:hover {
  background: rgba(30, 117, 187, 0.4);
  color: #FFCC33;
  transform: scale(1.15);
}

.citation-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  padding: 12px;
  min-width: 220px;
  max-width: 280px;
  background: #1e232a;
  border: 1px solid rgba(254, 253, 251, 0.15);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
  z-index: 100;
  pointer-events: none;
}

.citation-wrapper:hover .citation-tooltip {
  opacity: 1;
  visibility: visible;
}

.citation-snippet {
  display: block;
  font-size: 0.8rem;
  font-style: italic;
  color: rgba(254, 253, 251, 0.8);
  line-height: 1.5;
  margin-bottom: 8px;
}

.citation-source {
  display: block;
  font-size: 0.7rem;
  color: #1e75bb;
  font-weight: 500;
}

/* ============================================
   Loading Screen
   ============================================ */

.loading-screen {
  position: fixed;
  inset: 0;
  background: #0d1117;
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.loading-screen.loaded {
  opacity: 0;
  pointer-events: none;
}

/* Print header - hidden on screen, visible in print (see scout-print.css) */
.print-header {
  display: none;
}

/* Print styles extracted to scout-print.css */

/* ============================================
   REVIEW STUDIO - Semantic Tokens
   ============================================ */
:root {
  /* SURFACES - Match Scout's actual colors */
  --rs-surface-app: #0d1117;           /* Scout main background */
  --rs-surface-panel: #1a1f26;         /* Scout secondary/panel background */
  --rs-surface-hover: rgba(255, 255, 255, 0.03);
  --rs-surface-selected: rgba(255, 204, 51, 0.08);
  --rs-surface-accepted: rgba(16, 185, 129, 0.2);

  /* BORDERS */
  --rs-border-subtle: rgba(255, 255, 255, 0.08);
  --rs-border-strong: rgba(255, 255, 255, 0.15);
  --rs-border-active: rgba(255, 204, 51, 0.6);

  /* INK (Typography) */
  --rs-ink-body: #f1f5f9;              /* Slate 100 */
  --rs-ink-secondary: #cbd5e1;         /* Slate 300 */
  --rs-ink-muted: #94a3b8;             /* Slate 400 */
  --rs-ink-faint: #475569;             /* Slate 600 */

  /* ACCENTS */
  --rs-accent: #FFCC33;                /* Gold */
  --rs-accent-hover: #e6b82e;
  --rs-accent-text: #0f172a;           /* Text on accent buttons */

  /* SUCCESS */
  --rs-success: #10b981;               /* Emerald 500 */
  --rs-success-hover: #059669;
  --rs-success-text: #ffffff;

  /* HANDLE */
  --rs-resize-handle-hover: rgba(255, 204, 51, 0.2);

  /* CHAT - Scout avatar and message styling */
  --rs-avatar-bg: rgba(255, 255, 255, 0.1);
  --rs-avatar-ring: rgba(255, 204, 51, 0.4);
  --rs-msg-assistant-bg: rgba(255, 255, 255, 0.03);
  --rs-msg-assistant-border: rgba(255, 255, 255, 0.05);
  --rs-msg-user-bg: #002a41;           /* ink color */
  --rs-msg-user-border: rgba(255, 255, 255, 0.1);
  --rs-input-bg: #1a1f26;
  --rs-input-border: rgba(255, 255, 255, 0.15);
  --rs-input-shadow: rgba(0, 0, 0, 0.2);
}

/* ============================================
   REVIEW STUDIO - Utility Classes
   ============================================ */

/* Surfaces */
.rs-surface-app { background-color: var(--rs-surface-app); }
.rs-surface-panel { background-color: var(--rs-surface-panel); }

/* Accent backgrounds */
.rs-bg-accent { background-color: var(--rs-accent); }

/* Typography */
.rs-ink-body { color: var(--rs-ink-body); }
.rs-ink-secondary { color: var(--rs-ink-secondary); }
.rs-ink-muted { color: var(--rs-ink-muted); }
.rs-ink-faint { color: var(--rs-ink-faint); }

/* Borders */
.rs-border-subtle { border-color: var(--rs-border-subtle); }
.rs-border-strong { border-color: var(--rs-border-strong); }

/* Hover states */
.rs-hover-ink-body:hover { color: var(--rs-ink-body); }
.rs-hover-ink-secondary:hover { color: var(--rs-ink-secondary); }
.rs-hover-surface:hover { background-color: var(--rs-surface-hover); }

/* Placeholder */
.rs-placeholder::placeholder { color: var(--rs-ink-muted); }

/* Focus ring */
.rs-focus:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--rs-accent);
}
.rs-focus:focus:not(:focus-visible) {
  box-shadow: none;
}

/* ============================================
   REVIEW STUDIO - Buttons
   ============================================ */

.rs-btn-primary {
  background-color: var(--rs-accent);
  color: var(--rs-accent-text);
}
.rs-btn-primary:hover {
  background-color: var(--rs-accent-hover);
}

.rs-btn-success {
  background-color: var(--rs-success);
  color: var(--rs-success-text);
}
.rs-btn-success:hover {
  background-color: var(--rs-success-hover);
}

.rs-btn-ghost {
  background-color: transparent;
  border: 1px solid var(--rs-border-strong);
  color: var(--rs-ink-secondary);
}
.rs-btn-ghost:hover {
  background-color: var(--rs-surface-hover);
  color: var(--rs-ink-body);
}

/* ============================================
   REVIEW STUDIO - Chat Components
   ============================================ */

/* Scout avatar - matches real Scout styling */
.rs-avatar {
  background-color: var(--rs-avatar-bg);
  box-shadow: 0 0 0 2px var(--rs-avatar-ring);
}

/* Assistant message card */
.rs-msg-assistant {
  background-color: var(--rs-msg-assistant-bg);
  border: 1px solid var(--rs-msg-assistant-border);
}

/* User message bubble */
.rs-msg-user {
  background-color: var(--rs-msg-user-bg);
  border: 1px solid var(--rs-msg-user-border);
}

/* Chat input */
.rs-input {
  background-color: var(--rs-input-bg);
  border: 1px solid var(--rs-input-border);
  box-shadow: 0 8px 16px var(--rs-input-shadow);
}
.rs-input:focus {
  border-color: var(--rs-border-strong);
}

/* ============================================
   REVIEW STUDIO - Typography
   ============================================ */

.rs-font-ui {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

.rs-font-editorial {
  font-family: 'Georgia', 'Cambria', 'Times New Roman', serif;
  line-height: 1.7;
}

.rs-font-mono {
  font-family: 'SF Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

/* ============================================
   REVIEW STUDIO - Paragraph Interactions
   ============================================ */

.rs-paragraph {
  transition: background-color 150ms ease-out, box-shadow 150ms ease-out;
  border-radius: 4px;
  cursor: pointer;
  user-select: text;
}

.rs-paragraph:hover {
  background-color: var(--rs-surface-hover);
}

.rs-paragraph:hover .rs-para-number {
  color: var(--rs-accent);
}

/* "Golden Thread" selection - left border accent */
.rs-paragraph.is-selected {
  background-color: var(--rs-surface-selected);
  box-shadow: inset 3px 0 0 0 var(--rs-accent);
}

.rs-paragraph.is-selected .rs-para-number {
  color: var(--rs-accent);
}

/* Accept flash animation */
@keyframes rs-accept-flash {
  0% { background-color: var(--rs-surface-accepted); }
  100% { background-color: transparent; }
}

.rs-paragraph.is-accepted {
  animation: rs-accept-flash 1.5s ease-out;
}

/* Paragraph numbers must not be selectable */
.rs-para-number {
  user-select: none;
  color: var(--rs-ink-faint);
  transition: color 150ms ease-out;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .rs-paragraph {
    transition: none;
  }
  .rs-paragraph.is-accepted {
    animation: none;
    background-color: var(--rs-surface-accepted);
  }

  /* Disable panel transitions for users who prefer reduced motion */
  .rs-transition-panel {
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   REVIEW STUDIO - Resize Handle
   ============================================ */

.rs-resize-handle {
  transition: background-color 150ms ease-out;
}

.rs-resize-handle:hover,
.rs-resize-handle.is-dragging {
  background-color: var(--rs-resize-handle-hover);
}

/* ============================================
   REVIEW STUDIO - Panel Depth
   ============================================ */

.rs-panel-depth {
  /* Dark mode: subtle inner highlight for beveled look */
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
}

/* ============================================
   Alpine Cloak (prevent flash of unstyled content)
   ============================================ */

[x-cloak] { display: none !important; }
