/* Оболочка: на телефоне шапка и нижняя навигация, на широком экране боковая панель */

.shell { min-height: 100vh; min-height: 100dvh; }

.sidebar { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 8px) 8px calc(var(--safe-left) + 16px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; margin: 0; font-size: var(--fs-xl); }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn[aria-current="page"] { color: var(--accent); }

.view {
  flex: 1;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 16px calc(var(--safe-right) + 16px) calc(var(--tabbar-h) + var(--safe-bottom) + 96px) calc(var(--safe-left) + 16px);
}
.view:focus { outline: none; }
.view > * + * { margin-top: 14px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: var(--fs-2xs);
  color: var(--muted);
  text-decoration: none;
}
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed;
  z-index: 11;
  right: calc(var(--safe-right) + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 6px 16px rgb(0 0 0 / 22%);
}
.fab svg { width: 28px; height: 28px; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; font-size: var(--fs-lg); font-weight: 700; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
}
.brand-mark svg { width: 20px; height: 20px; stroke-width: 2.6; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-sep { height: 1px; margin: 10px 12px; background: var(--border); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    padding: calc(var(--safe-top) + 20px) 12px 20px calc(var(--safe-left) + 12px);
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .tabbar, .topbar-actions { display: none; }
  .topbar { padding: 16px 32px; }
  .view { padding: 24px 32px 120px; }
  .fab { right: 32px; bottom: 32px; }
}

/* 9.1: всё в экран. Элементы сеток и флексов могут сжиматься (иначе колонку растягивает самый длинный кусок текста),
   длинные слова и ссылки переносятся, строки инструментов переносятся на узких экранах */
.view, .card, .stack, .field, .actions, .toolbar, .task-head, .task-body, .task-head-row, .meta-chips, .hints { min-width: 0; }
.card, .task-head, .task-body { grid-template-columns: minmax(0, 1fr); }
.card, .hints li, .task-meta, .note-row-title, .note-row-meta, .md, .kanban-title, .kanban-meta, .tip, .notice, .field-hint { overflow-wrap: anywhere; }
.toolbar { flex-wrap: wrap; }
.meta-chip { max-width: 100%; }
.meta-chip-text { white-space: normal; overflow-wrap: anywhere; text-align: left; }
/* Таблицы (например, в «Итогах») прокручиваются внутри себя, а не растягивают страницу */
.data-table { display: block; max-width: 100%; overflow-x: auto; }

/* 9.3: навигация как в TickTick — выдвижное меню слева, настраиваемый низ */
.side-nav { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; }
.nav-heading { margin: 14px 12px 4px; color: var(--muted); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { flex: none; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: var(--fs-xs); line-height: 20px; text-align: center; }
.nav-link .icon svg { width: 20px; height: 20px; }
.drawer {
  position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); max-width: none; height: 100%; max-height: none; margin: 0;
  padding: calc(var(--safe-top) + 16px) 12px calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 12px);
  border: 0; background: var(--surface); color: var(--text); display: none; flex-direction: column;
  box-shadow: 8px 0 24px rgb(0 0 0 / 25%);
}
.drawer[open] { display: flex; animation: drawer-in 0.18s ease-out; }
.drawer::backdrop { background: rgb(0 0 0 / 40%); }
.drawer .brand { padding-right: 0; }
.drawer-close { margin-left: auto; }
@keyframes drawer-in { from { transform: translateX(-100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .drawer[open] { animation: none; } }
.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-burger[hidden], .topbar .icon-btn[hidden] { display: none; }
/* Нижнее меню: подписи не шире ячейки даже с крупным шрифтом */
.tab { min-width: 0; padding: 0 2px; position: relative; }
.tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .icon { position: relative; }
.tab-badge { position: absolute; top: -4px; right: -10px; min-width: 16px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: var(--fs-2xs); line-height: 16px; text-align: center; }
@media (min-width: 900px) {
  .topbar-burger { display: none; }
  .sidebar .side-nav { flex: 1; }
}
.drawer:focus { outline: none; }
.fab { border: 0; cursor: pointer; font: inherit; }

/* Меню модулями: сворачиваемые группы, подпункты, закреплённые плитки (ROADMAP 17) */
.nav-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; } /* без minmax сетка растягивается под длинное название — появлялась горизонтальная прокрутка */
.nav-toggle { display: flex; align-items: center; gap: 6px; width: calc(100% - 24px); border: 0; background: none; cursor: pointer; font-family: inherit; text-align: left; padding: 0; }
.nav-toggle:hover { color: var(--text); }
.nav-caret { width: 12px; font-size: 10px; }
.nav-link.is-sub { padding-left: 34px; }
.nav-link.is-sub .icon { display: none; }
.nav-pins { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 8px 8px 4px; }
.nav-pin { display: grid; justify-items: center; gap: 4px; padding: 8px 2px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: var(--fs-xs); }
.nav-pin:hover { background: var(--surface-2); }
.nav-pin .icon, .nav-pin-glyph { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); font-size: 18px; }
.nav-pin .icon svg { width: 18px; height: 18px; }
.nav-pin-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Боковое меню: без полос прокрутки (прокрутка колёсиком и пальцем остаётся), без прокрутки вбок */
.side-nav { overflow-x: hidden; scrollbar-width: none; }
/* Пункты меню не сжимаются: с overflow у вложенного nav flex-колонка сжимала «Подключения» и «Настройки» до нуля
   (на телефоне они пропадали). Прокручивается всё меню целиком */
.side-nav > * { flex-shrink: 0; }
/* «Подключения» и «Настройки» — всегда видны внизу меню */
.nav-footer { position: sticky; bottom: 0; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--border); background: var(--surface); }
.side-nav::-webkit-scrollbar { display: none; }
.nav-link { min-width: 0; }

/* Закреплённое и папки, раскрытие типов заметок (ROADMAP 18) */
.nav-row { position: relative; display: flex; align-items: center; min-width: 0; }
.nav-row > .nav-link { flex: 1; }
.nav-row:has(.nav-more:not(.nav-expand)) > .nav-link { padding-right: 36px; }
.nav-more { flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-left: -32px; margin-right: 4px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 14px; opacity: 0; }
.nav-more .icon, .nav-more svg { width: 16px; height: 16px; }
.nav-row:hover .nav-more, .nav-more:focus-visible, .nav-expand { opacity: 1; }
.nav-more:hover { background: var(--surface-2); color: var(--text); }
.nav-expand { position: static; margin-left: 0; }
.nav-row:has(.nav-expand) > .nav-link { padding-right: 4px; }
@media (hover: none) { .nav-more { opacity: 1; } }
.nav-folder { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; text-align: left; }
.nav-folder .nav-caret { margin-left: auto; color: var(--muted); }
.nav-link.is-deep { padding-left: 50px; font-size: var(--fs-sm); color: var(--muted); }
.nav-link.is-deep .icon { display: none; }
.nav-link.is-done .nav-label { text-decoration: line-through; color: var(--muted); }
.nav-glyph { display: inline-grid; place-items: center; width: 20px; font-size: 16px; line-height: 1; }
.nav-empty { margin: 2px 12px 6px 34px; color: var(--muted); font-size: var(--fs-xs); }
.pin-btn.is-on { color: var(--accent); }
/* Переход между экранами — мягко, без рывка (ROADMAP 19) */
.view.is-entering { animation: view-in 0.16s ease-out; }
@keyframes view-in { from { opacity: 0.4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view.is-entering { animation: none; } }
