/**
 * Mobile-First Responsive Stylesheet
 * Hebrew Bible Analysis Suite
 *
 * Optimized for:
 * - Touch interfaces (44x44px minimum touch targets)
 * - Fast loading (minimal animations, optimized assets)
 * - Accessibility (WCAG 2.1 AA compliant)
 * - Progressive enhancement (mobile-first, desktop-enhanced)
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */

:root {
  /* Colors */
  --primary: #667eea;
  --primary-dark: #5568d3;
  --primary-light: #7c8ff0;
  --secondary: #764ba2;
  --accent: #f093fb;

  --text-primary: #2c3e50;
  --text-secondary: #7f8c8d;
  --text-light: #95a5a6;

  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;

  --success: #27ae60;
  --warning: #f39c12;
  --error: #e74c3c;
  --info: #3498db;

  --border: #e0e0e0;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.15);

  /* Spacing */
  --space-xs: 0.25rem;   /* 4px */
  --space-sm: 0.5rem;    /* 8px */
  --space-md: 1rem;      /* 16px */
  --space-lg: 1.5rem;    /* 24px */
  --space-xl: 2rem;      /* 32px */
  --space-2xl: 3rem;     /* 48px */

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  --font-hebrew: 'David Libre', 'Frank Ruehl CLM', 'Times New Roman', serif;

  --font-size-xs: 0.75rem;   /* 12px */
  --font-size-sm: 0.875rem;  /* 14px */
  --font-size-md: 1rem;      /* 16px - base */
  --font-size-lg: 1.125rem;  /* 18px */
  --font-size-xl: 1.25rem;   /* 20px */
  --font-size-2xl: 1.5rem;   /* 24px */
  --font-size-3xl: 1.875rem; /* 30px */
  --font-size-4xl: 2.25rem;  /* 36px */

  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-loose: 1.75;

  /* Border Radius */
  --radius-sm: 0.25rem;  /* 4px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-xl: 1rem;     /* 16px */
  --radius-full: 9999px; /* pill shape */

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;

  /* Z-index layers */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;

  /* Touch targets */
  --touch-target: 44px;  /* Apple HIG minimum */

  /* Breakpoints (for reference in media queries) */
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
}

/* ============================================
   Reset & Base Styles
   ============================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%; /* Prevent text scaling on orientation change */
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background: var(--bg-secondary);
  overflow-x: hidden;
}

/* ============================================
   Typography
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  line-height: var(--line-height-tight);
  font-weight: 700;
  margin-bottom: var(--space-md);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-md); }
h6 { font-size: var(--font-size-sm); }

p {
  margin-bottom: var(--space-md);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-dark);
}

.hebrew {
  font-family: var(--font-hebrew);
  direction: rtl;
}

/* ============================================
   Layout Containers
   ============================================ */

.container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: var(--space-md);
}

@media (min-width: 640px) {
  .container {
    padding: var(--space-lg);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1280px;
    padding: var(--space-xl);
  }
}

/* ============================================
   Mobile Navigation
   ============================================ */

.mobile-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  box-shadow: 0 2px 8px var(--shadow);
}

.mobile-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
}

.logo {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: white;
}

.hamburger {
  width: var(--touch-target);
  height: var(--touch-target);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
  -webkit-tap-highlight-color: transparent;
}

.hamburger span {
  width: 24px;
  height: 3px;
  background: white;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  margin: 2px 0;
}

.hamburger.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-nav {
  display: none;
  background: white;
  border-top: 1px solid var(--border);
  box-shadow: 0 4px 12px var(--shadow);
}

.mobile-nav.active {
  display: block;
}

.mobile-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mobile-nav-item {
  border-bottom: 1px solid var(--border);
}

.mobile-nav-link {
  display: flex;
  align-items: center;
  padding: var(--space-md);
  color: var(--text-primary);
  font-weight: 600;
  min-height: var(--touch-target);
  transition: background var(--transition-fast);
}

.mobile-nav-link:hover,
.mobile-nav-link:active {
  background: var(--bg-secondary);
}

.mobile-nav-link.active {
  background: var(--bg-tertiary);
  color: var(--primary);
  border-right: 4px solid var(--primary);
}

.nav-icon {
  width: 24px;
  height: 24px;
  margin-left: var(--space-sm);
  font-size: var(--font-size-xl);
}

/* Desktop Navigation */
@media (min-width: 768px) {
  .hamburger {
    display: none;
  }

  .mobile-nav {
    display: flex !important;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .mobile-nav-list {
    display: flex;
    gap: var(--space-sm);
    width: 100%;
    justify-content: center;
  }

  .mobile-nav-item {
    border: none;
  }

  .mobile-nav-link {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: white;
    min-height: auto;
  }

  .mobile-nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
  }

  .mobile-nav-link.active {
    background: rgba(255, 255, 255, 0.3);
    border: none;
  }
}

/* ============================================
   Buttons (Touch-Optimized)
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-lg);
  min-height: var(--touch-target);
  font-size: var(--font-size-md);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 12px var(--shadow-lg);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: var(--space-sm);
  min-width: var(--touch-target);
  min-height: var(--touch-target);
}

/* ============================================
   Form Elements (Touch-Optimized)
   ============================================ */

input[type="text"],
input[type="search"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: var(--space-md);
  min-height: var(--touch-target);
  font-size: var(--font-size-md);
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: white;
  transition: border-color var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: 600;
  color: var(--text-primary);
}

/* Custom checkbox/radio (larger touch targets) */
input[type="checkbox"],
input[type="radio"] {
  width: 24px;
  height: 24px;
  margin-left: var(--space-sm);
  cursor: pointer;
}

/* ============================================
   Cards
   ============================================ */

.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: var(--space-md);
}

.card-header {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--border);
}

.card-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.card-body {
  margin-bottom: var(--space-md);
}

.card-footer {
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

/* ============================================
   Grid System
   ============================================ */

.grid {
  display: grid;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 640px) {
  .grid-sm-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-sm-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
  .grid-md-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-md-4 { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
  .grid-lg-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-lg-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-lg-5 { grid-template-columns: repeat(5, 1fr); }
}

/* ============================================
   Status Messages
   ============================================ */

.status {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.status-success {
  background: rgba(39, 174, 96, 0.1);
  color: var(--success);
  border: 2px solid var(--success);
}

.status-error {
  background: rgba(231, 76, 60, 0.1);
  color: var(--error);
  border: 2px solid var(--error);
}

.status-warning {
  background: rgba(243, 156, 18, 0.1);
  color: var(--warning);
  border: 2px solid var(--warning);
}

.status-info {
  background: rgba(52, 152, 219, 0.1);
  color: var(--info);
  border: 2px solid var(--info);
}

/* ============================================
   Loading States
   ============================================ */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--space-md);
}

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

/* ============================================
   Bottom Action Bar (Mobile)
   ============================================ */

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px var(--shadow);
  padding: var(--space-sm) var(--space-md);
  z-index: var(--z-sticky);
  display: flex;
  gap: var(--space-sm);
}

@media (min-width: 768px) {
  .bottom-bar {
    display: none;
  }
}

/* ============================================
   Root Display Components
   ============================================ */

.root-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-md);
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin: var(--space-xs);
}

.root-expansion {
  background: rgba(102, 126, 234, 0.05);
  border-right: 4px solid var(--primary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin: var(--space-md) 0;
}

.root-expansion-title {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: var(--space-sm);
}

.root-words {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.root-word {
  background: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-family: var(--font-hebrew);
  font-size: var(--font-size-lg);
}

/* ============================================
   Result Cards
   ============================================ */

.result-item {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  transition: all var(--transition-fast);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.result-item:hover,
.result-item:active {
  border-color: var(--primary);
  box-shadow: 0 4px 12px var(--shadow);
  transform: translateY(-2px);
}

.result-item.selected {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.05);
}

.result-word {
  font-family: var(--font-hebrew);
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: var(--space-sm);
  direction: rtl;
}

.result-meta {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.result-score {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  background: var(--primary);
  color: white;
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

/* ============================================
   Tabs (Touch-Optimized)
   ============================================ */

.tabs {
  display: flex;
  gap: var(--space-sm);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: var(--space-md) var(--space-lg);
  min-height: var(--touch-target);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ============================================
   Utilities
   ============================================ */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

.hidden { display: none !important; }
.visible { display: block !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.mt-0 { margin-top: 0 !important; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

/* ============================================
   Accessibility
   ============================================ */

.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;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .mobile-header,
  .mobile-nav,
  .bottom-bar,
  .btn {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--border);
  }
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* GPU acceleration for animations */
.spinner,
.hamburger span,
.btn,
.result-item {
  will-change: transform;
}

/* Prevent layout shift */
img {
  max-width: 100%;
  height: auto;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
