/* ============================================
   Médiathèque AppForm - Design System
   Mobile-First CSS avec Bootstrap 5
   ============================================ */

/* CSS Variables - Design Tokens */
:root {
  /* Primary - Orange dynamique */
  --primary-h: 24;
  --primary-s: 95%;
  --primary-l: 53%;
  --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
  --primary-foreground: hsl(0, 0%, 100%);
  
  /* Secondary - Bleu Marine profond */
  --secondary-h: 220;
  --secondary-s: 60%;
  --secondary-l: 20%;
  --secondary: hsl(var(--secondary-h), var(--secondary-s), var(--secondary-l));
  --secondary-foreground: hsl(0, 0%, 100%);
  
  /* Background */
  --background: hsl(0, 0%, 100%);
  --foreground: hsl(220, 60%, 15%);
  
  /* Surfaces */
  --card: hsl(0, 0%, 100%);
  --card-foreground: hsl(220, 60%, 15%);
  
  /* Muted */
  --muted: hsl(220, 14%, 96%);
  --muted-foreground: hsl(220, 20%, 40%);
  
  /* Border */
  --border: hsl(220, 13%, 91%);
  
  /* Sidebar */
  --sidebar-bg: hsl(220, 60%, 20%);
  --sidebar-foreground: hsl(0, 0%, 95%);
  --sidebar-accent: hsl(220, 50%, 28%);
  --sidebar-border: hsl(220, 50%, 25%);
  
  /* Shadows */
  --shadow-card: 0 4px 20px -2px hsla(220, 60%, 15%, 0.08);
  --shadow-card-hover: 0 8px 30px -4px hsla(220, 60%, 15%, 0.12);
  --shadow-header: 0 2px 12px -2px hsla(220, 60%, 15%, 0.1);
  
  /* Radius */
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 200ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;
}

/* Base Styles */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--foreground);
  background-color: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

html {
  overflow-x: hidden;
}

/* ============================================
   Header
   ============================================ */
.header-fixed {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background-color: hsla(0, 0%, 100%, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-header);
  padding-top: env(safe-area-inset-top, 0);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 1rem;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background-color: var(--primary);
  color: var(--primary-foreground);
  font-size: 1.25rem;
}

.logo-text {
  font-weight: 600;
  color: var(--secondary);
  white-space: nowrap;
}

.logo-text .text-primary {
  color: var(--primary);
}

.search-wrapper {
  flex: 1;
  max-width: 400px;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-foreground);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 1rem 0 2.5rem;
  border: none;
  border-radius: var(--radius);
  background-color: var(--muted);
  color: var(--foreground);
  font-size: 0.875rem;
  transition: box-shadow var(--transition-fast);
}

.search-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

.search-input::placeholder {
  color: var(--muted-foreground);
}

.mobile-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--foreground);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.btn-icon:hover {
  background-color: var(--muted);
}

.search-mobile {
  padding: 0.5rem 0 1rem;
}

/* ============================================
   Mobile Drawer
   ============================================ */
.mobile-overlay {
  position: fixed;
  inset: 0;
  background-color: hsla(220, 60%, 15%, 0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.mobile-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 288px;
  background-color: var(--sidebar-bg);
  z-index: 50;
  transform: translateX(100%);
  transition: transform var(--transition-normal) ease-out;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-drawer.active {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.drawer-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--sidebar-foreground);
  margin: 0;
}

.drawer-header .btn-icon {
  color: var(--sidebar-foreground);
}

.drawer-header .btn-icon:hover {
  background-color: var(--sidebar-accent);
}

.drawer-nav {
  list-style: none;
  padding: 1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.drawer-nav-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-foreground);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  transition: background-color var(--transition-fast);
}

.drawer-nav-item:hover {
  background-color: var(--sidebar-accent);
}

.drawer-nav-item.active {
  background-color: var(--primary);
  color: var(--primary-foreground);
}

.drawer-nav-item .count {
  margin-left: 0.5rem;
  font-size: 0.875rem;
  opacity: 0.75;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  padding-top: 80px;
  padding-bottom: 2rem;
  flex: 1;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--foreground);
  margin: 0 0 0.5rem;
}

.page-subtitle {
  color: var(--muted-foreground);
  margin: 0;
}

@media (min-width: 768px) {
  .page-header {
    margin-bottom: 2rem;
  }
  
  .page-title {
    font-size: 1.875rem;
  }
}

/* ============================================
   Chapter Tabs
   ============================================ */
.chapter-tabs-wrapper {
  margin: 0 -12px 1.5rem;
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

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

.chapter-tabs {
  display: flex;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  min-width: max-content;
}

.chapter-tab {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--muted);
  color: var(--muted-foreground);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  min-height: 44px;
  transition: all var(--transition-fast);
}

.chapter-tab:hover {
  background-color: hsla(220, 14%, 90%, 1);
  color: var(--foreground);
}

.chapter-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px var(--background);
}

.chapter-tab.active {
  background-color: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 2px 8px hsla(24, 95%, 53%, 0.3);
}

.chapter-tab .count {
  margin-left: 0.375rem;
  font-size: 0.75rem;
  opacity: 0.75;
}

@media (min-width: 768px) {
  .chapter-tabs-wrapper {
    margin: 0 0 2rem;
    padding: 0;
  }
}

/* ============================================
   Results Count
   ============================================ */
.results-count {
  margin-bottom: 1rem;
}

.results-count p {
  font-size: 0.875rem;
  color: var(--muted-foreground);
  margin: 0;
}

@media (min-width: 768px) {
  .results-count {
    margin-bottom: 1.5rem;
  }
}

/* ============================================
   Media Grid
   ============================================ */
.media-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

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

@media (min-width: 992px) {
  .media-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
}

/* ============================================
   Media Card
   ============================================ */
.media-card {
  display: flex;
  flex-direction: column;
  background-color: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  opacity: 0;
  animation: fadeInUp 0.5s ease-out forwards;
}

.media-card:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-card-hover);
}

@media (min-width: 768px) {
  .media-card:hover {
    transform: scale(1.05);
  }
}

/* Staggered animation delays */
.media-card:nth-child(1) { animation-delay: 0.1s; }
.media-card:nth-child(2) { animation-delay: 0.2s; }
.media-card:nth-child(3) { animation-delay: 0.3s; }
.media-card:nth-child(4) { animation-delay: 0.4s; }
.media-card:nth-child(5) { animation-delay: 0.5s; }
.media-card:nth-child(6) { animation-delay: 0.6s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-image-wrapper {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: var(--muted);
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

.media-card:hover .card-image {
  transform: scale(1.05);
}

.card-badge-type {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background-color: hsla(220, 60%, 20%, 0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-full);
  color: var(--secondary-foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.card-badge-type i {
  font-size: 0.875rem;
}

.card-badge-duration {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background-color: hsla(0, 0%, 100%, 0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-sm);
  color: var(--foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.card-badge-duration i {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.card-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1rem;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .card-content {
    padding: 1.5rem;
  }
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--foreground);
  line-height: 1.3;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (min-width: 768px) {
  .card-title {
    font-size: 1.25rem;
  }
}

.card-description {
  font-size: 0.875rem;
  color: var(--muted-foreground);
  line-height: 1.5;
  margin: 0;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (min-width: 768px) {
  .card-description {
    font-size: 1rem;
    -webkit-line-clamp: 3;
  }
}

.card-footer {
  padding: 0 1rem 1rem;
  margin-top: auto;
}

@media (min-width: 768px) {
  .card-footer {
    padding: 0 1.5rem 1.5rem;
    margin-top: auto;
  }
}

.card-button {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background-color: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  min-height: 44px;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.card-button:hover {
  background-color: hsl(24, 95%, 45%);
}

.card-button:active {
  transform: scale(0.98);
}

.card-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--primary);
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
  text-align: center;
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  border-radius: 50%;
  background-color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--muted-foreground);
}

.empty-title {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--foreground);
  margin: 0 0 0.25rem;
}

.empty-text {
  color: var(--muted-foreground);
  margin: 0;
}

/* ============================================
   Footer
   ============================================ */
.footer {
  background-color: var(--secondary);
  padding: 1.5rem 0;
  margin-top: auto;
}

.footer-text {
  font-size: 0.875rem;
  color: hsla(0, 0%, 100%, 0.8);
  margin: 0;
}

/* ============================================
   Utility Classes
   ============================================ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

@media (min-width: 768px) {
  .container {
    padding: 0 1.5rem;
  }
}

/* Hide scrollbar */
.hide-scrollbar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

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

/* Visually hidden for screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Detail Page
   ============================================ */
.detail-page {
  padding-top: 80px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color var(--transition-fast);
}

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

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background-color: var(--muted);
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--transition-fast);
}

.btn-back:hover {
  background-color: hsla(220, 14%, 90%, 1);
  color: var(--foreground);
}

/* Hero Section */
.detail-hero {
  margin-bottom: 1.5rem;
}

.hero-image-wrapper {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background-color: var(--muted);
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to top, hsla(0, 0%, 0%, 0.5), transparent);
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.play-overlay:hover {
  background: linear-gradient(to top, hsla(0, 0%, 0%, 0.6), hsla(0, 0%, 0%, 0.1));
}

.play-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-color: var(--primary);
  color: var(--primary-foreground);
  font-size: 1.75rem;
  box-shadow: 0 4px 20px hsla(24, 95%, 53%, 0.4);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.play-overlay:hover .play-button {
  transform: scale(1.1);
  box-shadow: 0 6px 30px hsla(24, 95%, 53%, 0.5);
}

@media (min-width: 768px) {
  .play-button {
    width: 80px;
    height: 80px;
    font-size: 2rem;
  }
}

/* Content Section */
.detail-content {
  margin-bottom: 2rem;
}

.content-header {
  margin-bottom: 1.5rem;
}

.content-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--foreground);
  margin: 0 0 1rem;
  line-height: 1.3;
}

@media (min-width: 768px) {
  .content-title {
    font-size: 2rem;
  }
}

.content-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
}

.type-badge {
  background-color: var(--secondary);
  color: var(--secondary-foreground);
}

.duration-badge {
  background-color: var(--muted);
  color: var(--foreground);
}

.chapter-badge {
  background-color: hsla(24, 95%, 53%, 0.15);
  color: var(--primary);
}

.content-body {
  padding: 1.5rem;
  background-color: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--foreground);
  margin: 0 0 0.75rem;
}

.content-description {
  font-size: 1rem;
  color: var(--muted-foreground);
  line-height: 1.7;
  margin: 0 0 1.5rem;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background-color: var(--primary);
  color: var(--primary-foreground);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 48px;
  text-decoration: none;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn-action:hover {
  background-color: hsl(24, 95%, 45%);
  color: var(--primary-foreground);
}

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

/* Navigation */
.detail-navigation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background-color: var(--muted);
  text-decoration: none;
  transition: background-color var(--transition-fast);
}

.nav-link:hover {
  background-color: hsla(220, 14%, 90%, 1);
}

.nav-prev {
  justify-content: flex-start;
}

.nav-next {
  justify-content: flex-end;
  text-align: right;
}

.nav-link i {
  font-size: 1.25rem;
  color: var(--muted-foreground);
}

.nav-text {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.nav-label {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 575px) {
  .nav-title {
    display: none;
  }
}

/* Related Resources */
.related-section {
  margin-bottom: 2rem;
}

.related-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--foreground);
  margin: 0 0 1rem;
}

/* Card with link */
.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.card-footer {
  padding: 0 1rem 1rem;
  margin-top: auto;
}

@media (min-width: 768px) {
  .card-footer {
    padding: 0 1.5rem 1.5rem;
    margin-top: auto;
  }
}

/* Not Found */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
  text-align: center;
  min-height: 50vh;
}

.not-found-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
  border-radius: 50%;
  background-color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--muted-foreground);
}

.not-found-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--foreground);
  margin: 0 0 0.5rem;
}

.not-found-text {
  color: var(--muted-foreground);
  margin: 0 0 1.5rem;
}
