/* ==========================================================
   layout.css — Grid/flex layout primitives for app shell
   ========================================================== */

/* ─── App shell ──────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
  background: var(--bg-base);
}

/* ─── Nav rail (desktop sidebar) ────────────────────────── */
.nav-rail {
  width: var(--nav-rail-width);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
}

.nav-rail.collapsed {
  width: var(--nav-rail-collapsed);
}

.nav-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  height: 64px;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  font-weight: var(--weight-semi);
  color: var(--text-primary);
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
}

.nav-logo .logo-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}

.nav-rail.collapsed .nav-logo-text { display: none; }
.nav-rail.collapsed .nav-label { display: none; }

.nav-body {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--duration-micro) var(--ease-out),
              color var(--duration-micro) var(--ease-out);
  position: relative;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

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

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

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-link svg { flex-shrink: 0; }

.nav-footer {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* KB switcher in nav */
.nav-kb-section {
  padding: var(--space-2) var(--space-3);
}

.nav-kb-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

/* ─── Main content area ──────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--nav-rail-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--duration-base) var(--ease-out);
}

.main-content.rail-collapsed {
  margin-left: var(--nav-rail-collapsed);
}

/* Top bar (within main content) */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left  { display: flex; align-items: center; gap: var(--space-3); }
.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

/* ─── Page container ────────────────────────────────────── */
.page-container {
  flex: 1;
  padding: var(--space-8) var(--space-6);
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

.page-container.full-height {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  overflow: hidden;
  padding: 0;
}

/* ─── Two-column layout (chat, KB manager) ───────────────── */
.two-col-layout {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

.sidebar-col {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-col.collapsed {
  width: 0;
  border: none;
}

.content-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ─── Section header pattern ─────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  color: var(--text-primary);
}

/* ─── Mobile bottom nav ──────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  z-index: 100;
  padding: var(--space-2) 0;
  padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
}

.mobile-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: var(--weight-medium);
  cursor: pointer;
  border: none;
  background: none;
  transition: color var(--duration-micro) var(--ease-out);
}

.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item.active svg { color: var(--accent); }

/* ─── Responsive breakpoints ─────────────────────────────── */
@media (max-width: 1023px) {
  .nav-rail {
    transform: translateX(-100%);
  }
  .nav-rail.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .main-content {
    margin-left: 0 !important;
    padding-bottom: 80px; /* space for mobile nav */
  }
  .mobile-nav { display: block; }
}

@media (max-width: 767px) {
  .page-container {
    padding: var(--space-4) var(--space-4);
  }
  .topbar {
    padding: 0 var(--space-4);
  }
  .sidebar-col {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }
  .sidebar-col.mobile-open {
    transform: translateX(0);
  }
}

/* ─── Overlay backdrop ───────────────────────────────────── */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 80;
}

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

/* ─── Grid layouts ───────────────────────────────────────── */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* ─── Slide-over panel ───────────────────────────────────── */
.slide-over {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xl);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-base) var(--ease-out);
}

.slide-over.open {
  transform: translateX(0);
}

.slide-over-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.slide-over-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
}
