/* =================================================================
   nav.css  –  Sidebar layout system  (v3)
   Topbar : fixed, always full-width, always visible (z-index 500)
   Sidebar: slides in from left BELOW topbar (top: 56px), overlay
   Auto-hide: JS adds/removes body.sidebar-open
   ================================================================= */

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg, #fff);
  border-bottom: 1px solid var(--divider-light, #e0e8f5);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: var(--z-topbar, 500);
  box-shadow: var(--shadow-sm, 0 1px 4px rgba(0,0,0,0.06));
}
[data-theme="dark"] .topbar {
  background: #12131f;
  border-bottom-color: #1e1e30;
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
}

/* Hamburger – always visible */
.topbar-hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 1.5px solid rgba(0,0,0,0.12);
  cursor: pointer;
  padding: 7px;
  border-radius: 7px;
  width: 40px; height: 40px;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.topbar-hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: #333;
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease, width 0.2s ease;
}
[data-theme="dark"] .topbar-hamburger { border-color: rgba(255,255,255,0.15); }
[data-theme="dark"] .topbar-hamburger span { background: #ddd; }
.topbar-hamburger:hover { background: rgba(13,71,161,0.08); border-color: rgba(13,71,161,0.3); }
[data-theme="dark"] .topbar-hamburger:hover { background: rgba(255,255,255,0.09); border-color: rgba(255,255,255,0.25); }

/* Hamburger → X when sidebar open */
.topbar-hamburger.is-open { background: rgba(13,71,161,0.1); border-color: rgba(13,71,161,0.35); }
.topbar-hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar-hamburger.is-open span:nth-child(2) { opacity: 0; width: 0; }
.topbar-hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Brand title in topbar – links to home */
.topbar-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary, #0d47a1);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-theme="dark"] .topbar-title { color: var(--primary, #90caf9); }
.topbar-title:hover { opacity: 0.85; }

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 56px;                       /* below topbar */
  left: 0;
  width: 240px;
  height: calc(100vh - 56px);
  background: var(--bg, #fff);
  border-right: 1px solid var(--divider-light, #e0e8f5);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar, 400);
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateX(-100%);    /* hidden by default */
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1),
              box-shadow 0.28s;
  box-shadow: none;
}
[data-theme="dark"] .sidebar {
  background: #1a1b2e;
  border-right: none;
}
.sidebar.is-open {
  transform: translateX(0);
  box-shadow: 4px 0 20px rgba(0,0,0,0.14);
}
[data-theme="dark"] .sidebar.is-open { box-shadow: 4px 0 28px rgba(0,0,0,0.5); }

/* Sidebar brand row (text link, no icon) */
.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  text-decoration: none;
  border-bottom: 1px solid var(--divider-light, #e8eef8);
  flex-shrink: 0;
  min-height: 50px;
}
[data-theme="dark"] .sidebar-brand { border-bottom-color: rgba(255,255,255,0.07); }

.brand-name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary, #0d47a1);
  white-space: nowrap;
  line-height: 1.3;
}
[data-theme="dark"] .brand-name { color: var(--primary, #90caf9); }

/* Nav list */
.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.sidebar-nav ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm, 8px);
  text-decoration: none;
  color: var(--nav-text, #5a6a7e);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
[data-theme="dark"] .sidebar-link { color: rgba(255,255,255,0.55); }

.sidebar-link:hover   { background: rgba(13,71,161,0.07); color: var(--primary, #0d47a1); }
[data-theme="dark"] .sidebar-link:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.9); }

.sidebar-link.active  { background: #e8f0fe; color: var(--primary, #0d47a1); font-weight: 600; }
[data-theme="dark"] .sidebar-link.active { background: var(--secondary, #1565c0); color: #fff; }

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; fill: currentColor; }

/* Sidebar footer – theme toggle + auth */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--divider-light, #e8eef8);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
[data-theme="dark"] .sidebar-footer { border-top-color: rgba(255,255,255,0.07); }

.sidebar-footer .theme-toggle {
  background: var(--surface-alt, #f0f4fb);
  border: 1.5px solid var(--divider-light, #dde4f0);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  padding: 5px 10px;
  color: var(--text-secondary, #555);
  transition: background 0.2s;
  font-family: inherit;
  line-height: 1;
}
[data-theme="dark"] .sidebar-footer .theme-toggle {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
  color: #fff;
}
.sidebar-footer .theme-toggle:hover { background: var(--surface-hover, #dde8f5); }
[data-theme="dark"] .sidebar-footer .theme-toggle:hover { background: rgba(255,255,255,0.14); }

/* Auth nav */
#auth-nav { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#auth-nav .nav-btn {
  font-size: 0.75rem; padding: 5px 10px;
  border-radius: var(--radius-sm, 6px);
  background: var(--primary, #0d47a1); color: #fff; text-decoration: none;
  font-weight: 600; white-space: nowrap; transition: opacity 0.15s;
}
#auth-nav .nav-btn:hover { opacity: 0.85; }
#auth-nav .nav-btn-secondary {
  font-size: 0.75rem; padding: 5px 10px;
  border-radius: var(--radius-sm, 6px);
  background: transparent; border: 1.5px solid var(--input-border, #cdd6e8);
  color: var(--text-secondary, #555);
  cursor: pointer; font-family: inherit; font-weight: 500;
  white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
#auth-nav .nav-btn-secondary:hover {
  background: var(--surface-alt, #f0f4fb);
  border-color: #a0b4cc;
}
[data-theme="dark"] #auth-nav .nav-btn-secondary { color: #ccc; border-color: #444; }
[data-theme="dark"] #auth-nav .nav-btn-secondary:hover { background: rgba(255,255,255,0.08); }

/* ── Overlay backdrop ─────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 56px; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.35);
  z-index: calc(var(--z-sidebar, 400) - 10);
}
.sidebar-overlay.active { display: block; }

/* ── Page body offset ─────────────────────────────────────────── */
/* Push content down for topbar */
body:has(.sidebar) main,
body.has-sidebar main {
  margin-top: 56px;
  margin-left: 0;
  transition: margin-left 0.28s cubic-bezier(0.4,0,0.2,1);
}
/* Pages without <main>: pad body so all content clears the fixed topbar */
body:has(.sidebar):not(:has(main)),
body.has-sidebar:not(:has(main)) {
  padding-top: 56px;
}
body:has(.sidebar) footer,
body.has-sidebar footer {
  margin-left: 0;
  transition: margin-left 0.28s cubic-bezier(0.4,0,0.2,1);
}

/* When sidebar open on desktop: push content right */
@media (min-width: 901px) {
  body.sidebar-open main  { margin-left: 240px; }
  body.sidebar-open footer { margin-left: 240px; }
}

/* ── Bottom Nav (mobile only) ─────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--bg, #fff);
  border-top: 1px solid var(--divider-light, #e0e8f5);
  z-index: var(--z-float, 250);
  display: none;
  align-items: stretch;
  will-change: transform;          /* own compositing layer – won't shift on overscroll */
  transform: translateZ(0);        /* force GPU layer promotion */
}
[data-theme="dark"] .bottom-nav { background: #12131f; border-top-color: #1e1e30; }

.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-decoration: none; color: #9aa5b4;
  font-size: 0.62rem; font-weight: 600;
  gap: 3px; padding: 8px 2px 6px;
  transition: color 0.15s; letter-spacing: 0.02em;
}
[data-theme="dark"] .bottom-nav-item { color: #55607a; }
.bottom-nav-item.active { color: var(--secondary, #1565c0); }
[data-theme="dark"] .bottom-nav-item.active { color: var(--primary, #64b5f6); }
.bn-icon { width: 22px; height: 22px; fill: currentColor; }
.bn-label { line-height: 1; }

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Prevent overscroll bounce from pushing the fixed bottom-nav up */
  html {
    overscroll-behavior-y: none;
  }

  /* On mobile: sidebar always full 240px drawer */
  .sidebar { width: 240px; }

  /* Mobile: no content push when sidebar open */
  body.sidebar-open main  { margin-left: 0 !important; }
  body.sidebar-open footer { margin-left: 0 !important; }

  /* Add bottom padding for bottom-nav */
  body:has(.sidebar) main,
  body.has-sidebar main { padding-bottom: 64px; }

  /* Show bottom nav */
  .bottom-nav { display: flex; }
}
