/* Khung layout + design token dùng chung cho /app, /history, /connections, /admin.
   Trước đây CSS này bị copy-paste ở cả 4 file và đã lệch nhau — xem
   docs/superpowers/specs/2026-07-30-shell-layout-aspect-ratio-admin-nav-design.md.
   Trang nào cần khác thì override trong <style> của chính nó; nhớ đặt <link>
   này TRƯỚC <style> để override ăn theo thứ tự nguồn. */

:root {
  --bg: #0d1117; --panel: #161b22; --border: #30363d;
  --text: #e6edf3; --muted: #8b949e; --accent: #2f6bff; --accent2: #9333ea;
  --grad: linear-gradient(135deg, var(--accent), var(--accent2));
  --ok: #3fb950; --warn: #d29922;
  --shell-w: 1280px; --sidenav-w: 180px;
}

* { box-sizing: border-box; margin: 0; }
body { background: var(--bg); color: var(--text);
       font: 16px/1.6 -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }

header { border-bottom: 1px solid var(--border); position: sticky; top: 0;
         background: rgba(13,17,23,.9); backdrop-filter: blur(8px); z-index: 10; }
.nav { max-width: var(--shell-w); margin: 0 auto; padding: 14px 16px;
       display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800;
         font-size: 18px; text-decoration: none; }
.brand img { height: 36px; width: auto; }
.user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.user img { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); }

.btn { border: 0; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600;
       cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: var(--grad); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.shell { display: flex; gap: 8px; max-width: var(--shell-w); margin: 0 auto; align-items: flex-start; }
.sidenav { width: var(--sidenav-w); flex-shrink: 0; padding: 32px 12px; position: sticky; top: 65px; }
.sidenav .nav-item { display: block; padding: 10px 14px; border-radius: 8px; color: var(--muted);
                     text-decoration: none; margin-bottom: 4px; font-weight: 600; }
.sidenav .nav-item:hover { background: var(--panel); }
.sidenav .nav-item.active { background: var(--panel); color: var(--text); }

/* Mục Admin: ẩn mặc định, chỉ hiện khi data-admin="1". Khớp CẢ HAI class để
   độ đặc hiệu (0-3-0) thực sự thắng .sidenav .nav-item (0-2-0) — không phụ
   thuộc thứ tự nguồn. KHÔNG dùng class .hidden vì !important của nó sẽ chặn
   luôn luật hiện lại bên dưới. */
.sidenav .nav-item.nav-admin { display: none; }
html[data-admin="1"] .sidenav .nav-item.nav-admin { display: block; }

@media (max-width: 640px) {
  .shell { flex-direction: column; }
  .sidenav { width: 100%; display: flex; gap: 8px; padding: 12px 16px; position: static; }
}

main { flex: 1; min-width: 0; padding: 32px 16px 80px; }
.card { background: var(--panel); border: 1px solid var(--border);
        border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.hidden { display: none !important; }
.note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.err { color: #ff7b72; margin-top: 10px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted);
           border-top-color: transparent; border-radius: 50%;
           animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

#gate { max-width: 420px; margin: 100px auto; text-align: center; }
#gate .gate-logo { display: block; width: 240px; height: auto; margin: 0 auto 22px; }
#gate h1 { font-size: 22px; margin-bottom: 8px; }
#gate p { color: var(--muted); margin-bottom: 24px; }

/* Khung auth 4 trạng thái. Mặc định HTML mang data-auth="out" nên khi JS tắt
   hoặc localStorage bị chặn thì màn login hiện ngay và ĐÚNG.
   - out      : chưa đăng nhập (xác nhận, hoặc không có cờ) → #gate
   - guess-in : có cờ tv_auth → vẽ ngay #boot, KHÔNG bao giờ hiện #gate
   - in       : Firebase xác nhận có user → #authed; #boot vẫn còn để không hở
                khoảng trắng, trang tự gọi hide("boot") khi dữ liệu về.
   - stalled  : auth.js nạp module Firebase từ gstatic thất bại (offline, proxy
                chặn, CDN lỗi) nên watchAuth không bao giờ chạy — thay vì kẹt ở
                spinner vô hạn, rơi về màn đăng nhập.
   #boot bị ẩn bằng class .hidden (!important) nên thắng luật display:block ở đây. */
#gate, #boot, #authed { display: none; }
html[data-auth="out"]      #gate   { display: block; }
html[data-auth="guess-in"] #boot   { display: block; }
html[data-auth="in"]       #boot   { display: block; }
html[data-auth="in"]       #authed { display: block; }
html[data-auth="stalled"]  #gate   { display: block; }
#boot { color: var(--muted); padding: 40px 0; text-align: center; }
