/* ============================================
   SVG Scraper — Styles
   ============================================ */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e5e5;
  --border-hover: #ccc;
  --text: #1a1a1a;
  --text-muted: #717171;
  --text-light: #999;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --checkerboard: conic-gradient(#e8e8e8 25%, transparent 25%, transparent 50%, #e8e8e8 50%, #e8e8e8 75%, transparent 75%);
  --max-width: 1200px;
}

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

/* Ensure hidden attribute works even with explicit display rules */
[hidden] {
  display: none !important;
}

/* Screen-reader only */
.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;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* Header
   ---------------------------------------- */

.header {
  text-align: center;
  padding: 64px 0 16px;
}

.header h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.subtitle {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Search
   ---------------------------------------- */

.search-section {
  max-width: 640px;
  margin: 24px auto 48px;
}

.search-bar {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.search-bar:focus-within {
  border-color: var(--accent);
}

#url-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 16px;
  font-family: inherit;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
}

#url-input::placeholder {
  color: var(--text-light);
}

#scrape-btn {
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

#scrape-btn:hover {
  background: var(--accent-hover);
}

#scrape-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-msg {
  text-align: center;
  color: #dc2626;
  font-size: 14px;
  margin-top: 12px;
}

/* Loading
   ---------------------------------------- */

.loading {
  text-align: center;
  padding: 48px 0;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.7s linear infinite;
}

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

.loading p {
  color: var(--text-muted);
  font-size: 14px;
}

/* Results Header
   ---------------------------------------- */

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.results-meta h2 {
  font-size: 20px;
  font-weight: 600;
}

.fetch-time {
  font-size: 13px;
  color: var(--text-light);
}

.results-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Buttons
   ---------------------------------------- */

.btn-primary {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-secondary {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

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

/* Filters
   ---------------------------------------- */

.filters-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 4px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-pill:hover {
  border-color: var(--border-hover);
}

.filter-pill.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

#sort-select {
  padding: 5px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.search-filter input {
  padding: 5px 12px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 180px;
}

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

/* SVG Grid
   ---------------------------------------- */

.svg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.svg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.svg-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.svg-card:hover .card-actions {
  opacity: 1;
}

.card-preview {
  position: relative;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-image: var(--checkerboard);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

.card-preview svg,
.card-preview img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.card-action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}

.card-action-btn:hover {
  background: #fff;
}

.card-info {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.card-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.source-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 4px;
}

.meta-text {
  font-size: 12px;
  color: var(--text-light);
}

/* No results */

.no-results,
.empty-state {
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

/* Modal
   ---------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 1;
  transition: background 0.1s;
  color: var(--text);
  line-height: 1;
}

.modal-close:hover {
  background: var(--border);
}

.modal-preview {
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.modal-preview .checkerboard {
  background-image: var(--checkerboard);
  background-size: 16px 16px;
  padding: 24px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

.modal-preview .checkerboard svg {
  max-width: 400px;
  max-height: 300px;
  width: auto;
  height: auto;
}

.modal-info {
  padding: 0 32px 32px;
}

.modal-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.modal-code-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.modal-code-wrap pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
}

.modal-code-wrap code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

/* Info section
   ---------------------------------------- */

.info-section {
  margin-top: 80px;
  padding: 48px 0;
  border-top: 1px solid var(--border);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40px;
}

.info-grid h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.info-grid p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* Footer
   ---------------------------------------- */

.footer {
  text-align: center;
  padding: 32px 0;
  font-size: 13px;
  color: var(--text-light);
}

.footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer a:hover {
  color: var(--text);
}

/* Toast
   ---------------------------------------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  transition: all 0.2s;
  z-index: 2000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Density toggle
   ---------------------------------------- */

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.svg-grid.compact {
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.svg-grid.compact .card-preview {
  height: 90px;
  padding: 10px;
}

.svg-grid.compact .card-info {
  padding: 6px 8px;
}

.svg-grid.compact .source-badge {
  font-size: 10px;
  padding: 1px 6px;
}

.svg-grid.compact .meta-text {
  font-size: 11px;
}

/* Try URL buttons in empty state */

.empty-hint {
  margin-top: 12px;
}

.try-url {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  text-decoration: underline;
  padding: 0;
}

.try-url:hover {
  color: var(--accent-hover);
}

/* Sticky search when scrolled */

.search-section.sticky {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding: 12px 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

/* Focus styles
   ---------------------------------------- */

.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.filter-pill:focus-visible,
.card-action-btn:focus-visible,
.modal-close:focus-visible,
#sort-select:focus-visible,
.search-filter input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Responsive
   ---------------------------------------- */

@media (max-width: 1024px) {
  .svg-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .svg-grid.compact {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .header {
    padding: 40px 0 12px;
  }

  .header h1 {
    font-size: 26px;
  }

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

  .svg-grid.compact {
    grid-template-columns: repeat(3, 1fr);
  }

  .info-grid {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .results-header {
    flex-direction: column;
  }

  .results-actions {
    width: 100%;
  }

  .results-actions .btn-secondary {
    flex: 1;
  }

  .filters-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-filter input {
    width: 100%;
  }

  .modal {
    padding: 0;
  }

  .modal-content {
    border-radius: 0;
    max-height: 100vh;
    height: 100%;
  }

  .modal-preview {
    padding: 24px 16px;
  }

  .modal-info {
    padding: 0 16px 24px;
  }
}

@media (max-width: 480px) {
  .search-bar {
    flex-direction: column;
  }

  #scrape-btn {
    border-top: 1px solid var(--border);
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }
}
