/* ── App Shell — Mobile-First Navigation & Layout ──────────────────────
 * Provides consistent header, bottom nav, and page transitions.
 * All pages include this via <link> — individual page styles layer on top.
 * author: AEON Dev | created: 2026-04-26
 */

/* ── Design Tokens ───────────────────────────────────────────────────── */
:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #222633; --surface3: #2a2e3b;
  --border: #2e3345; --border2: #3d4255;
  --text: #e2e4ea; --text-muted: #8b90a0; --text-dim: #5a5f72;
  --accent: #2f7c55; --accent-light: #4ade80; --accent-dim: #1e4a35;
  --blue: #2563eb; --blue-light: #60a5fa;
  --purple: #7c3aed; --purple-light: #a78bfa;
  --orange: #d97706; --orange-light: #fbbf24;
  --positive: #4ade80; --negative: #f87171; --warning: #fbbf24; --info: #60a5fa;
  --radius: 12px; --radius-sm: 6px;
  --header-h: 52px;
  --bottom-nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  min-height: 100dvh;
  /* Prevent rubber-band overscroll on iOS */
  overscroll-behavior-y: none;
  /* Account for bottom nav + safe area */
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

/* ── Top Header ──────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
  /* Blur effect for scroll-under content */
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(26, 29, 39, 0.92);
}

.app-header-back {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  color: var(--accent-light); text-decoration: none;
  font-size: 1.1rem; flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.app-header-back:hover { background: var(--surface2); }

.app-header-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.app-header-title small {
  font-weight: 400; color: var(--text-muted); font-size: 0.78rem; margin-left: 6px;
}

.app-header-actions {
  display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0;
}

.app-header-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent;
}

/* ── User Menu (dropdown on avatar tap) ──────────────────────────────── */
.user-menu {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 8px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 8px 0;
  min-width: 200px; z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.user-menu.open { display: block; }
.user-menu-email {
  padding: 10px 16px; font-size: 0.78rem; color: var(--text-muted);
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
  word-break: break-all;
}
.user-menu-item {
  display: block; width: 100%; padding: 10px 16px;
  background: none; border: none; color: var(--text);
  font-size: 0.85rem; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.user-menu-item:hover { background: var(--surface3); }
.user-menu-item.danger { color: var(--negative); }

/* ── Bottom Navigation Bar ───────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: rgba(26, 29, 39, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: stretch; justify-content: space-around;
}

.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 2px;
  color: var(--text-dim); text-decoration: none;
  font-size: 0.62rem; font-weight: 500; letter-spacing: 0.2px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 6px 0;
}
.bottom-nav-item:active { transform: scale(0.95); }
.bottom-nav-item .nav-icon { font-size: 1.25rem; line-height: 1; }
.bottom-nav-item.active { color: var(--accent-light); }
.bottom-nav-item.active::after {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 2px; background: var(--accent-light); border-radius: 1px;
}

/* ── Page Content ────────────────────────────────────────────────────── */
.app-content {
  max-width: 1200px; width: 100%;
  margin: 0 auto; padding: 16px;
}

/* ── Mobile Utilities ────────────────────────────────────────────────── */
.hide-mobile { display: none; }
.show-mobile { display: block; }

/* Touch-friendly targets */
button, a, select, input, .touchable {
  min-height: 44px;
  /* iOS recommended minimum */
}
select { min-height: 36px; }

/* Pull-to-refresh indicator */
.pull-indicator {
  text-align: center; padding: 12px; color: var(--text-dim);
  font-size: 0.78rem; display: none;
}

/* Page transition feel */
.app-content { animation: fadeSlideIn 0.2s ease-out; }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Toast — global */
.app-toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 10px 20px;
  font-size: 0.85rem; z-index: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
  max-width: 90vw; text-align: center;
}
.app-toast.visible { opacity: 1; pointer-events: auto; }

/* ── Tablet+ (≥768px) ───────────────────────────────────────────────── */
@media (min-width: 768px) {
  .hide-mobile { display: initial; }
  .show-mobile { display: none; }
  .app-content { padding: 24px; }
  .app-header { padding: 0 24px; }

  /* On tablet+, bottom nav stays but gets wider tap targets */
  .bottom-nav-item { font-size: 0.7rem; gap: 3px; }
  .bottom-nav-item .nav-icon { font-size: 1.3rem; }
}

/* ── Desktop (≥1024px) ───────────────────────────────────────────────── */
@media (min-width: 1024px) {
  :root { --bottom-nav-h: 0px; }
  body { padding-bottom: 0; }

  /* Hide bottom nav on desktop — use header nav instead */
  .bottom-nav { display: none; }

  /* Show desktop nav in header */
  .desktop-nav { display: flex !important; }

  .app-header { padding: 0 32px; height: 56px; }
  .app-content { padding: 32px; }
}

/* Desktop nav links in header — hidden on mobile */
.desktop-nav {
  display: none; align-items: center; gap: 4px; margin-left: 24px;
}
.desktop-nav a {
  padding: 6px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); text-decoration: none; font-size: 0.85rem;
  transition: all 0.15s; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.desktop-nav a:hover { color: var(--text); background: var(--surface2); }
.desktop-nav a.active { color: var(--accent-light); background: var(--accent-dim); }

/* ── Shared Component Styles ─────────────────────────────────────────── */
.btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  cursor: pointer; font-size: 0.82rem; font-weight: 500;
  transition: all .15s; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface3); border-color: var(--border2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); color: #000; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; min-height: 36px; }
