<?php
// includes/layout.php
require_once __DIR__ . '/auth.php';

function page_header(string $title, ?array $user=null): void {
  echo "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>";
  echo "<title>".h($title)."</title>";
  echo "<style>
    body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;margin:0;background:#0b0e14;color:#e8eefc}
    a{color:#89b4ff;text-decoration:none}
    .top{display:flex;align-items:center;justify-content:space-between;padding:14px 18px;border-bottom:1px solid #1b2333;background:#0d1220;position:sticky;top:0}
    .wrap{max-width:1100px;margin:0 auto;padding:18px}
    .card{background:#0f1729;border:1px solid #1b2333;border-radius:14px;padding:14px;margin:12px 0}
    input,select,button,textarea{background:#0b1020;border:1px solid #2a3752;color:#e8eefc;border-radius:10px;padding:10px}
    button{cursor:pointer}
    .row{display:flex;gap:12px;flex-wrap:wrap}
    .row>div{flex:1;min-width:260px}
    .muted{opacity:.75}
    .danger{color:#ff7b7b}
    .tbl{width:100%;border-collapse:collapse}
    .tbl th,.tbl td{border-bottom:1px solid #1b2333;padding:10px;text-align:left}
    .pill{display:inline-block;padding:3px 10px;border-radius:999px;border:1px solid #2a3752;background:#0b1020;font-size:12px}
  </style>";
  echo "</head><body>";
  echo "<div class='top'><div><strong>Itahuka Portal</strong> <span class='muted'>Projects → Rooms → Egress → Fanout</span></div><div>";
  if ($user) {
    echo "<span class='pill'>".h($user['display_name'] ?: $user['email'])."</span> ";
    echo "<a href='/dashboard.php'>Dashboard</a> · <a href='/logout.php'>Logout</a>";
  } else {
    echo "<a href='/login.php'>Login</a> · <a href='/register.php'>Register</a>";
  }
  echo "</div></div><div class='wrap'>";
}

function page_footer(): void {
  echo "</div></body></html>";
}
