/* layout.css — two-column body grid, sidebar, content area, filter panel */

/* Body: sidebar | content, full viewport, no outer scroll */
body {
  display: grid;
  grid-template-columns: auto 1fr;   /* auto = sized by #sidebar width */
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  background: var(--parchment);
  color: var(--ink);
}

/* ===========================
   SIDEBAR
   =========================== */

#sidebar {
  grid-column: 1;
  width: var(--sidebar-w);
  min-width: var(--sidebar-collapsed-w);
  height: 100vh;
  overflow: hidden;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  transition: width 220ms ease;
  z-index: 100;
  flex-shrink: 0;
}

body.sidebar-collapsed #sidebar {
  width: var(--sidebar-collapsed-w);
}

/* Header row inside sidebar */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s2) 0 var(--s4);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  height: 56px;
  gap: var(--s2);
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 150ms ease;
  flex: 1;
  min-width: 0;
}

body.sidebar-collapsed .site-title {
  opacity: 0;
  pointer-events: none;
}

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-muted);
  font-size: 1.1rem;
  padding: var(--s1) var(--s2);
  border-radius: var(--r);
  flex-shrink: 0;
  line-height: 1;
  transition: color 100ms ease, background 100ms ease;
}

.sidebar-toggle:hover {
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.07);
}

/* Nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: var(--s2) 0;
  overflow-y: auto;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  color: var(--sidebar-muted);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  white-space: nowrap;
  min-height: 40px;
  transition: color 100ms ease, background 100ms ease, border-color 100ms ease;
  overflow: hidden;
}

.nav-link:hover {
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
  color: var(--sidebar-text);
  background: var(--sidebar-active);
  border-left-color: var(--accent);
}

.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  color: var(--sidebar-text);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.nav-label {
  opacity: 1;
  transition: opacity 150ms ease;
  overflow: hidden;
  min-width: 0;
}

body.sidebar-collapsed .nav-label {
  opacity: 0;
  pointer-events: none;
}

body.sidebar-collapsed .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* ===========================
   CONTENT AREA (default — padded)
   =========================== */

#content {
  grid-column: 2;
  height: 100vh;
  overflow-y: auto;
  padding: var(--s6);
  background: var(--parchment);
}

/* Fade-in */
@media (prefers-reduced-motion: no-preference) {
  @keyframes fadein {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  #content {
    animation: fadein 140ms ease;
  }
}

/* ===========================
   BROWSER PAGES (grammar, topics, idioms, templates)
   #content.page-browser overrides the default padded layout to a flex row
   =========================== */

#content.page-browser {
  padding: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow: hidden;
}

/* Filter panel — left side of browser pages */
.frames-filter-panel {
  width: var(--filter-panel-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--s5) var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}

/* Main scrollable area — right side of browser pages */
.frames-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: var(--s5);
}

/* Card grid inside .frames-main */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s4);
}

@media (max-width: 900px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  /* stack the browser-page columns vertically below 900px */
  #content.page-browser {
    flex-direction: column;
    overflow-y: auto;
  }

  .frames-filter-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }

  .frames-main {
    overflow-y: visible;
  }
}

/* Page heading (used inside .frames-main and on standard pages) */
.page-heading {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--s5);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
}
