<?php
declare(strict_types=1);
// layout_head($title) — call before any HTML output
function lk_layout_head(string $title = 'LudoKing Bot Panel'): void { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?> — LudoKing Bot</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;900&display=swap" rel="stylesheet">
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
  --bg:    #0b1120;
  --bg2:   #0f1929;
  --card:  #111c35;
  --bd:    rgba(255,255,255,.08);
  --txt:   #e2e8f0;
  --muted: rgba(226,232,240,.55);
  --a1:    #10b981;
  --a2:    #059669;
  --a3:    #34d399;
  --gold:  #fbbf24;
  --bad:   #ef4444;
  --warn:  #f59e0b;
  --good:  #10b981;
  --nav-w: 220px;
}
html,body{height:100%}
body{display:flex;flex-direction:column;min-height:100dvh;background:var(--bg);font-family:'Inter',sans-serif;color:var(--txt);}
body::before{
  content:'';position:fixed;inset:0;pointer-events:none;z-index:0;
  background:
    radial-gradient(ellipse 55% 45% at 10% 5%, rgba(16,185,129,.10), transparent 55%),
    radial-gradient(ellipse 45% 55% at 90% 95%, rgba(251,191,36,.07), transparent 55%);
}

/* ── TOP NAV ── */
.topbar{
  position:sticky;top:0;z-index:50;
  display:flex;align-items:center;gap:12px;
  padding:0 20px;height:58px;
  background:rgba(11,17,32,.88);
  backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
  border-bottom:1px solid var(--bd);
}
.topbar-brand{
  display:flex;align-items:center;gap:10px;
  font-weight:900;font-size:18px;color:var(--txt);text-decoration:none;
}
.topbar-brand .ico{
  width:36px;height:36px;border-radius:10px;
  background:linear-gradient(135deg,var(--a1),var(--a2));
  display:flex;align-items:center;justify-content:center;font-size:18px;
  box-shadow:0 4px 14px rgba(16,185,129,.35);
  flex-shrink:0;
}
.topbar-nav{display:flex;align-items:center;gap:4px;margin-left:auto;}
.topbar-nav a{
  padding:7px 14px;border-radius:10px;font-size:13px;font-weight:700;
  color:var(--muted);text-decoration:none;transition:background .15s,color .15s;
  white-space:nowrap;
}
.topbar-nav a:hover,.topbar-nav a.active{background:rgba(16,185,129,.14);color:var(--a3);}
.topbar-nav a.logout{color:rgba(239,68,68,.8);}
.topbar-nav a.logout:hover{background:rgba(239,68,68,.12);color:#fca5a5;}

/* ── MAIN CONTENT ── */
.page{
  flex:1;position:relative;z-index:1;
  max-width:1100px;width:100%;margin:0 auto;
  padding:28px 20px 48px;
}

/* ── CARDS & GRIDS ── */
.card{background:var(--card);border:1px solid var(--bd);border-radius:20px;padding:24px;}
.card-sm{padding:16px 20px;}
.grid-2{display:grid;grid-template-columns:repeat(2,1fr);gap:16px;}
.grid-3{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;}
.grid-4{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;}

/* ── HEADINGS ── */
.page-head{margin-bottom:24px;}
.page-head h2{font-size:22px;font-weight:900;
  background:linear-gradient(120deg,var(--a3),var(--gold));
  -webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;
}
.page-head p{font-size:13px;color:var(--muted);margin-top:4px;}

/* ── KPI CARD ── */
.kpi{
  background:linear-gradient(160deg,rgba(16,185,129,.08),rgba(16,185,129,.02));
  border:1px solid rgba(16,185,129,.18);
  border-radius:18px;padding:20px;
}
.kpi .kpi-label{font-size:12px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.05em;}
.kpi .kpi-val{font-size:28px;font-weight:900;color:var(--a3);margin:8px 0 4px;}
.kpi .kpi-sub{font-size:12px;color:var(--muted);}

/* ── TABLES ── */
.tbl{width:100%;border-collapse:collapse;font-size:13px;}
.tbl th{text-align:left;padding:10px 14px;color:var(--muted);font-weight:700;border-bottom:1px solid var(--bd);}
.tbl td{padding:10px 14px;border-bottom:1px solid rgba(255,255,255,.04);color:var(--txt);}
.tbl tr:last-child td{border-bottom:none;}
.tbl tr:hover td{background:rgba(255,255,255,.03);}
.tbl .code{font-family:monospace;font-size:15px;font-weight:700;color:var(--gold);letter-spacing:.04em;}

/* ── BADGES ── */
.badge{display:inline-flex;align-items:center;gap:4px;padding:3px 10px;border-radius:999px;font-size:11px;font-weight:700;}
.badge-green{background:rgba(16,185,129,.15);color:var(--a3);border:1px solid rgba(16,185,129,.25);}
.badge-gold{background:rgba(251,191,36,.12);color:var(--gold);border:1px solid rgba(251,191,36,.22);}
.badge-red{background:rgba(239,68,68,.12);color:#fca5a5;border:1px solid rgba(239,68,68,.22);}
.badge-muted{background:rgba(255,255,255,.06);color:var(--muted);border:1px solid var(--bd);}

/* ── FORMS ── */
label.lbl{display:block;font-size:12px;font-weight:700;color:var(--muted);margin-bottom:6px;}
.inp{
  width:100%;padding:10px 14px;background:rgba(255,255,255,.05);
  border:1px solid var(--bd);border-radius:12px;color:var(--txt);
  font-size:14px;font-family:inherit;outline:none;transition:border-color .2s;
}
.inp:focus{border-color:var(--a1);}
select.inp{cursor:pointer;}
.field{margin-bottom:16px;}

/* ── BUTTONS ── */
.btn{display:inline-flex;align-items:center;gap:6px;padding:9px 20px;border:none;border-radius:12px;cursor:pointer;font-size:13px;font-weight:700;font-family:inherit;transition:box-shadow .18s,transform .18s;white-space:nowrap;}
.btn:hover{transform:translateY(-1px);}
.btn-green{background:linear-gradient(135deg,var(--a1),var(--a2));color:#fff;box-shadow:0 6px 18px rgba(16,185,129,.30);}
.btn-green:hover{box-shadow:0 10px 26px rgba(16,185,129,.45);}
.btn-gold{background:linear-gradient(135deg,#fbbf24,#d97706);color:#1a1200;box-shadow:0 6px 18px rgba(251,191,36,.28);}
.btn-gold:hover{box-shadow:0 10px 26px rgba(251,191,36,.42);}
.btn-red{background:linear-gradient(135deg,#ef4444,#dc2626);color:#fff;box-shadow:0 6px 18px rgba(239,68,68,.28);}
.btn-red:hover{box-shadow:0 10px 26px rgba(239,68,68,.42);}
.btn-ghost{background:rgba(255,255,255,.07);color:var(--txt);border:1px solid var(--bd);}
.btn-ghost:hover{background:rgba(255,255,255,.12);}
.btn-sm{padding:6px 14px;font-size:12px;border-radius:9px;}
.btn-lg{padding:13px 28px;font-size:15px;border-radius:14px;}

/* ── FLASH ── */
.flash{padding:12px 16px;border-radius:14px;font-size:13px;font-weight:700;margin-bottom:18px;}
.flash-ok{background:rgba(16,185,129,.12);color:#a7f3d0;border:1px solid rgba(16,185,129,.28);}
.flash-bad{background:rgba(239,68,68,.12);color:#fca5a5;border:1px solid rgba(239,68,68,.28);}
.flash-warn{background:rgba(245,158,11,.12);color:#fde68a;border:1px solid rgba(245,158,11,.28);}

/* ── SECTION DIVIDER ── */
.sec-head{font-size:13px;font-weight:900;color:var(--a3);text-transform:uppercase;letter-spacing:.06em;margin-bottom:14px;display:flex;align-items:center;gap:8px;}
.sec-head::after{content:'';flex:1;height:1px;background:rgba(255,255,255,.07);}

/* ── RESPONSIVE ── */
@media(max-width:700px){
  .grid-2,.grid-3,.grid-4{grid-template-columns:1fr;}
  .topbar-nav a span{display:none;}
  .topbar-nav a{padding:7px 10px;}
  .page{padding:18px 14px 40px;}
}
</style>
<?php } ?>
<?php
function lk_layout_nav(string $active = ''): void {
    $pages = [
        ['href'=>'/','label'=>'Dashboard','key'=>'dashboard','ico'=>'📊'],
        ['href'=>'/rooms.php','label'=>'Rooms','key'=>'rooms','ico'=>'🎮'],
        ['href'=>'/users.php','label'=>'Users','key'=>'users','ico'=>'👥'],
        ['href'=>'/super_panel.php','label'=>'IP Mgmt','key'=>'super','ico'=>'🔑'],
        ['href'=>'/logout.php','label'=>'Logout','key'=>'logout','ico'=>'↩','class'=>'logout'],
    ];
    ?>
    <nav class="topbar">
      <a href="/" class="topbar-brand">
        <div class="ico">♟</div>
        <span>LudoKing Bot</span>
      </a>
      <div class="topbar-nav">
        <?php foreach ($pages as $p): ?>
          <a href="<?= lk_e($p['href']) ?>" class="<?= $active === ($p['key'] ?? '') ? 'active' : '' ?> <?= $p['class'] ?? '' ?>">
            <?= $p['ico'] ?> <span><?= lk_e($p['label']) ?></span>
          </a>
        <?php endforeach; ?>
      </div>
    </nav>
    <?php
}

function lk_layout_foot(): void { ?>
</div></body></html>
<?php }
