/* ============================================================
   LAYOUT — nav, sidebar, grid, flex helpers, page shell
   ============================================================ */

/* ── App shell ─────────────────────────────────────────────── */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Top Nav ───────────────────────────────────────────────── */

.top-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--nav-h);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  padding: 0 var(--s-5);
  gap: var(--s-4);
}

.nav-logo {
  font-size: var(--fs-xl);
  font-weight: 800;
  font-family: var(--font-display);
  background: linear-gradient(135deg, var(--accent), #a855f7, #ec4899);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease infinite;
  text-decoration: none;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  flex: 1;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
  border: none;
  background: none;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-light);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
}

.nav-hamburger {
  display: none;
  padding: var(--s-2);
  cursor: pointer;
  color: var(--text-secondary);
}

/* ── Page with sidebar ─────────────────────────────────────── */

.page-with-sidebar {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-3);
  overflow-y: auto;
  transition: transform var(--t-med);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.sidebar-item__icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-item__label {
  flex: 1;
}

.sidebar-item__count {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  padding: 1px 6px;
  border-radius: var(--r-full);
}

.sidebar-item.active .sidebar-item__count {
  background: var(--accent);
  color: #fff;
}

/* ── Main content ──────────────────────────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
}

.content-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  font-family: var(--font-display);
}

/* ── Flex helpers ──────────────────────────────────────────── */

.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end   { justify-content: flex-end; }
.flex-1      { flex: 1; }
.flex-wrap   { flex-wrap: wrap; }
.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.gap-5 { gap: var(--s-5); }

/* ── Grid helpers ───────────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-4); }

/* ── Spacing helpers ────────────────────────────────────────── */

.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-5 { margin-bottom: var(--s-5); }
.ml-auto { margin-left: auto; }

.p-2  { padding: var(--s-2); }
.p-3  { padding: var(--s-3); }
.p-4  { padding: var(--s-4); }
.p-5  { padding: var(--s-5); }
.px-4 { padding-left: var(--s-4); padding-right: var(--s-4); }
.py-3 { padding-top: var(--s-3); padding-bottom: var(--s-3); }

/* ── Visibility helpers ─────────────────────────────────────── */

.hidden  { display: none !important; }
.invisible { visibility: hidden; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  .nav-links {
    display: none;
  }

  .nav-hamburger {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    z-index: var(--z-overlay);
    transform: translateX(-100%);
    width: min(var(--sidebar-w), 80vw);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: calc(var(--z-overlay) - 1);
    display: none;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .main-content {
    padding: var(--s-4);
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  #toast-container {
    bottom: var(--s-4);
    right: var(--s-4);
    left: var(--s-4);
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .modal {
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    max-height: 95dvh;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
}
