/* ============================================================
   layout.css — App shell: sidebar + topbar + content
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  grid-column: 1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.sidebar__logo {
  width: 38px; height: 38px; flex: none;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-accent-500), var(--c-accent-700));
  color: #fff; display: grid; place-items: center;
  font-weight: var(--fw-extrabold); font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
}
.sidebar__title { font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.sidebar__subtitle { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }

.sidebar__search {
  margin: var(--sp-4) var(--sp-4) var(--sp-2);
}
.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-3) var(--sp-6);
}
.nav-group__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  transition: background var(--t-fast), color var(--t-fast);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-muted); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: var(--fw-semibold); }
.nav-item.is-active .nav-item__icon { color: var(--accent); }
.nav-item__icon { width: 18px; height: 18px; flex: none; color: var(--text-muted); }
.nav-item__badge {
  margin-left: auto; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  background: var(--bg-muted); color: var(--text-muted);
  padding: 1px 8px; border-radius: var(--r-full);
}

.sidebar__footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
}

/* ---------- Main column ---------- */
.main {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  min-height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-6);
  /* Respect the iOS status bar / Dynamic Island in standalone mode */
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.topbar__menu-btn { display: none; }
.topbar__crumbs { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); min-width: 0; }
.topbar__crumbs .sep { opacity: 0.5; }
.topbar__crumbs .current { color: var(--text); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); }

.content {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.content__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6) var(--sp-16);
}
.content--wide .content__inner { max-width: 1180px; }

.page-header { margin-bottom: var(--sp-6); }
.page-header__eyebrow { font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.page-header__title { margin-top: var(--sp-2); }
.page-header__lead { margin-top: var(--sp-3); color: var(--text-secondary); font-size: var(--fs-lg); max-width: 62ch; }

/* ---------- Responsive ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  z-index: var(--z-overlay); opacity: 0; visibility: hidden; transition: opacity var(--t-base);
}
.scrim.is-open { opacity: 1; visibility: visible; }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: min(86vw, var(--sidebar-w));
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform var(--t-slow);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .main { grid-column: 1; }
  .topbar__menu-btn { display: inline-grid; }
  .content__inner { padding: var(--sp-6) var(--sp-4) var(--sp-16); }
}

@media (min-width: 921px) {
  .scrim { display: none; }
}

/* ---------- Mobile bottom tab bar (app feel) ---------- */
.bottomnav { display: none; }

@media (max-width: 920px) {
  .sidebar__brand { padding-top: calc(var(--sp-5) + env(safe-area-inset-top)); }

  .bottomnav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(10px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
  }
  .bottomnav__item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 8px 2px 6px; color: var(--text-muted);
    font-size: 10.5px; font-weight: var(--fw-semibold); text-decoration: none;
    transition: color var(--t-fast);
  }
  .bottomnav__item:hover { text-decoration: none; }
  .bottomnav__item.is-active { color: var(--accent); }
  .bottomnav__icon { width: 22px; height: 22px; }
  .bottomnav__icon svg { width: 22px; height: 22px; }

  /* Keep content clear of the bottom bar */
  .content__inner { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
