/* Non-Critical CSS - Below the fold and deferred styles */

/* Enhanced Color Variables */
:root {
  --economist-light-red: #ff4a4a;
  --text-light: #888888;
  --text-tertiary: #999999;
  --bg-tertiary: #e9ecef;
  --shadow-medium: rgba(0, 0, 0, 0.15);
  --success-green: #28a745;
  --warning-yellow: #ffc107;
  --error-red: #dc3545;
}

/* Dark mode support - Enhanced */
@media (prefers-color-scheme: dark) {
  :root {
    --text-light: #888888;
    --text-tertiary: #999999;
    --bg-tertiary: #404040;
    --shadow-medium: rgba(0, 0, 0, 0.5);
  }
}

/* Enhanced Touch Support */
body {
  touch-action: manipulation;
  user-select: none;
}

/* Skeleton Loading States */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--bg-tertiary) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.skeleton-title {
  height: 20px;
  width: 70%;
  margin-bottom: 0.5rem;
}

.skeleton-subtitle {
  height: 16px;
  width: 50%;
  margin-bottom: 0.25rem;
}

.skeleton-duration {
  height: 24px;
  width: 60px;
  border-radius: 6px;
}

/* Error Styles */
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
}

.error-icon {
  width: 60px;
  height: 60px;
  background: var(--error-red);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.retry-btn {
  background: var(--economist-red);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.retry-btn:hover {
  background: var(--economist-dark-red);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-medium);
}

/* Empty States */
.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.no-results-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  opacity: 0.3;
}

.no-results h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

/* Filter Container */
.filter-container {
  background: var(--bg-secondary);
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.section-filter {
  flex: 1;
  min-width: 200px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}

/* Section Containers */
.section-container {
  margin-bottom: 2.5rem;
}

.section-header {
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color);
}

.section-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.02em;
}

.section-articles {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Enhanced Article Cards */
.article-card.playing {
  border-color: var(--economist-red);
  box-shadow: 0 0 0 2px var(--economist-light-red);
}

.article-card.playing::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--economist-red);
}

/* Enhanced Player Controls */
.track-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.track-btn:hover:not(:disabled) {
  background: var(--economist-red);
  color: white;
}

/* Sleep Timer Styles */
.sleep-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  position: relative;
}

.sleep-btn:hover:not(:disabled) {
  background: var(--economist-red);
  color: white;
}

.sleep-btn.active {
  background: var(--economist-red);
  color: white;
}

.sleep-btn.active::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--success-green);
  border-radius: 50%;
  border: 2px solid var(--economist-red);
}

/* Sleep Timer Overlay */
.sleep-timer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.sleep-timer-content {
  background: var(--bg-primary);
  border-radius: 16px;
  max-width: 400px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 40px var(--shadow-medium);
}

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

.sleep-timer-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.2s;
}

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

.sleep-timer-body {
  padding: 1.5rem;
}

.sleep-timer-status {
  margin: 0 0 1.5rem 0;
  font-size: 1rem;
  color: var(--text-primary);
  text-align: center;
}

.timer-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.timer-preset-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.timer-preset-btn:hover {
  background: var(--economist-red);
  color: white;
  border-color: var(--economist-red);
}

.timer-preset-btn.selected {
  background: var(--economist-red);
  color: white;
  border-color: var(--economist-red);
}

.custom-timer {
  margin-bottom: 2rem;
}

.timer-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  outline: none;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s;
}

.timer-input:focus {
  border-color: var(--economist-red);
}

.timer-input::placeholder {
  color: var(--text-light);
}

.custom-timer-display {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.sleep-timer-actions {
  display: flex;
  gap: 1rem;
}

.timer-cancel-btn {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.timer-cancel-btn:hover {
  background: var(--bg-tertiary);
}

.timer-start-btn {
  flex: 1;
  background: var(--economist-red);
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.timer-start-btn:hover {
  background: var(--economist-dark-red);
}

/* Speed Control Styles */
.speed-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 6px;
}

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

.speed-indicator {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--economist-red);
  min-width: 24px;
  text-align: center;
}

.speed-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.speed-content {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 8px 32px var(--shadow-medium);
  border: 1px solid var(--border-color);
  min-width: 200px;
}

.speed-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.speed-option {
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  text-align: center;
}

.speed-option:hover {
  background: var(--economist-red);
  color: white;
  border-color: var(--economist-red);
  transform: translateY(-1px);
}

.speed-option.active {
  background: var(--economist-red);
  color: white;
  border-color: var(--economist-red);
}

/* iOS Specific Optimizations */
@supports (-webkit-touch-callout: none) {
  .control-btn {
    width: 44px;
    height: 44px;
  }

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

  .track-btn:not(:disabled):active {
    background: var(--economist-red);
    color: white;
  }

  #playPauseBtn {
    background: var(--economist-red) !important;
    color: white !important;
  }

  .audio-player {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Enhanced Mobile Optimizations */
@media (max-width: 480px) {
  .header {
    padding: 0.5rem;
  }

  .header-content {
    padding: 0;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .search-container {
    padding: 0.5rem;
  }

  .filter-container {
    padding: 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .main-content {
    padding: 0.75rem;
  }

  .article-card {
    padding: 0.5rem;
  }

  .article-title {
    font-size: 0.9rem;
  }

  .player-controls {
    gap: 0.25rem;
  }

  .time-display {
    font-size: 0.625rem;
    min-width: 70px;
  }

  .speed-btn {
    background: transparent;
    border: none;
    padding: 0.25rem;
    min-width: auto;
    flex-shrink: 0;
  }

  .speed-indicator {
    font-size: 0.625rem;
    min-width: 20px;
  }

  .sleep-btn {
    background: transparent;
    border: none;
    flex-shrink: 0;
  }

  .track-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
  }

  .track-btn:not(:disabled):hover {
    background: var(--economist-red);
    color: white;
    border-color: var(--economist-red);
  }
}

/* Touch Optimizations */
@media (hover: none) {
  .article-card:hover {
    transform: none;
    box-shadow: 0 2px 8px var(--shadow-light);
  }

  .control-btn:hover {
    background: none;
  }

  .search-btn:hover {
    background: none;
  }

  .timer-preset-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
  }

  .speed-option:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
  }

  .article-card {
    transition: all 0.1s ease;
  }

  .control-btn {
    transition: all 0.1s ease;
  }
}

/* Focus States */
button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--economist-red);
  outline-offset: 2px;
}

/* RTL Support */
[dir="rtl"] .article-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .time-display {
  flex-direction: row-reverse;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --shadow-light: rgba(0, 0, 0, 0.5);
    --shadow-medium: rgba(0, 0, 0, 0.7);
  }
}

/* Notification Animations */
@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

@keyframes slideDown {
  from {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 0);
    opacity: 1;
  }
  to {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
}

/* Progress Bar Enhancement */
.progress-fill {
  height: 100%;
  background: var(--economist-red);
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s ease;
}

/* iOS PWA Specific Fixes */
@supports (-webkit-touch-callout: none) {
  .audio-player {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  html.ios-pwa {
    height: 100vh;
    overflow: hidden;
  }

  body.ios-pwa {
    height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ios-pwa .header {
    padding-top: calc(
      max(1rem, env(safe-area-inset-top)) + env(safe-area-inset-top)
    );
  }

  .ios-pwa .audio-player {
    padding-bottom: calc(
      max(1rem, env(safe-area-inset-bottom)) + env(safe-area-inset-bottom)
    );
  }
}

/* Print Styles */
@media print {
  .header,
  .filter-container,
  .audio-player,
  .search-container {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .article-card {
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
