<?php
declare(strict_types=1);

$year = (int)date('Y');
$appConfigPath = __DIR__ . '/app_config.php';
$appConfig = is_file($appConfigPath) ? (require $appConfigPath) : [];
$footerSiteName = trim((string)($appConfig['branding']['site_name'] ?? 'Електронний журнал'));
if ($footerSiteName === '') {
    $footerSiteName = 'Електронний журнал';
}
if (isset($conn) && ($conn instanceof mysqli)) {
    if ($res = $conn->query("SELECT setting_value FROM settings WHERE setting_name = 'site_name' LIMIT 1")) {
        if ($row = $res->fetch_assoc()) {
            $dbSiteName = trim((string)($row['setting_value'] ?? ''));
            if ($dbSiteName !== '') {
                $footerSiteName = $dbSiteName;
            }
        }
        $res->free();
    }
}
?>
<style>
  :root{
      /* Brand */
      --brand-mint:#a3e8d3;
      --brand-mint-2:#92dec7;
      --brand-purple:#432755;
      --brand-purple-2:#3a244d;

      /* Footer UI */
      --footer-bg: var(--brand-purple);
      --footer-bg-2: var(--brand-purple-2);
      --footer-text: rgba(255,255,255,.92);
      --footer-muted: rgba(255,255,255,.70);
      --footer-border: rgba(255,255,255,.14);
      --footer-chip: rgba(255,255,255,.12);
      --footer-chip-hover: rgba(255,255,255,.18);
  }

  .kp-footer{
      margin-top:24px;
      padding:18px 14px;
      background:
        radial-gradient(900px 340px at 20% 0%, rgba(163,232,211,.14), rgba(67,39,85,0) 60%),
        radial-gradient(700px 320px at 90% 40%, rgba(163,232,211,.10), rgba(67,39,85,0) 58%),
        linear-gradient(180deg, var(--footer-bg), var(--footer-bg-2));
      color: var(--footer-text);
      border-top: 1px solid var(--footer-border);
  }

  .kp-footer__wrap{
      max-width:1100px;
      margin:0 auto;
      display:flex;
      flex-wrap:wrap;
      align-items:center;
      justify-content:space-between;
      gap:12px;
  }

  .kp-footer__brand{
      font-weight:900;
      letter-spacing:.2px;
      color: var(--footer-text);
      display:flex;
      align-items:center;
      gap:10px;
      flex-wrap:wrap;
  }

  .kp-footer__brand small{
      font-weight:800;
      color: var(--footer-muted);
      letter-spacing:.15px;
  }

  .kp-footer__links{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
      align-items:center;
      justify-content:center;
  }

  .kp-footer__links a{
      color: var(--footer-text);
      text-decoration:none;
      padding:8px 12px;
      border-radius:9999px;
      background: var(--footer-chip);
      border: 1px solid rgba(255,255,255,.10);
      font-weight:900;
      transition: background .15s ease, transform .05s ease;
      line-height: 1;
      white-space: nowrap;
  }

  .kp-footer__links a:hover{
      background: var(--footer-chip-hover);
      text-decoration:none;
  }
  .kp-footer__links a:active{
      transform: translateY(1px);
  }

  .kp-footer__dev{
      color: var(--footer-muted);
      font-weight:800;
      display:flex;
      align-items:center;
      gap:6px;
      flex-wrap:wrap;
  }

  .kp-footer__dev a{
      color: var(--brand-mint);
      text-decoration:none;
      font-weight:900;
      transition: opacity .15s ease;
  }

  .kp-footer__dev a:hover{
      opacity:.85;
      text-decoration:underline;
  }

  /* Блок лічильника (залишаємо оригінальний розмір) */
  .kp-counter{
      display:flex;
      align-items:center;
      justify-content:center;
      background: rgba(255,255,255,.10);
      border: 1px solid rgba(255,255,255,.12);
      padding:8px 10px;
      border-radius:12px;
  }

  @media (max-width: 600px){
      .kp-footer{
          padding:16px 12px;
      }
      .kp-footer__wrap{
          justify-content:center;
          text-align:center;
      }
      .kp-footer__brand{
          justify-content:center;
      }
      .kp-footer__dev{
          justify-content:center;
      }
  }
</style>

<footer class="kp-footer" role="contentinfo">
  <div class="kp-footer__wrap">

    <div class="kp-footer__brand">
      <?= htmlspecialchars((string)$footerSiteName, ENT_QUOTES, 'UTF-8') ?> · © <?= $year ?>
    </div>

    <nav class="kp-footer__links" aria-label="Посилання в футері">
      <a href="/index.php">Головна</a>
      <a href="/forgot_password.php">Забув пароль</a>
    </nav>

    <div class="kp-footer__dev">
      <span>Розроблено</span>
      <a href="https://sitepro.net.ua/" target="_blank" rel="noopener noreferrer">SitePro</a>
    </div>

  </div>
</footer>