/**
 * Hugging Face Model Explorer - Design System & Responsive Styles
 * WCAG AAA compliant, system-theme aware, and zero layout shift (CLS).
 */

:root {
  --hf-bg: #0f172a;
  --hf-surface: #1e293b;
  --hf-surface-hover: #334155;
  --hf-border: #334155;
  --hf-border-focus: #38bdf8;
  --hf-text: #f8fafc;
  --hf-text-muted: #94a3b8;
  --hf-primary: #38bdf8;
  --hf-primary-hover: #0ea5e9;
  --hf-accent: #f59e0b;
  --hf-badge-task: #1e3a8a;
  --hf-badge-task-text: #93c5fd;
  --hf-badge-lib: #14532d;
  --hf-badge-lib-text: #86efac;
  --hf-badge-license: #4c1d95;
  --hf-badge-license-text: #d8b4fe;
  --hf-error-bg: #450a0a;
  --hf-error-border: #991b1b;
  --hf-error-text: #fca5a5;
  --hf-radius-sm: 6px;
  --hf-radius-md: 10px;
  --hf-radius-lg: 16px;
  --hf-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --hf-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --hf-bg: #f8fafc;
    --hf-surface: #ffffff;
    --hf-surface-hover: #f1f5f9;
    --hf-border: #cbd5e1;
    --hf-border-focus: #0369a1;
    --hf-text: #0f172a;
    --hf-text-muted: #475569;
    --hf-primary: #0369a1;
    --hf-primary-hover: #075985;
    --hf-accent: #d97706;
    --hf-badge-task: #dbeafe;
    --hf-badge-task-text: #1e40af;
    --hf-badge-lib: #dcfce7;
    --hf-badge-lib-text: #166534;
    --hf-badge-license: #f3e8ff;
    --hf-badge-license-text: #6b21a8;
    --hf-error-bg: #fef2f2;
    --hf-error-border: #f87171;
    --hf-error-text: #991b1b;
  }
}

hf-model-explorer {
  display: block;
  font-family: var(--hf-font);
  color: var(--hf-text);
  margin: 1.5rem 0 3rem;
  line-height: 1.5;
  min-height: 800px;
}

.explorer-app-shell {
  min-height: 800px;
}

.explorer-main {
  min-height: 540px;
}

/* App Header */
.explorer-header {
  margin-bottom: 2rem;
}

.explorer-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  color: var(--hf-primary);
  margin-bottom: 0.75rem;
}

.explorer-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin: 0 0 0.5rem;
  color: var(--hf-text);
  text-wrap: balance;
}

.explorer-lead {
  font-size: 1.05rem;
  color: var(--hf-text-muted);
  max-width: 65ch;
  margin: 0;
}

/* Search Bar */
.search-bar-container {
  margin-bottom: 1.25rem;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--hf-text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.85rem 3rem 0.85rem 2.75rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--hf-text);
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-md);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  border-color: var(--hf-border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.btn-clear-search {
  position: absolute;
  right: 1rem;
  background: transparent;
  border: none;
  color: var(--hf-text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--hf-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-clear-search:hover {
  color: var(--hf-text);
}

/* Filters Bar */
.filters-bar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.15rem;
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-md);
  margin-bottom: 2rem;
}

.filters-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filters-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hf-text-muted);
  min-width: 60px;
}

.pills-scroll-container {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 0.35rem 0.75rem;
  font-size: 0.825rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: 9999px;
  background: transparent;
  border: 1px solid var(--hf-border);
  color: var(--hf-text-muted);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}

.filter-pill:hover {
  background: var(--hf-surface-hover);
  color: var(--hf-text);
}

.filter-pill.active {
  background: var(--hf-primary);
  border-color: var(--hf-primary);
  color: #ffffff;
  font-weight: 600;
}

.sort-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sort-select {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--hf-bg);
  color: var(--hf-text);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  outline: none;
  cursor: pointer;
}

.sort-select:focus {
  border-color: var(--hf-border-focus);
}

/* Results Grid */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.results-count {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--hf-text-muted);
}

.models-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

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

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

/* Model Card */
.model-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 180px;
}

.model-card:hover {
  transform: translateY(-2px);
  border-color: var(--hf-border-focus);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.model-card:focus-visible {
  outline: 3px solid var(--hf-border-focus);
  outline-offset: 2px;
}

.model-card-header {
  margin-bottom: 0.75rem;
}

.model-author {
  font-size: 0.8rem;
  color: var(--hf-text-muted);
  display: block;
  margin-bottom: 0.2rem;
}

.model-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  color: var(--hf-text);
  word-break: break-word;
}

.model-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--hf-radius-sm);
  display: inline-block;
}

.badge-task {
  background: var(--hf-badge-task);
  color: var(--hf-badge-task-text);
}

.badge-library {
  background: var(--hf-badge-lib);
  color: var(--hf-badge-lib-text);
}

.badge-license {
  background: var(--hf-badge-license);
  color: var(--hf-badge-license-text);
}

.model-card-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--hf-border);
  font-size: 0.825rem;
  color: var(--hf-text-muted);
}

.model-stat {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Skeletons & Zero CLS */
.skeleton-card {
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-md);
  padding: 1.25rem;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.skeleton-line {
  background: var(--hf-border);
  border-radius: var(--hf-radius-sm);
  animation: hf-pulse 1.6s ease-in-out infinite;
}

.skeleton-author {
  width: 35%;
  height: 12px;
  margin-bottom: 0.5rem;
}

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

.skeleton-badges {
  display: flex;
  gap: 0.5rem;
}

.skeleton-badge {
  width: 60px;
  height: 18px;
  background: var(--hf-border);
  border-radius: var(--hf-radius-sm);
  animation: hf-pulse 1.6s ease-in-out infinite;
}

.skeleton-meta {
  width: 50%;
  height: 14px;
  margin-top: 1rem;
}

@keyframes hf-pulse {

  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 0.85;
  }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  background: var(--hf-surface);
  border: 1px dashed var(--hf-border);
  border-radius: var(--hf-radius-md);
}

.empty-state-icon {
  color: var(--hf-text-muted);
  margin-bottom: 1rem;
}

.empty-state-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.empty-state-text {
  color: var(--hf-text-muted);
  max-width: 45ch;
  margin: 0 auto 1.5rem;
}

/* Error State */
.error-state {
  padding: 2rem 1.5rem;
  background: var(--hf-error-bg);
  border: 1px solid var(--hf-error-border);
  border-radius: var(--hf-radius-md);
  text-align: center;
  margin: 1rem 0;
}

.error-state-icon {
  color: var(--hf-error-border);
  margin-bottom: 0.75rem;
}

.error-state-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--hf-error-text);
  margin: 0 0 0.5rem;
}

.error-state-text {
  color: var(--hf-error-text);
  max-width: 50ch;
  margin: 0 auto 0.75rem;
}

.error-state-hint {
  font-size: 0.85rem;
  color: var(--hf-text-muted);
  margin-bottom: 1.25rem;
}

/* Action Buttons */
.btn-action {
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--hf-radius-sm);
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;
}

.btn-clear-filters {
  background: var(--hf-surface-hover);
  color: var(--hf-text);
  border: 1px solid var(--hf-border);
}

.btn-clear-filters:hover {
  background: var(--hf-border);
}

.btn-retry {
  background: var(--hf-primary);
  color: #ffffff;
}

.btn-retry:hover {
  background: var(--hf-primary-hover);
}

/* Idle / Welcome State */
.idle-state {
  background: var(--hf-surface);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-md);
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.idle-state-header h3 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.idle-state-header p {
  color: var(--hf-text-muted);
  margin: 0 0 1.25rem;
}

.suggested-queries {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-suggested {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  color: var(--hf-primary);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-suggested:hover {
  background: var(--hf-surface-hover);
  border-color: var(--hf-primary);
}

/* Details View & Modal Dialog (Google Chrome Modern Web Guidance) */
dialog.model-details-dialog {
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-lg);
  background: var(--hf-surface);
  color: var(--hf-text);
  max-width: 840px;
  width: 92vw;
  max-height: 88vh;
  padding: 0;
  margin: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  overflow-y: auto;
  box-sizing: border-box;
}

dialog.model-details-dialog::backdrop {
  background-color: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
}

.model-details-view {
  background: var(--hf-surface);
  padding: 1.75rem;
  box-sizing: border-box;
}

.details-skeleton {
  pointer-events: none;
}

.details-skeleton .btn-back,
.details-skeleton .btn-close-modal {
  pointer-events: auto;
}

.skeleton-telemetry {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.details-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.dialog-close-form {
  margin: 0;
  display: inline-flex;
}

.btn-close-modal {
  background: transparent;
  border: 1px solid var(--hf-border);
  color: var(--hf-text-muted);
  font-size: 1.5rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: var(--hf-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-close-modal:hover {
  background: var(--hf-surface-hover);
  color: var(--hf-text);
  border-color: var(--hf-border-focus);
}

.btn-back {
  background: transparent;
  border: 1px solid var(--hf-border);
  color: var(--hf-text);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--hf-radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

/* Mobile full-screen bottom sheet adaptation */
@media (max-width: 640px) {
  dialog.model-details-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
    border: none;
  }
}

.btn-back:hover {
  background: var(--hf-surface-hover);
}

.details-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.details-author {
  font-size: 0.9rem;
  color: var(--hf-text-muted);
  font-weight: 500;
}

.details-title {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0.2rem 0 0;
  outline: none;
}

.hf-external-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--hf-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.hf-external-link:hover {
  text-decoration: underline;
}

.details-telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.telemetry-card {
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  padding: 1rem;
}

.telemetry-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--hf-text-muted);
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.35rem;
}

.telemetry-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.details-section {
  margin-bottom: 2rem;
}

.section-subtitle {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.85rem;
}

.snippet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.btn-copy {
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.35rem 0.75rem;
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  color: var(--hf-text);
  border-radius: var(--hf-radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-copy:hover {
  background: var(--hf-surface-hover);
}

.btn-copy.copied {
  background: #14532d;
  color: #86efac;
  border-color: #22c55e;
}

.snippet-code {
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  padding: 1.25rem;
  font-family: var(--hf-font-mono);
  font-size: 0.9rem;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

.spaces-list {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.space-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  border-radius: 9999px;
  font-size: 0.825rem;
  color: var(--hf-primary);
  text-decoration: none;
  transition: all 0.15s;
}

.space-badge:hover {
  background: var(--hf-surface-hover);
  border-color: var(--hf-primary);
}

.files-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  divide-y: 1px solid var(--hf-border);
}

.file-item {
  display: flex;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--hf-border);
}

.file-item:last-child {
  border-bottom: none;
}

.file-name {
  font-family: var(--hf-font-mono);
}

.file-size {
  color: var(--hf-text-muted);
}

.file-more {
  padding: 0.65rem 1rem;
  font-size: 0.8rem;
  color: var(--hf-text-muted);
  font-style: italic;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}