/* Обвивката: mobile-first grid (header / main / bottom nav), desktop drawer.
   Никакъв хоризонтален overflow на ниво страница. */

html, body { width: 100%; min-height: 100%; overflow-x: clip; }

.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr) auto;
  min-height: 100dvh;
}

/* новата обвивка неутрализира legacy flex подредбата */
#app { display: grid; }

.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px 0 6px;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  height: calc(var(--header-height) + var(--safe-top));
}
.brand-line { font-family: var(--serif); font-size: 17px; letter-spacing: .04em; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-line:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 20px; }
.header-space { flex: 1; }

#main {
  padding: 18px 14px calc(var(--nav-height) + 24px);
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  min-width: 0;
}
#main:focus { outline: none; }

/* ------------------------------------------------ долна мобилна навигация */
.mobile-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.mobile-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 7px 2px 6px;
  font-size: 10.5px; letter-spacing: .02em;
  color: var(--muted); text-decoration: none;
}
.mobile-nav a span { font-size: 17px; line-height: 1; }
.mobile-nav a.active { color: var(--accent); }
.mobile-nav a:hover { text-decoration: none; color: var(--text); }

/* ---------------------------------------------------------------- drawer */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
  width: min(300px, 84vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .22s ease;
  overflow-y: auto;
  padding: calc(10px + var(--safe-top)) 10px 20px;
  display: flex; flex-direction: column; gap: 2px;
}
.drawer.open { transform: translateX(0); }
.drawer-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); }
.drawer-head { display: flex; gap: 10px; align-items: center; padding: 8px 12px 14px; }
.drawer-sub { font-size: 10.5px; color: var(--muted); letter-spacing: .06em; }
.drawer .nav-section { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); opacity: .7; padding: 12px 12px 3px; }
.drawer a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--muted); font-size: 14px; text-decoration: none;
}
.drawer a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.drawer a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }

/* --------------------------------------------------------------- desktop */
@media (min-width: 600px) {
  #main { padding-left: 22px; padding-right: 22px; }
}

@media (min-width: 900px) {
  .app-shell { grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: var(--header-height) minmax(0, 1fr); }
  .app-header { grid-column: 1 / -1; }
  .drawer {
    position: static; transform: none; width: 232px;
    grid-row: 2; grid-column: 1;
    border-right: 1px solid var(--border);
    padding-top: 12px;
  }
  .drawer-toggle, .drawer-overlay { display: none; }
  .mobile-nav { display: none; }
  #main { grid-row: 2; grid-column: 2; padding-bottom: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
