/* App shell (design/src/frame.py, mobile.py; Э-1.2, Э-1.4): header 64, nav 236, filter bar 114,
   content padding 24/32/32. Phone ≤ 767 px: header 56, bottom nav 64, filter sheet. */

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--bg); }

/* ---------------------------------------------------------------- header */
.hdr {
  flex-shrink: 0; height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.hdr__brand { display: flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; min-width: 0; }
.hdr__brand:hover { color: var(--ink); }
.hdr__divider { width: 1px; height: 28px; background: var(--line-2); flex-shrink: 0; }
.hdr__title { font-family: var(--font-display); font-size: 16px; line-height: 1.1; color: var(--ink-2); white-space: nowrap; }
.hdr__right { display: flex; align-items: center; gap: 16px; min-width: 0; }
.hdr__search { width: 300px; }
.hdr__user { display: flex; align-items: center; gap: 10px; min-width: 0; padding-left: 16px; border-left: 1px solid var(--line); }
.hdr__who { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
.hdr__name { max-width: 100%; font-size: 13px; line-height: 16px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* a long name must not push the header out of the window: the search gives way first, then the name is cut */
.hdr__right > .help-pair:first-child { flex-shrink: 1; min-width: 0; }
.hdr__right > .help-pair:first-child .hdr__search { flex-shrink: 1; min-width: 120px; }
.hdr__role { font-size: 11px; line-height: 14px; color: var(--ink-3); }

/* ---------------------------------------------------------------- body: nav + main */
.app__body { flex-grow: 1; min-height: 0; display: flex; align-items: stretch; }

.nav {
  flex-shrink: 0; width: 236px; display: flex; flex-direction: column; padding-top: 12px;
  background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
}
.nav__item {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 16px;
  background: transparent; color: var(--ink); font-size: 14px; font-weight: 400; text-decoration: none;
  border-left: 3px solid transparent;
}
.nav__item:hover { color: var(--ink); }
.nav__item[aria-current="page"] { background: var(--accent-soft); color: var(--on-soft); font-weight: 500; border-left-color: var(--accent); }
.nav__item[aria-current="page"] .help-dot { color: var(--on-soft); }
.nav__label { flex-grow: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__foot { margin-top: auto; padding: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.nav__foot-label { font-size: 11px; line-height: 14px; color: var(--ink-3); }
.nav__foot-value { font-size: 12px; line-height: 16px; color: var(--ink-2); }

.main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); overflow-y: auto; }
.content { flex-grow: 1; padding: 24px 32px 32px 32px; display: flex; flex-direction: column; gap: 20px; }

/* ---------------------------------------------------------------- filter bar */
.fbar {
  flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 32px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.fbar__row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.fbar__grow { flex-grow: 1; }
.fbar__switches { display: flex; align-items: center; gap: 14px; }
.fbar__gap { width: 14px; flex-shrink: 0; }
.fbar__pair { display: inline-flex; align-items: center; gap: 4px; }
.scope-chip { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; background: var(--warn-bg); color: var(--warn-ink); font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.fchip--chat { width: 236px; }
.fchip--chat-wide { width: 262px; }
.fchip--brand { min-width: 116px; }
.fchip--circuit { min-width: 122px; }
.fchip--dates { width: 196px; }
/* «Обновить сегодня» with its state (element-map period_group, 27.09) */
.fchip--dates-one { width: 150px; }
.fbar__stepday { display: inline-flex; align-items: center; height: 38px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.refresh-today { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.refresh-today__main { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.refresh-today__state { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

/* ---------------------------------------------------------------- mobile pieces (hidden on desktop) */
.mhdr, .mnav, .mfilter, .sheet { display: none; }

/* ---------------------------------------------------------------- tablet: 768–1279 */
@media (max-width: 1279px) and (min-width: 768px) {
  .nav { width: 64px; }
  .nav__item { justify-content: center; padding: 0; }
  .nav__label, .nav .help-dot, .nav__foot { display: none; }
  .hdr__search { width: 196px; }
  .fbar { padding: 14px 24px; }
  .fbar__row { flex-wrap: wrap; }
  .content { padding: 24px; }
  .kpi-row { flex-wrap: wrap; }
  .kpi-row .kpi { flex-basis: calc(33.333% - 11px); }
}

/* ---------------------------------------------------------------- phone: ≤ 767 (element-map §3) */
@media (max-width: 767px) {
  .hdr, .nav, .fbar, .page-title__right { display: none; }
  .app { height: auto; min-height: 100vh; min-height: 100dvh; }
  .app__body { display: block; }
  .main { overflow: visible; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .content { padding: 16px; gap: 12px; }

  .mhdr {
    display: flex; position: sticky; top: 0; z-index: 20; height: 56px; align-items: center; gap: 4px;
    padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .mhdr__title {
    flex-grow: 1; min-width: 0; font-family: var(--font-display); font-size: 19px; color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mhdr__btn {
    display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex-shrink: 0;
    margin-right: -12px; background: transparent; border: 0; color: var(--ink-2);
  }
  .mhdr__btn + .mhdr__btn { margin-left: 12px; }
  .mhdr .help-pair .mhdr__btn { margin-right: -10px; }
  .mhdr .help-pair + .help-pair { margin-left: 6px; }
  .mhdr__back { margin: 0 0 0 -12px; color: var(--ink); }
  .mhdr__back .ico { transform: rotate(90deg); }

  .mnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; align-items: stretch;
    height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .mnav__item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--ink-3); text-decoration: none; font-size: 11px; line-height: 14px;
  }
  .mnav__item:hover { color: var(--ink-3); }

  /* a tap zone of at least 44×44 around small controls (E0-08, EM §1.6 and §3): the look does not change */
  .help-dot, .icon-act, .tour__skip, .btn, .mtab, .segmented__btn, .due-chip, .toggle, .checkbox, .date-input__btn,
  .sheet__period > button, .login__row a, .dash--why { position: relative; }
  .help-dot::after, .icon-act::after, .tour__skip::after, .btn::after, .mtab::after, .segmented__btn::after, .due-chip::after,
  .toggle::after, .checkbox::after, .date-input__btn::after, .sheet__period > button::after, .login__row a::after, .dash--why::after {
    content: ''; position: absolute; left: 50%; top: 50%; width: max(100%, 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
  }
  .mnav__item[aria-current="page"], .mnav__item[aria-current="page"]:hover { color: var(--accent); font-weight: 500; }

  .mfilter {
    display: flex; align-items: center; gap: 8px; width: 100%; height: 44px; padding: 0 12px;
    background: var(--surface); border: 1px solid var(--line-2); border-radius: 0;
    color: var(--ink); font-size: 13px; text-align: left;
  }
  .mfilter__text { flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mfilter .ico { color: var(--ink-2); }
  .mswitch { display: flex; align-items: center; gap: 4px; }

  .sheet[data-open="true"] {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto;
  }
  .sheet__body { flex-grow: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
  /* six (reach: seven) period buttons in a 3-column grid, 40 high (Э-1.4, v70) */
  .sheet__period { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line-2); border-left: 1px solid var(--line-2); }
  .sheet__period button {
    display: flex; align-items: center; justify-content: center; height: 40px; padding: 0;
    font-size: 13px; background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2);
  }
  .sheet__period button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
  .sheet__dates { display: flex; gap: 10px; }
  .sheet__chatbox { background: var(--surface); border: 1px solid var(--line-2); }
  .sheet__chats {
    display: flex; align-items: center; justify-content: space-between; width: 100%; height: 44px; padding: 0 12px;
    background: transparent; color: var(--ink); border: 0; border-radius: 0; font-size: 14px; text-align: left;
  }
  .sheet__chats .ico { color: var(--ink-2); }
  .sheet__chats--open .ico { transform: rotate(180deg); }
  .sheet__chatrow { display: flex; align-items: center; height: 44px; padding: 0 12px; border-top: 1px solid var(--line-2); }
  .sheet__chatrow .checkbox { width: 100%; height: 100%; }
  .sheet__chatrow .brand-chip { font-size: 14px; }
  .sheet__dates .field { flex: 1 1 0; min-width: 0; }
  .sheet__foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
  .sheet .field__input, .sheet .select select { height: 44px; }
  .sheet .select .ico { top: 12px; }

  .page-title h1 { font-size: 24px; line-height: 28px; }
  .kpi-row { flex-wrap: wrap; gap: 10px; }
  .kpi-row .kpi { flex: 1 1 calc(50% - 5px); padding: 12px; gap: 4px; }
  .kpi-row .kpi__label { font-size: 11px; }
  .kpi-row .kpi__value { font-size: 26px; }

  /* «Ещё» (М-1, phone 4) */
  .more { display: flex; flex-direction: column; gap: 6px; }
  .more__profile { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); }
  .more__avatar {
    width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--on-soft); font-family: var(--font-display); font-size: 18px;
  }
  .more__name { font-size: 15px; font-weight: 500; }
  .more__sub { font-size: 12px; color: var(--ink-3); }
  .more__list { display: flex; flex-direction: column; gap: 5px; }
  .mrow {
    display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 44px;
    background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
  }
  .mrow:hover { color: var(--ink); }
  .mrow__main { flex-grow: 1; min-width: 0; font-size: 14px; }
  .mrow__sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
  .mrow__right { flex-shrink: 0; font-size: 14px; font-weight: 500; color: var(--ink); }
  .msection { font-family: var(--font-display); font-size: 17px; font-weight: 400; color: var(--ink); margin-top: 6px; }
  .more__exit { margin-top: 12px; }
}

@media (min-width: 768px) { .more { display: none; } }
