{% extends "base.html" %}

{% block title %}{{ t.dir_page_title }} - {{ config.APP_NAME }}{% endblock %}

{% block head %}
<meta name="description" content="{{ t.dir_page_meta_desc | tformat(count=total_suppliers, countries=total_countries) }}">
<meta property="og:title" content="{{ t.dir_page_title }} - {{ config.APP_NAME }}">
<meta property="og:description" content="{{ t.dir_page_og_desc | tformat(count=total_suppliers, countries=total_countries) }}">
<style>
  :root {
    --dir-green:      #15803D;
    --dir-green-mid:  #16a34a;
    --dir-green-dark: #0D5228;
    --dir-blue:       #1D4ED8;
    --dir-text-1:     #111827;
    --dir-text-2:     #6B7280;
    --dir-text-3:     #9CA3AF;
    --dir-card-bg:    #FFFFFF;
    --dir-card-bdr:   #E6E2D8;
    --dir-r:          16px;
    --dir-shadow:     0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.04);
    --dir-shadow-hov: 0 14px 36px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);
    --dir-shadow-pro: 0 14px 36px rgba(21,128,61,0.13), 0 2px 8px rgba(21,128,61,0.08);
  }

  .dir-hero { text-align: center; padding: 2rem 0 1.5rem; }
  .dir-hero h1 { font-size: 2rem; line-height: 1.3; }
  .dir-hero p { color: #64748B; margin-top: 0.5rem; }
  .dir-stats { display: flex; justify-content: center; gap: 2rem; margin-top: 1rem; font-size: 0.875rem; color: #64748B; }
  .dir-stats strong { color: #1E293B; }

  .dir-search { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
  .dir-search input[type="search"] {
    flex: 1; min-width: 200px; padding: 10px 14px; border: 1px solid #CBD5E1;
    border-radius: 12px; font-size: 0.875rem;
  }
  .dir-search input[type="search"]:focus { outline: none; border-color: #1D4ED8; box-shadow: 0 0 0 3px rgba(29,78,216,0.1); }
  .dir-search select {
    padding: 10px 12px; border: 1px solid #CBD5E1; border-radius: 12px;
    font-size: 0.8125rem; background: white; min-width: 140px;
  }
  .dir-search button[type="submit"] {
    padding: 10px 20px; background: #1D4ED8; color: white; border: none;
    border-radius: 12px; font-weight: 600; cursor: pointer; font-size: 0.875rem;
    box-shadow: 0 2px 10px rgba(29,78,216,0.25);
  }

  .dir-active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 1rem; }
  .dir-filter-tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; background: #EFF6FF; border: 1px solid #BFDBFE;
    border-radius: 999px; font-size: 0.75rem; color: #1D4ED8;
  }
  .dir-filter-tag a { color: #1D4ED8; text-decoration: none; font-weight: 700; }

  .dir-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem; margin-bottom: 2rem;
  }

  /* ---- Base card ---- */
  .dir-card {
    background: var(--dir-card-bg);
    border: 1px solid var(--dir-card-bdr);
    border-radius: var(--dir-r);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--dir-shadow);
  }
  .dir-card:hover { transform: translateY(-3px); box-shadow: var(--dir-shadow-hov); }

  /* ---- Cover media ---- */
  .dir-card__media {
    position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  }
  .dir-card__media img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    transition: transform 0.45s ease;
  }
  .dir-card:hover .dir-card__media img { transform: scale(1.04); }
  .dir-card__media::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(to bottom, transparent 45%, rgba(0,0,0,0.45) 100%);
    pointer-events: none; z-index: 2;
  }

  /* CSS court visualization (pro default placeholder) */
  .dir-card__media--court {
    background:
      radial-gradient(ellipse at 50% 20%, rgba(74,222,128,0.15) 0%, transparent 60%),
      linear-gradient(160deg, #1a5c30 0%, #2d7a45 35%, #1e6338 65%, #143d22 100%);
  }
  .dir-card__media--court .court-lines {
    position: absolute; inset: 0; z-index: 1;
    background-image:
      linear-gradient(transparent calc(49.5% - 1px), rgba(255,255,255,0.92) calc(49.5% - 1px), rgba(255,255,255,0.92) calc(50.5% + 1px), transparent calc(50.5% + 1px)),
      linear-gradient(transparent calc(8% - 0.5px), rgba(255,255,255,0.65) calc(8% - 0.5px), rgba(255,255,255,0.65) calc(8% + 0.75px), transparent calc(8% + 0.75px)),
      linear-gradient(transparent calc(92% - 0.5px), rgba(255,255,255,0.65) calc(92% - 0.5px), rgba(255,255,255,0.65) calc(92% + 0.75px), transparent calc(92% + 0.75px)),
      linear-gradient(90deg, transparent calc(10% - 0.5px), rgba(255,255,255,0.55) calc(10% - 0.5px), rgba(255,255,255,0.55) calc(10% + 0.75px), transparent calc(10% + 0.75px)),
      linear-gradient(90deg, transparent calc(90% - 0.5px), rgba(255,255,255,0.55) calc(90% - 0.5px), rgba(255,255,255,0.55) calc(90% + 0.75px), transparent calc(90% + 0.75px));
  }
  .dir-card__media--court .court-lines::before {
    content: ''; position: absolute; left: 10%; right: 10%; top: calc(50% - 1.5px); height: 3px;
    background-image: repeating-linear-gradient(90deg, rgba(255,255,255,0.18), rgba(255,255,255,0.18) 3px, transparent 3px, transparent 8px);
    z-index: 2;
  }
  .dir-card__media--court .court-lines::after {
    content: ''; position: absolute; inset: 0;
    background-image: repeating-linear-gradient(0deg, transparent, transparent 5px, rgba(0,0,0,0.015) 5px, rgba(0,0,0,0.015) 6px);
    z-index: 0;
  }

  /* Dark-green grid placeholder (paid tiers without cover photo) */
  .dir-card__media--placeholder {
    background: linear-gradient(135deg, #0f2218 0%, #1a3828 50%, #0d1e14 100%);
  }
  .dir-card__media--placeholder .ph-grid {
    position: absolute; inset: 0; z-index: 1;
    background-image:
      repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,0.04) 39px, rgba(255,255,255,0.04) 40px),
      repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.04) 39px, rgba(255,255,255,0.04) 40px);
  }
  .dir-card__media--placeholder .ph-label {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    z-index: 2; font-size: 1.625rem; font-weight: 800;
    color: rgba(255,255,255,0.07); letter-spacing: -0.02em; text-transform: uppercase;
  }
  /* Free tier placeholder — grey/desaturated */
  .dir-card--free .dir-card__media--placeholder {
    background: linear-gradient(135deg, #1f2937 0%, #374151 50%, #1f2937 100%);
  }

  /* Example card media */
  .dir-card__media--example {
    background: linear-gradient(135deg, #1e2e4a 0%, #2d4270 50%, #1a273e 100%);
    display: flex; align-items: center; justify-content: center;
  }
  .dir-card__media--example .example-icon {
    text-align: center; z-index: 3; position: relative;
  }
  .dir-card__media--example .example-icon svg { opacity: 0.25; }
  .dir-card__media--example .example-icon p {
    margin-top: 6px; font-size: 0.6875rem; font-weight: 600;
    color: rgba(255,255,255,0.25); letter-spacing: 0.04em;
  }

  /* ---- Overlays ---- */
  /* Category badge — frosted pill, top-right of media */
  .dir-card__cat {
    position: absolute; top: 10px; right: 10px; z-index: 5;
    font-size: 0.6375rem; font-weight: 700; letter-spacing: 0.03em;
    text-transform: uppercase; padding: 3.5px 9px; border-radius: 5px;
    backdrop-filter: blur(8px) saturate(180%); -webkit-backdrop-filter: blur(8px) saturate(180%);
    white-space: nowrap;
  }
  .dir-card__cat--manufacturer { background: rgba(219,234,254,0.92); color: #1e40af; }
  .dir-card__cat--turnkey      { background: rgba(220,252,231,0.92); color: #065f46; }
  .dir-card__cat--turf         { background: rgba(254,243,199,0.92); color: #78350f; }
  .dir-card__cat--lighting     { background: rgba(254,226,226,0.92); color: #991b1b; }
  .dir-card__cat--software     { background: rgba(237,233,254,0.92); color: #4c1d95; }
  .dir-card__cat--hall_builder { background: rgba(255,237,213,0.92); color: #7c2d12; }
  .dir-card__cat--consultant   { background: rgba(240,253,250,0.92); color: #134e4a; }
  .dir-card__cat--franchise    { background: rgba(252,231,243,0.92); color: #831843; }
  .dir-card__cat--example      { background: rgba(219,234,254,0.85); color: #1e40af; }

  /* Featured ribbon — top-left */
  .dir-card__featured {
    position: absolute; top: 10px; left: 10px; z-index: 5;
    background: var(--dir-blue); color: white;
    font-size: 0.5875rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; padding: 3.5px 9px; border-radius: 5px;
    box-shadow: 0 2px 8px rgba(29,78,216,0.35);
  }

  /* Logo avatar — body-relative so it straddles the media/body border */
  .dir-card__logo-wrap {
    position: absolute; top: -22px; left: 14px; z-index: 6;
  }
  .dir-card__logo,
  .dir-card__logo-ph {
    width: 44px; height: 44px; border-radius: 10px;
    border: 2.5px solid white; box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    display: flex; align-items: center; justify-content: center;
  }
  .dir-card__logo { object-fit: contain; background: white; }
  .dir-card__logo-ph {
    background: #EFF6FF; color: var(--dir-blue);
    font-size: 0.875rem; font-weight: 800; letter-spacing: -0.01em;
  }

  /* ---- Card body ---- */
  .dir-card__body {
    position: relative;
    padding: 30px 16px 16px; /* 30px top = logo overhang room */
  }
  .dir-card__name {
    font-size: 0.9375rem; font-weight: 700; color: var(--dir-text-1);
    line-height: 1.25; letter-spacing: -0.01em;
  }
  .dir-card__loc {
    display: flex; align-items: center; gap: 3px;
    font-size: 0.75rem; color: var(--dir-text-2); margin-top: 3px;
  }
  .dir-card__loc svg { flex-shrink: 0; }
  .dir-card__stats {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    margin-top: 10px; padding-top: 10px; border-top: 1px solid #F1F5F9;
  }
  .dir-card__stat {
    display: flex; align-items: center; gap: 3.5px;
    font-size: 0.6875rem; font-weight: 600; color: var(--dir-text-2); white-space: nowrap;
  }
  .dir-card__stat svg { flex-shrink: 0; color: var(--dir-text-3); }
  .dir-card__stat--verified { color: var(--dir-green); }
  .dir-card__stat--verified svg { color: var(--dir-green); }
  .dir-card__tier-chip {
    font-size: 0.5875rem; font-weight: 700; letter-spacing: 0.05em;
    text-transform: uppercase; padding: 2.5px 7px; border-radius: 4px;
  }
  .dir-card__tier-chip--growth     { background: #EFF6FF; color: #1e40af; }
  .dir-card__tier-chip--unverified { background: #F9FAFB; color: var(--dir-text-3); }
  .dir-card__desc {
    font-size: 0.8125rem; color: var(--dir-text-2); line-height: 1.55; margin-top: 8px;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  .dir-card__foot {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 12px; padding-top: 12px; border-top: 1px solid #F1F5F9;
  }
  .dir-card__web {
    font-size: 0.75rem; color: var(--dir-text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px;
  }
  .dir-card__action {
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.01em;
    white-space: nowrap; flex-shrink: 0;
  }
  .dir-card__action--quote   { color: var(--dir-green); }
  .dir-card__action--claim   { color: var(--dir-text-3); }
  .dir-card__action--example { color: var(--dir-blue); }

  /* ---- Tier variants ---- */
  /* PRO — green top line + subtle green glow */
  .dir-card--pro::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2.5px;
    background: linear-gradient(90deg, var(--dir-green-dark), var(--dir-green-mid));
    z-index: 7; border-radius: var(--dir-r) var(--dir-r) 0 0;
  }
  .dir-card--pro {
    box-shadow: 0 1px 3px rgba(21,128,61,0.06), 0 1px 2px rgba(0,0,0,0.04);
  }
  .dir-card--pro:hover { box-shadow: var(--dir-shadow-pro); }

  /* HIGHLIGHT — green ring (boost add-on) */
  .dir-card--highlight {
    box-shadow: 0 0 0 2px rgba(21,128,61,0.2), 0 6px 24px rgba(21,128,61,0.1);
  }
  .dir-card--highlight:hover {
    box-shadow: 0 0 0 2px rgba(21,128,61,0.3), var(--dir-shadow-pro);
  }

  /* FREE — muted */
  .dir-card--free { opacity: 0.62; }
  .dir-card--free:hover {
    opacity: 0.82; transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  }

  /* EXAMPLE — dashed CTA card */
  .dir-card--example { border: 2px dashed #93C5FD; background: #F0F7FF; }
  .dir-card--example::before { display: none; }

  .dir-pagination { display: flex; justify-content: center; gap: 4px; margin: 2rem 0; }
  .dir-pagination a, .dir-pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 10px; font-size: 0.8125rem;
    text-decoration: none; border: 1px solid #E2E8F0; color: #475569;
  }
  .dir-pagination span.current { background: #1D4ED8; color: white; border-color: #1D4ED8; }
  .dir-pagination a:hover { background: #F1F5F9; }

  .dir-empty { text-align: center; padding: 3rem 1rem; color: #64748B; }
  .dir-empty h3 { color: #1E293B; margin-bottom: 0.5rem; }

  @media (max-width: 640px) {
    .dir-search { flex-direction: column; }
    .dir-grid { grid-template-columns: 1fr; }
    .dir-stats { flex-direction: column; gap: 0.25rem; align-items: center; }
  }
</style>
{% endblock %}

{% block content %}
<main class="container-page">
  <div class="dir-hero">
    <h1>{{ t.dir_heading }}</h1>
    <p>{{ t.dir_subheading | tformat(n=total_suppliers, c=total_countries) }}</p>
    <div class="dir-stats">
      <span><strong>{{ total_suppliers }}</strong> {{ t.dir_stat_suppliers }}</span>
      <span><strong>{{ total_countries }}</strong> {{ t.dir_stat_countries }}</span>
      <span><strong>{{ category_counts | length }}</strong> {{ t.dir_stat_categories }}</span>
    </div>
  </div>

  <!-- Search + Filters -->
  <form method="get" class="dir-search" id="dir-search-form">
    <input type="search" name="q" value="{{ q }}" placeholder="{{ t.dir_search_placeholder }}"
           hx-get="{{ url_for('directory.results') }}"
           hx-trigger="input changed delay:300ms"
           hx-target="#dir-results"
           hx-include="#dir-search-form">
    <select name="country"
            hx-get="{{ url_for('directory.results') }}"
            hx-trigger="change"
            hx-target="#dir-results"
            hx-include="#dir-search-form">
      <option value="">{{ t.dir_filter_all_countries }}</option>
      {% for cc in country_counts %}
      <option value="{{ cc.country_code }}" {{ 'selected' if country == cc.country_code }}>{{ country_labels.get(cc.country_code, cc.country_code) }} ({{ cc.cnt }})</option>
      {% endfor %}
    </select>
    <select name="category"
            hx-get="{{ url_for('directory.results') }}"
            hx-trigger="change"
            hx-target="#dir-results"
            hx-include="#dir-search-form">
      <option value="">{{ t.dir_filter_all_categories }}</option>
      {% for cat in category_counts %}
      <option value="{{ cat.category }}" {{ 'selected' if category == cat.category }}>{{ category_labels.get(cat.category, cat.category) }} ({{ cat.cnt }})</option>
      {% endfor %}
    </select>
    {% if region %}<input type="hidden" name="region" value="{{ region }}">{% endif %}
    <button type="submit">{{ t.dir_search_btn }}</button>
  </form>

  <!-- Active filters -->
  {% if q or country or category or region %}
  <div class="dir-active-filters">
    {% if q %}<span class="dir-filter-tag">Search: "{{ q }}" <a href="{{ request.path }}?{{ request.query_string.decode().replace('q=' + q, 'q=') }}">&times;</a></span>{% endif %}
    {% if country %}<span class="dir-filter-tag">{{ country_labels.get(country, country) }} <a href="{{ request.path }}?q={{ q }}&category={{ category }}">&times;</a></span>{% endif %}
    {% if category %}<span class="dir-filter-tag">{{ category_labels.get(category, category) }} <a href="{{ request.path }}?q={{ q }}&country={{ country }}">&times;</a></span>{% endif %}
    <a href="{{ request.path }}" style="font-size:0.75rem;color:#64748B;text-decoration:none;padding:4px 8px">{{ t.dir_filter_clear }}</a>
  </div>
  {% endif %}

  <!-- Results (swappable via HTMX) -->
  <div id="dir-results">
    {% include "partials/results.html" %}
  </div>

  <!-- Supplier CTA -->
  <section style="text-align:center;padding:2rem 0;border-top:1px solid #E2E8F0;margin-top:1rem">
    <h2 style="font-size:1.25rem;margin-bottom:0.5rem">{{ t.dir_cta_heading }}</h2>
    <p style="color:#64748B;font-size:0.875rem;margin-bottom:1rem">{{ t.dir_cta_subheading }}</p>
    <a href="{{ url_for('public.suppliers') }}" class="btn">{{ t.dir_cta_btn }}</a>
  </section>
</main>
{% endblock %}
