/* app/styles/layout.css
   App shell: sidebar (desktop) -> icon rail (tablet) -> bottom tab bar (phone), top bar and page frame. */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0;
  height: 100dvh;
  display: flex; flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-weight: 700; font-size: var(--fs-lg);
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand b { color: var(--brand); font-weight: 700; }
.brand small {
  font-family: var(--font-sans);
  font-size: var(--fs-xs); font-weight: 500;
  color: var(--text-3);
  padding: 1px 8px; border-radius: var(--radius-full);
  background: var(--neutral-soft);
}

.nav-list { display: flex; flex-direction: column; gap: 2px; list-style: none; margin: 0; padding: 0; }
.nav-group-label {
  margin: var(--sp-4) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-3);
}

.nav-link {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 40px;
  padding: 0 var(--sp-3);
  border: 0; border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-md);
  text-decoration: none;
  width: 100%;
  text-align: left;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.nav-link .icon { flex: none; }

.sidebar-footer { margin-top: auto; padding-top: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-1); }

/* ---------- Main + top bar ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-6);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}

.search-trigger {
  flex: 1; max-width: 520px;
  display: flex; align-items: center; gap: var(--sp-2);
  height: 36px; padding: 0 var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-3);
  text-align: left;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-spacer { flex: 1; }

.env-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600;
  background: var(--success-soft); color: var(--success);
  border: 0;
}
.env-badge[data-env="preview"] { background: var(--warning-soft); color: var(--warning); }
.env-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.env-banner {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--warning-soft); color: var(--warning);
  font-size: var(--fs-sm); font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.user-menu { position: relative; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: var(--fs-xs); font-weight: 600;
  border: 0;
}
.avatar.lg { width: 48px; height: 48px; font-size: var(--fs-md); }
.avatar.pro { background: var(--pro-soft); color: var(--pro); }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 220px; padding: var(--sp-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  z-index: 60;
}
.menu-head { padding: var(--sp-2) var(--sp-3); }
.menu-head strong { display: block; }
.menu-head span { color: var(--text-3); font-size: var(--fs-sm); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-2) 0; }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 38px; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text); text-align: left;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item[aria-checked="true"] { font-weight: 600; }
.menu-item .check { margin-left: auto; color: var(--accent); }

/* ---------- Page frame ---------- */
.page {
  width: 100%; max-width: 1280px;
  margin: 0 auto;
  padding: var(--sp-6);
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-head h1:focus { outline: none; }
.page-head p { color: var(--text-2); margin-top: var(--sp-1); max-width: 70ch; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.breadcrumb { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-3); margin-bottom: var(--sp-2); }
.breadcrumb a { color: var(--text-2); }

.grid { display: grid; gap: var(--sp-4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-sidebar { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack.tight { gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* ---------- Bottom nav (phone) ---------- */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav ul { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--bottomnav-h); margin: 0; padding: 0; list-style: none; }
.bottom-nav .tab-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 100%; height: 100%;
  border: 0; background: transparent;
  color: var(--text-3); font-size: 0.6875rem;
  text-decoration: none;
}
.bottom-nav .tab-link:hover { text-decoration: none; color: var(--text); }
.bottom-nav [aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  .app-shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .sidebar { padding-inline: var(--sp-2); align-items: center; }
  .nav-label, .brand small, .nav-group-label, .sidebar-footer .nav-label { display: none; }
  .brand { padding-inline: 0; }
  .nav-link { justify-content: center; padding: 0; width: 44px; height: 44px; }
  .nav-link[aria-current="page"]::before { left: -8px; }
  .grid.cols-sidebar { grid-template-columns: minmax(0, 1fr); }
  .topbar, .page { padding-inline: var(--sp-4); }
}

@media (max-width: 767px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
  .page { padding: var(--sp-4); }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding-inline: var(--sp-3); }
  .search-trigger kbd { display: none; }
  .env-badge .env-text { display: none; }
}
