/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Accessibility utilities */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Skip links for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 9999;
  font-weight: bold;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 6px;
  outline: 3px solid #ffbf47;
  outline-offset: 2px;
}

/* High contrast and focus indicators */
:root {
  --focus-color: #ffbf47;
  --focus-width: 3px;
  --text-primary: #212529;
  --text-secondary: #495057;
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --border-color: #dee2e6;
  --link-color: #0066cc;
  --link-hover: #004499;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --text-primary: #000000;
    --text-secondary: #000000;
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --border-color: #000000;
    --link-color: #0000ee;
    --link-hover: #000088;
  }

  .header {
    background: #000000 !important;
    color: #ffffff !important;
  }

  .search-input,
  .clear-button {
    border: 2px solid #000000 !important;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  font-size: 16px; /* Base font size for better readability */
}

/* Focus management */
*:focus {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users, keep for keyboard users */
*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

.container {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* Header */
.header {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
}

.header-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.site-description {
  font-size: 1.1rem;
  margin-bottom: 0;
  opacity: 0.9;
  line-height: 1.4;
}

.refresh-button {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.refresh-button:hover,
.refresh-button:focus {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

.refresh-button:active {
  transform: translateY(0);
}

.refresh-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.download-button {
  align-self: flex-start;
  background: rgba(34, 197, 94, 0.2); /* Green background for download */
  border: 2px solid rgba(34, 197, 94, 0.4);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  text-decoration: none;
  display: inline-block;
}

.download-button:hover,
.download-button:focus {
  background: rgba(34, 197, 94, 0.3);
  border-color: rgba(34, 197, 94, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
  text-decoration: none;
  color: white;
}

.download-button:active {
  transform: translateY(0);
}

.download-button:visited {
  color: white;
}

/* Header controls container */
.header-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-start;
}

/* Language selector */
.language-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.language-label {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  font-size: 1rem;
  margin-right: 0.5rem;
}

.language-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  min-width: 60px;
}

.language-btn:hover,
.language-btn:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

.language-btn.active {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.language-btn:active {
  transform: translateY(0);
}

/* Zone search */
.zone-search {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.zone-label {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  font-size: 1rem;
}

.zone-input-container {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.zone-input {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 120px;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.zone-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.zone-input:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

.zone-search-btn,
.zone-clear-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.zone-search-btn:hover,
.zone-search-btn:focus,
.zone-clear-btn:hover,
.zone-clear-btn:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

.zone-clear-btn {
  background: rgba(255, 100, 100, 0.2);
  border-color: rgba(255, 100, 100, 0.3);
}

.zone-clear-btn:hover,
.zone-clear-btn:focus {
  background: rgba(255, 100, 100, 0.3);
  border-color: rgba(255, 100, 100, 0.5);
}

.zone-help {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
  line-height: 1.4;
  max-width: 300px;
}

/* No results message */
.no-results {
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 2px solid var(--border-color);
  margin: 2rem auto;
  max-width: 500px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.no-results h2 {
  color: #dc3545;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.no-results p {
  color: var(--text-secondary);
  margin: 1rem 0;
  line-height: 1.6;
}

.retry-button {
  background: var(--link-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 1rem;
}

.retry-button:hover,
.retry-button:focus {
  background: var(--link-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

/* Sidebar */
.sidebar {
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: calc(100vh - 140px);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.sidebar-header h2 {
  color: var(--text-secondary);
  font-size: 1.2rem;
  margin: 0;
}

.toggle-button {
  background: none;
  border: 2px solid transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: none;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.toggle-button:hover,
.toggle-button:focus {
  background: var(--bg-secondary);
  border-color: var(--focus-color);
}

.toc-content {
  padding: 1rem;
}

.toc-content ul {
  list-style: none;
}

.toc-content li {
  margin: 0.5rem 0;
}

.toc-content a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  display: block;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  border: 2px solid transparent;
}

.toc-content a:hover,
.toc-content a:focus {
  background: var(--bg-secondary);
  color: var(--link-color);
  transform: translateX(5px);
  text-decoration: underline;
  border-color: var(--focus-color);
}

.toc-content .toc-h2 {
  font-weight: 600;
  margin-top: 1rem;
  font-size: 1rem;
}

.toc-content .toc-h3 {
  margin-left: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Improved keyboard navigation for TOC */
.toc-content a[aria-current="page"] {
  background: var(--link-color);
  color: white;
  font-weight: bold;
}

/* Main content */
.content {
  padding: 2rem;
  background: var(--bg-primary);
  overflow-y: auto;
  max-width: none;
}

#main-content {
  outline: none;
}

.loading {
  text-align: center;
  font-size: 1.2rem;
  color: var(--text-secondary);
  padding: 3rem;
}

/* Markdown styles with improved accessibility */
.content h1 {
  color: var(--text-primary);
  margin: 2rem 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid #3498db;
  font-size: 2.5rem;
  line-height: 1.2;
}

.content h2 {
  color: var(--text-primary);
  margin: 2rem 0 1rem 0;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--border-color);
  font-size: 2rem;
  line-height: 1.3;
}

.content h3 {
  color: var(--link-color);
  margin: 1.5rem 0 1rem 0;
  font-size: 1.5rem;
  line-height: 1.4;
}

.content h4,
.content h5,
.content h6 {
  color: var(--text-primary);
  margin: 1rem 0 0.5rem 0;
  line-height: 1.4;
}

.content ul {
  margin: 1rem 0;
  padding-left: 2rem;
}

.content li {
  margin: 0.5rem 0;
  line-height: 1.8;
}

.content li strong {
  color: var(--text-primary);
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.content p {
  margin: 1rem 0;
  line-height: 1.8;
  font-size: 1rem;
}

/* Links with better accessibility */
.content a,
.toc-content a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.content a:hover,
.content a:focus {
  color: var(--link-hover);
  text-decoration-thickness: 3px;
}

.content a:visited {
  color: #663399;
}

/* Responsive design with accessibility considerations */
@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 1000;
    background: var(--bg-primary);
    border-right: none;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    display: block;
  }

  .toggle-button {
    display: block;
  }

  .header {
    padding: 1rem;
  }

  .header h1 {
    font-size: 1.8rem;
  }

  .header-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .language-selector {
    justify-content: center;
    flex-wrap: wrap;
  }

  .language-label {
    align-self: center;
    margin-bottom: 0.5rem;
  }

  .language-btn {
    min-width: 50px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }

  .refresh-button {
    align-self: stretch;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }

  .download-button {
    align-self: stretch;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin-left: 0;
    margin-top: 0.5rem;
  }

  .zone-search {
    align-items: stretch;
  }

  .zone-label {
    align-self: center;
    margin-bottom: 0.5rem;
  }

  .zone-input-container {
    justify-content: stretch;
    flex-direction: column;
    gap: 0.5rem;
  }

  .zone-input {
    min-width: auto;
    width: 100%;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .zone-search-btn,
  .zone-clear-btn {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.9rem;
  }

  .zone-help {
    max-width: none;
    text-align: center;
  }

  .content {
    padding: 1rem;
  }

  .search-container {
    flex-direction: row;
    max-width: 100%;
  }

  .search-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Ensure skip links work on mobile */
  .skip-link:focus {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 10000;
  }
}

/* Large screens: horizontal header controls */
@media (min-width: 900px) {
  .header-controls {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .language-selector {
    margin-right: auto;
  }

  .refresh-button {
    align-self: auto;
    margin-left: 2rem;
  }

  .download-button {
    align-self: auto;
    margin-left: 0.5rem;
  }
}

/* Large text preferences */
@media (min-width: 1200px) {
  body {
    font-size: 18px;
  }

  .content h1 {
    font-size: 3rem;
  }

  .content h2 {
    font-size: 2.25rem;
  }

  .content h3 {
    font-size: 1.75rem;
  }
}

/* Scroll behavior with accessibility considerations */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Custom scrollbar with better contrast */
::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 6px;
  border: 2px solid var(--bg-secondary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-primary);
}

/* Animation with respect for reduced motion */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.content > * {
  animation: fadeIn 0.6s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .content > * {
    animation: none;
  }
}

/* Print styles for accessibility */
@media print {
  .header .search-container,
  .sidebar,
  .search-results,
  .skip-link {
    display: none;
  }

  .container {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 0;
    box-shadow: none;
  }

  .content h1,
  .content h2,
  .content h3 {
    color: black;
    border-bottom-color: black;
  }

  .content a {
    color: black;
    text-decoration: underline;
  }

  .content a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    word-break: break-all;
  }
}

/* Error and status messages */
.error {
  background: #f8d7da;
  color: #721c24;
  padding: 1rem;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  margin: 1rem 0;
  font-weight: 600;
}

.success {
  background: #d4edda;
  color: #155724;
  padding: 1rem;
  border: 1px solid #c3e6cb;
  border-radius: 4px;
  margin: 1rem 0;
  font-weight: 600;
}

.info {
  background: #d1ecf1;
  color: #0c5460;
  padding: 1rem;
  border: 1px solid #bee5eb;
  border-radius: 4px;
  margin: 1rem 0;
  font-weight: 600;
}

/* Loading spinner for better UX */
.loading::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-left: 10px;
  border: 3px solid var(--bg-secondary);
  border-radius: 50%;
  border-top-color: var(--link-color);
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading::after {
    animation: none;
    border-top-color: var(--link-color);
  }
}

/* Screen reader only content for better context */
.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;
}

/* Better button styles for accessibility */
button {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
  overflow: visible;
  text-transform: none;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Interactive elements minimum touch target size */
button,
.toc-content a,
.search-result-item[role="button"] {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toc-content a {
  justify-content: flex-start;
  padding: 12px;
}

/* Status announcements for screen readers */
[aria-live] {
  position: relative;
}

#search-status {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

/* Improved table styles if any tables are present */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}

th,
td {
  border: 1px solid var(--border-color);
  padding: 0.75rem;
  text-align: left;
}

th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
}

caption {
  padding: 0.75rem;
  font-weight: 600;
  text-align: left;
  caption-side: top;
}
