/* ============================================================
   AI Tools Directory — styles.css
   ============================================================ */

/* ---------- Google Font ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- Design Tokens ---------- */
:root {
  /* Brand */
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #e0e7ff;

  /* Pricing badge colours */
  --badge-free: #10b981;
  --badge-freemium: #f59e0b;
  --badge-paid: #ef4444;

  /* Light mode */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #64748b;
  --shadow: 0 4px 24px rgba(0, 0, 0, .08);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, .14);

  /* Spacing & shape */
  --radius-sm: 6px;
  --radius: 14px;
  --radius-lg: 22px;
  --transition: .2s ease;
}

/* ---------- Dark mode ---------- */
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #263348;
  --border: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --shadow: 0 4px 24px rgba(0, 0, 0, .4);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, .6);
  --accent-light: #312e81;
}

/* ---------- Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  z-index: 9999;
  transition: top .2s;
  font-size: .875rem;
  font-weight: 600;
}

.skip-link:focus {
  top: 8px;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  color: #fff;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(99, 102, 241, .4);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  gap: 1rem;
}

.header-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-brand h1 {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 800;
  letter-spacing: -.02em;
  color: #fff;
}

.header-subtitle {
  font-size: .75rem;
  color: rgba(255, 255, 255, .8);
  font-weight: 400;
}

/* Theme toggle button */
#themeToggle {
  background: rgba(255, 255, 255, .15);
  border: 1.5px solid rgba(255, 255, 255, .3);
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

#themeToggle:hover {
  background: rgba(255, 255, 255, .3);
  transform: rotate(15deg);
}

#themeToggle:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

/* ---------- Hero / Controls Section ---------- */
.controls-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
  transition: background var(--transition);
}

.controls-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Search bar */
.search-wrapper {
  position: relative;
  flex: 1;
}

.search-wrapper svg {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: .75rem 1rem .75rem 2.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  font-family: inherit;
}

#searchInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .2);
}

#searchInput::placeholder {
  color: var(--text-secondary);
}

/* Filter row */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex: 1;
  min-width: 140px;
}

.filter-group label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-secondary);
}

select {
  padding: .6rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2.25rem;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .2);
}

/* Results summary & clear */
.results-bar {
  max-width: 1280px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}

#resultsCount {
  font-size: .875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

#clearFilters {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: .35rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 600;
  transition: all var(--transition);
}

#clearFilters:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

#clearFilters:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Main Content ---------- */
main {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem 1.5rem 3rem;
}

/* ---------- Grid ---------- */
#toolsGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

/* ---------- Tool Card ---------- */
.tool-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition),
    border-color var(--transition), background var(--transition);
  position: relative;
  overflow: hidden;
}

.tool-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent) 0%, transparent 100%);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.tool-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.tool-card:hover::before {
  opacity: .04;
}

.tool-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Card header */
.card-header {
  display: flex;
  align-items: center;
  gap: .85rem;
}

.card-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--border);
}

.card-title-block {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-category {
  font-size: .75rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 1px;
}

/* Pricing badge */
.pricing-badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.pricing-badge.free {
  background: #d1fae5;
  color: #065f46;
}

.pricing-badge.freemium {
  background: #fef3c7;
  color: #92400e;
}

.pricing-badge.paid {
  background: #fee2e2;
  color: #991b1b;
}

[data-theme="dark"] .pricing-badge.free {
  background: #064e3b;
  color: #6ee7b7;
}

[data-theme="dark"] .pricing-badge.freemium {
  background: #451a03;
  color: #fcd34d;
}

[data-theme="dark"] .pricing-badge.paid {
  background: #450a0a;
  color: #fca5a5;
}

/* Card description */
.card-description {
  font-size: .875rem;
  color: var(--text-secondary);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Tags */
.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.tag {
  background: var(--accent-light);
  color: var(--accent);
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .55rem;
  border-radius: 999px;
  transition: background var(--transition);
}

[data-theme="dark"] .tag {
  color: #c4b5fd;
}

/* Visit button */
.visit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: .55rem 1rem;
  font-size: .85rem;
  font-weight: 600;
  width: 100%;
  transition: background var(--transition), transform var(--transition);
  margin-top: auto;
}

.visit-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.visit-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- Empty State ---------- */
#emptyState {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--text-secondary);
  text-align: center;
}

#emptyState.visible {
  display: flex;
}

#emptyState svg {
  opacity: .35;
}

#emptyState h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

#emptyState p {
  font-size: .9rem;
  max-width: 320px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
  transform: translateY(20px) scale(.97);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
  position: relative;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--surface-hover);
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-close:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-right: 2rem;
}

.modal-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: contain;
  background: var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.2;
}

.modal-category {
  font-size: .85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.modal-meta {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.modal-description {
  font-size: .95rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 1.25rem;
}

.modal-section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-secondary);
  margin-bottom: .5rem;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1.5rem;
}

.modal-visit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .75rem 1.5rem;
  font-size: .95rem;
  font-weight: 700;
  width: 100%;
  transition: background var(--transition), transform var(--transition);
}

.modal-visit-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.modal-visit-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- Loading Spinner ---------- */
.spinner-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  grid-column: 1 / -1;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Footer ---------- */
.footer-top {
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.footer-top a {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--accent);
  text-decoration: none;
  font-size: .95rem;
  transition: opacity var(--transition);
}

.footer-top a:hover {
  opacity: .75;
  text-decoration: none;
}

.footer-top a strong {
  font-weight: 800;
}

footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 2.5rem 1.5rem 1.5rem;
  transition: background var(--transition);
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
}

.footer-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
}

.footer-col h3 {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-secondary);
  margin-bottom: .75rem;
}

.deploy-steps {
  list-style: none;
  counter-reset: step-counter;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.deploy-steps li {
  counter-increment: step-counter;
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  font-size: .82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.deploy-steps li::before {
  content: counter(step-counter);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  font-size: .7rem;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: .15rem;
  flex-shrink: 0;
}

.cache-note {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .8rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.cache-note strong {
  color: var(--text);
}

.footer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  font-size: .8rem;
  color: var(--text-secondary);
}

.footer-badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--accent-light);
  color: var(--accent);
  padding: .25rem .6rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .75rem;
}

/* ---------- Utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .footer-main {
    grid-template-columns: 1fr;
  }

  #toolsGrid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  .header-inner {
    height: 60px;
  }

  .controls-section {
    padding: 1rem;
  }

  main {
    padding: 1rem 1rem 2rem;
  }

  .filter-row {
    flex-direction: column;
  }

  .filter-group {
    min-width: unset;
    width: 100%;
  }

  select {
    width: 100%;
  }
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-card {
  animation: fadeInUp .3s ease both;
}