<?php
include "config.php";
$stmt = $dbh->prepare("SELECT * FROM brokers LIMIT 6");
$stmt->execute();
$brokers = $stmt->fetchAll(PDO::FETCH_ASSOC);
$index = 0;
?>

<style>
  /* Main Container Display Logic */
  #rd {
    display: none;
    margin-bottom: 60px;
  }

  @media (max-width: 768px) {
    #rd {
      display: block;
    }
  }

  /* Horizontal Scroll Container */
  .ea-vsp-container {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    background: #f9f9f9;
    padding: 16px;
    gap: 16px;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;

    /* Hide scrollbar - cross-browser */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
  }

  .ea-vsp-container::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, Opera */
  }

  /* Card Wrapper Styles */
  .ea-cadr-wrapper {
    position: relative;
    flex: 0 0 auto;
    width: 200px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    scroll-snap-align: start;
    cursor: pointer;
  }

  .ea-cadr-wrapper:hover {
    z-index: 10;
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  }

  .ea-cadr-tag {
    position: absolute;
    top: 0;
    left: 0;
    background: #c49b5f;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-bottom-right-radius: 8px;
    z-index: 1;
  }

  .ea-cadr-content {
    padding: 18px 16px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .ea-cadr-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 12px;
  }

  .ea-cadr-title {
    font-size: 14px;
    font-weight: bold;
    color: #1d2129;
    margin-bottom: 8px;
    text-align: center;
  }

  .ea-cadr-specs {
    font-size: 12px;
    color: #86909c;
    text-align: center;
    line-height: 1.4;
    margin-bottom: 14px;
  }

  /* Button Styles */
  .ea-cadr-btn {
    display: inline-block;
    padding: 5px 6px;
    border-radius: 4px;
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    width: 70%;
  }

  .btn-fee {
    background: #3b76f6;
    color: white;
  }

  .btn-ultar {
    background: #ff6a00;
    color: white;
  }

  .btn-por {
    background: #1a1a2e;
    color: white;
  }

  /* Responsive Styles */
  /* ===== TABLET BREAKPOINT (max-width: 1100px) ===== */
  @media (max-width: 1100px) {
    #rd {
      margin-bottom: 50px;
    }

    .ea-vsp-container {
      padding: 14px;
      gap: 14px;
    }

    .ea-cadr-wrapper {
      width: 190px;
    }

    .ea-cadr-logo {
      width: 44px;
      height: 44px;
    }

    .ea-cadr-title {
      font-size: 13px;
      margin-bottom: 6px;
    }

    .ea-cadr-specs {
      font-size: 11px;
      margin-bottom: 10px;
    }

    .ea-cadr-btn {
      font-size: 9px;
      padding: 4px 8px;
    }
  }

  /* ===== MOBILE BREAKPOINT (max-width: 768px) ===== */
  @media (max-width: 768px) {
    #rd {
      display: block;
      margin-bottom: 40px;
    }

    .ea-vsp-container {
      padding: 12px;
      gap: 12px;
      background: #fafafa;
    }

    .ea-cadr-wrapper {
      width: 180px;
      transform: none !important;
      box-shadow: none;
      border-radius: 6px;
    }

    .ea-cadr-wrapper:hover {
      transform: none;
      z-index: auto;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .ea-cadr-tag {
      font-size: 10px;
      padding: 3px 8px;
    }

    .ea-cadr-content {
      padding: 14px 12px 12px;
    }

    .ea-cadr-logo {
      width: 40px;
      height: 40px;
      margin-bottom: 8px;
    }

    .ea-cadr-title {
      font-size: 12px;
      margin-bottom: 6px;
    }

    .ea-cadr-specs {
      font-size: 10px;
      margin-bottom: 10px;
      line-height: 1.3;
    }

    .ea-cadr-btn {
      font-size: 9px;
      padding: 6px 8px;
    }
  }

  /* ===== SMALL MOBILE BREAKPOINT (max-width: 480px) ===== */
  @media (max-width: 480px) {
    #rd {
      margin-bottom: 30px;
    }

    .ea-vsp-container {
      padding: 8px;
      gap: 8px;
      background: #fff;
      -webkit-overflow-scrolling: touch;
    }

    .ea-cadr-wrapper {
      width: calc(100vw - 48px);
      min-width: 160px;
      border-radius: 6px;
      border: 1px solid #f0f0f0;
    }

    .ea-cadr-wrapper:hover {
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .ea-cadr-tag {
      font-size: 9px;
      padding: 2px 6px;
    }

    .ea-cadr-content {
      padding: 10px 8px 8px;
    }

    .ea-cadr-logo {
      width: 36px;
      height: 36px;
      margin-bottom: 6px;
    }

    .ea-cadr-title {
      font-size: 11px;
      margin-bottom: 4px;
    }

    .ea-cadr-specs {
      font-size: 9px;
      margin-bottom: 8px;
      line-height: 1.2;
    }

    .ea-cadr-btn {
      font-size: 8px;
      padding: 4px 6px;
    }
  }

</style>

<div id="rd">
  <div class="main-content">
    <div class="ea-vsp-container">
      <?php foreach ($brokers as $broker):
        if ($index === 0) {
          $tag = 'EA VPS';
          $btnLabel = 'Open for free';
          $btnClass = 'btn-fee';
        } elseif ($index % 2 === 0) {
          $tag = 'Free';
          $btnLabel = 'VPS Ultra';
          $btnClass = 'btn-ultar';
        } else {
          $tag = 'Free';
          $btnLabel = 'VPS Pro L1';
          $btnClass = 'btn-por';
        }

        $logoPath = './uploads/' . htmlspecialchars($broker['logo']);
      ?>

        <div class="ea-cadr-wrapper">
          <div class="ea-cadr-tag"><?= $tag ?></div>
          <div class="ea-cadr-content">
            <img src="<?= $logoPath ?>" alt="<?= htmlspecialchars($broker['name']) ?> logo" class="ea-cadr-logo">
            <h3 class="ea-cadr-title"><?= htmlspecialchars($broker['name']) ?></h3>
            <p class="ea-cadr-specs">
              <?= htmlspecialchars($broker['software']) ?>*CPU /
              <?= htmlspecialchars($broker['license']) ?>*RAM /
              <?= htmlspecialchars($broker['average_transaction']) ?>*HDD /
              1M*ADSL
            </p>
            <a href="avatrade.php?name=<?= urlencode(strtolower($broker['name'])) ?>" target="_blank" class="ea-cadr-btn <?= $btnClass ?>">
              <?= $btnLabel ?>
            </a>
          </div>
        </div>

      <?php
        $index++;
      endforeach;
      ?>
    </div>

    <?php //include "articles.php"; 
    ?>
  </div>
</div>