/* ===== App shell ========================================================= */
.app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: min(84vw, 300px);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--dur) var(--ease);
  overflow-y: auto;
}
.app.is-nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
.nav-scrim {
  position: fixed; inset: 0; z-index: 30;
  background: var(--overlay);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.app.is-nav-open .nav-scrim { opacity: 1; pointer-events: auto; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px;
  font-weight: 700; font-size: var(--fs-lg); color: var(--ink); text-decoration: none;
}
.brand svg { flex: none; }

.nav { padding: 6px 10px 16px; display: grid; gap: 2px; }
.nav__section { margin: 14px 12px 4px; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--touch);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-sunken); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav a svg { flex: none; opacity: 0.85; }

.sidebar__footer { margin-top: auto; padding: 12px 20px 20px; border-top: 1px solid var(--line); font-size: var(--fs-sm); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
  padding: 8px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__title { font-size: var(--fs-lg); font-weight: 650; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-toggle { display: inline-flex; }

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 20px var(--gutter) 64px;
  display: grid; gap: 20px;
  min-width: 0;
}

@media (min-width: 1024px) {
  .app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; transform: none; width: auto; }
  .nav-scrim, .topbar .nav-toggle { display: none; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.page-head > div:first-child { margin-right: auto; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

.grid-2 { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.grid-3 { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.stack { display: grid; gap: 12px; }
.stack-lg { display: grid; gap: 20px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }

/* ===== Auth layout ======================================================= */
.auth {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 32px var(--gutter);
}
.auth__card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 28px;
}
.auth__card h1 { margin-bottom: 6px; }
.auth__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: var(--fs-lg); margin-bottom: 20px; }
.auth__footer { margin-top: 16px; font-size: var(--fs-sm); color: var(--ink-2); }

@media (max-width: 639px) {
  .topbar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .topbar__title { display: none; }
  .topbar .month-switcher { margin-left: auto; flex-wrap: nowrap; gap: 0; min-width: 0; }
  .topbar .month-switcher__today { display: none; } /* the arrows are enough on a phone */
  .topbar .month-switcher__form { gap: 4px; min-width: 0; }
  .topbar .select--inline { max-width: 8.4em; padding-left: 7px; padding-right: 2px; font-size: var(--fs-sm); } /* the native arrow is extra */
  .topbar .month-switcher__year { width: 5.4em; }
}

/* ===== Phone tab bar (the sidebar is a drawer there) ======================= */
.tabbar { display: none; }
@media (max-width: 767px) {
  .tabbar {
    position: fixed; inset: auto 0 0 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }
  .tabbar a {
    display: grid; justify-items: center; gap: 2px; min-height: var(--touch); padding: 4px 2px;
    color: var(--ink-3); text-decoration: none; font-size: 11px; font-weight: 600; border-radius: var(--radius-sm);
  }
  .tabbar a[aria-current="page"] { color: var(--accent-ink); }
  .tabbar .tabbar__add { color: var(--ink-inverse); background: var(--accent); margin: 0 6px; }
  .content { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}

/* Guided tour */
.tour {
  position: fixed; z-index: 40; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: min(360px, calc(100vw - 32px)); padding: 16px; display: grid; gap: 10px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
}
.tour[hidden] { display: none; }
.tour__head { margin: 0; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.tour__text { margin: 0; }
.is-tour-target { outline: 3px solid var(--accent); outline-offset: 4px; border-radius: var(--radius); }
@media (max-width: 767px) { .tour { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); } }

/* Switch to another budget (shown only to people in several budgets). */
.budget-switch summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--ink-2); }
.budget-switch .stack { padding-block: 4px; }

/* «Записать» lives in the tab bar on phones, in the top bar on wider screens. */
@media (max-width: 767px) { .topbar .topbar__quick { display: none; } } /* beats .btn, loaded later */
