/* LMail 2.0 — application shell: sidebar, header, bottom tab bar.
   Package A put here only the portal carry-over (phase-one.css:1-47, 235-243,
   282-291, 385-407, 647-689; globals.css:2939-2964, 4719-4741) and the shell
   recipes of SPEC-UI 2.4. Layout heights/columns of sections 3.2-3.4 belong
   to package B, which owns this file after package A is delivered. */

/* ── Frame and sidebar ── */
.app-frame { min-height: 100vh; min-height: 100dvh; --sidebar-width: 248px; }
.app-frame[data-collapsed="true"] { --sidebar-width: 68px; }
.app-main { min-width: 0; padding-left: 248px; }
.app-main > main { min-height: calc(100vh - 72px); min-height: calc(100dvh - 72px); }

.tech-sidebar { position: fixed; inset: 0 auto 0 0; z-index: var(--lm-z-sidebar); width: 248px; display: flex; flex-direction: column; border-right: 1px solid var(--border-color); background: var(--lm-sidebar-bg); box-shadow: var(--lm-sidebar-shadow); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.tech-brand { height: 72px; flex: 0 0 72px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border-color); }
.tech-brand > a { display: flex; align-items: center; gap: 11px; color: var(--text-primary); text-decoration: none; }
.tech-brand > button { display: none; margin-left: auto; color: var(--text-secondary); }

.tech-sidebar > nav { display: flex; flex-direction: column; gap: 16px; padding: 18px 12px 12px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.nav-group { display: grid; gap: 4px; }
.nav-group-label { display: flex; align-items: center; padding: 4px 13px 2px; color: var(--text-muted); font: 700 12px/1 "JetBrains Mono", monospace; letter-spacing: .14em; text-transform: uppercase; }
.tech-sidebar > nav a, .tech-sidebar > nav span:where(.lm-folder) { position: relative; min-height: 42px; display: flex; align-items: center; gap: 13px; padding: 0 13px; border: 1px solid transparent; color: var(--text-secondary); font: 650 14.5px/1 "Space Grotesk", sans-serif; letter-spacing: .03em; text-decoration: none; transition: 160ms ease; }
.tech-sidebar > nav a:hover { border-color: var(--line); background: var(--lm-nav-hover); color: var(--text-primary); }
@media (max-width: 820px), (max-height: 500px) { .tech-sidebar > nav a, .tech-sidebar > nav span:where(.lm-folder) { min-height: 44px; } }
.tech-sidebar > nav a[data-active="true"] { border-color: var(--lm-nav-active-border); background: linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 12%, transparent), transparent); color: var(--lm-accent-ink); }
.tech-sidebar > nav a[data-active="true"]::before { position: absolute; left: -13px; width: 2px; height: 26px; background: var(--accent-primary); box-shadow: 0 0 13px var(--accent-primary); content: ""; }
.tech-sidebar > nav a i { width: 3px; height: 3px; margin-left: auto; border-radius: 50%; background: currentColor; opacity: .25; }
/* globals.css:2939-2964 */
.tech-sidebar > nav { padding-left: 14px; overflow-x: hidden; }
.tech-sidebar > nav a, .tech-sidebar > nav span:where(.lm-folder) { min-width: 0; padding-block: 9px; }
.tech-sidebar > nav a > svg, .tech-sidebar > nav span:where(.lm-folder) > svg { flex: 0 0 auto; }
.tech-sidebar > nav a > span { min-width: 0; line-height: 1.3; overflow-wrap: break-word; }

/* Account block */
.sidebar-profile { width: 100%; min-height: 72px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-top: 1px solid var(--border-color); color: var(--text-primary); text-align: left; text-decoration: none; }
.sidebar-profile > span, .hex-avatar { width: 35px; height: 39px; display: grid; place-items: center; clip-path: polygon(50% 0, 94% 24%, 94% 76%, 50% 100%, 6% 76%, 6% 24%); background: var(--lm-hex-bg); color: #fff; font: 700 12.5px/1 "JetBrains Mono", monospace; }
.sidebar-profile > span { flex: 0 0 auto; overflow: hidden; }
.sidebar-profile > div { min-width: 0; flex: 1; }
.sidebar-profile strong, .sidebar-profile small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-profile strong { font-size: 13px; } .sidebar-profile small { margin-top: 4px; color: var(--text-muted); font-size: 12px; }
.sidebar-profile > svg { flex: 0 0 auto; color: var(--text-muted); }
.sidebar-account { flex: 0 0 auto; border-top: 1px solid var(--border-color); }
.sidebar-account .sidebar-profile { border-top: 0; }
.sidebar-logout { width: 100%; min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px 12px; border: 0; background: transparent; color: var(--text-muted); font: 12px/1 "JetBrains Mono", monospace; letter-spacing: .1em; text-transform: uppercase; cursor: pointer; transition: color 140ms ease; }
.sidebar-logout:hover:not(:disabled) { color: var(--lm-danger-ink); }
.sidebar-logout:disabled { cursor: not-allowed; opacity: .5; }

/* Collapse button and collapsed state — phase-one.css:647-689 */
.tech-brand > button.sidebar-collapse { display: grid; place-items: center; width: 28px; height: 28px; margin-left: auto; border: 1px solid transparent; color: var(--text-muted); transition: 140ms ease; }
.tech-brand > button.sidebar-collapse:hover { border-color: var(--line-strong); color: var(--lm-accent-ink); }

@media (min-width: 821px) {
  .tech-sidebar { width: var(--sidebar-width); transition: width 180ms ease; }
  .app-main { padding-left: var(--sidebar-width); transition: padding-left 180ms ease; }

  .app-frame[data-collapsed="true"] .tech-brand { padding: 0 10px; }
  .app-frame[data-collapsed="true"] .tech-brand > a { display: none; }
  .app-frame[data-collapsed="true"] .tech-brand > button.sidebar-collapse { margin: 0 auto; }

  .app-frame[data-collapsed="true"] .tech-sidebar > nav { padding: 14px 8px 10px; gap: 10px; }
  .app-frame[data-collapsed="true"] .tech-sidebar > nav a,
  .app-frame[data-collapsed="true"] .tech-sidebar > nav span:where(.lm-folder) { justify-content: center; padding: 0; }
  .app-frame[data-collapsed="true"] .tech-sidebar > nav a > span,
  .app-frame[data-collapsed="true"] .tech-sidebar > nav a > i,
  .app-frame[data-collapsed="true"] .nav-group-label,
  .app-frame[data-collapsed="true"] .sidebar-profile > div,
  .app-frame[data-collapsed="true"] .sidebar-profile > svg,
  .app-frame[data-collapsed="true"] .sidebar-logout span { display: none; }
  .app-frame[data-collapsed="true"] .tech-sidebar > nav a[data-active="true"]::before { left: -8px; }
  .app-frame[data-collapsed="true"] .sidebar-profile { justify-content: center; padding: 0; }
  .app-frame[data-collapsed="true"] .sidebar-logout { justify-content: center; }
}

/* ── Header ── */
.tech-header { position: sticky; top: 0; z-index: var(--lm-z-header); height: calc(var(--lm-header-h) + env(safe-area-inset-top)); display: flex; align-items: center; gap: 20px; padding: env(safe-area-inset-top) 28px 0; border-bottom: 1px solid var(--border-color); background: var(--lm-header-bg); box-shadow: var(--lm-header-shadow); backdrop-filter: blur(18px); }
.header-menu { display: none; color: var(--text-primary); }
.header-search { width: min(470px, 50vw); height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1px solid var(--border-color); border-radius: var(--r-xl); background: var(--lm-control-bg); color: var(--text-secondary); text-align: left; transition: 160ms ease; }
.header-search:hover { border-color: color-mix(in srgb, var(--accent-primary) 35%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--accent-primary) 6%, transparent); }
.header-search span { flex: 1; font-size: 14px; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.header-actions > button { height: 38px; display: flex; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid var(--border-color); background: var(--lm-control-bg); color: var(--text-secondary); font: 600 12.5px/1 "JetBrains Mono", monospace; }
.header-actions > button:hover { border-color: var(--line-strong); color: var(--lm-accent-ink); }
.header-actions > button > kbd { padding: 0; border: 0; color: inherit; }
.network-status { display: flex; align-items: center; gap: 7px; margin-right: 8px; color: var(--text-muted); font: 12px/1 "JetBrains Mono", monospace; }
.network-status i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-tertiary); box-shadow: 0 0 8px var(--accent-tertiary); }
.network-status[data-state="offline"] i { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.network-status[data-state="syncing"] i { background: var(--accent-primary); box-shadow: 0 0 8px var(--accent-primary); }

/* ── Phone: drawer menu and bottom tab bar ── */
.mobile-tabbar { display: none; }
.sidebar-scrim { display: none; }

@media (max-width: 820px) {
  .app-main { padding-left: 0; padding-bottom: calc(var(--lm-tabbar-h) + env(safe-area-inset-bottom)); }
  .tech-sidebar { transform: translateX(-105%); transition: transform 180ms ease; }
  .tech-sidebar.is-open { transform: translateX(0); }
  .tech-brand > button { display: block; }
  .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: var(--lm-z-scrim); background: var(--lm-scrim); }
  .header-menu { display: block; }
  .network-status { display: none; }
  .mobile-tabbar { position: fixed; inset: auto 0 0; z-index: var(--lm-z-scrim); height: calc(var(--lm-tabbar-h) + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--border-color); background: var(--lm-tabbar-bg); box-shadow: var(--lm-tabbar-shadow); backdrop-filter: blur(15px); }
  .mobile-tabbar :is(a, button) { position: relative; display: grid; place-items: center; align-content: center; gap: 5px; color: var(--text-muted); font-size: 12px; text-align: center; text-decoration: none; }
  .mobile-tabbar :is(a, button)[data-active="true"] { color: var(--accent-primary); }
  .mobile-tabbar :is(a, button)[data-active="true"]::before { position: absolute; top: 0; width: 35%; height: 1px; background: var(--accent-primary); box-shadow: 0 0 8px var(--accent-primary); content: ""; }
}
@media (max-width: 560px), (max-height: 500px) {
  :root { --lm-header-h: 62px; }
}
@media (max-width: 560px) {
  .tech-header { padding-left: 14px; padding-right: 14px; gap: 10px; }
  .header-search { width: 40px; padding: 0; justify-content: center; }
  .header-search span, .header-search kbd, .header-actions > button span { display: none; }
  .header-actions > button { width: 38px; justify-content: center; padding: 0; }
}
/* phase-one.css:385-407 — touch targets of 44px */
@media (max-width: 820px) {
  .header-menu,
  .header-search,
  .header-actions > button { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .header-menu { display: inline-flex; }
  .header-search { width: auto; padding: 0 12px; }
  .tech-brand > button.sidebar-collapse { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tech-sidebar, .app-main { transition: none; }
}

/* ── Logo (mask) — globals.css:4719-4741; widths as currently published on lapis.kz ── */
.lapis-logo { width: 154px; aspect-ratio: 413 / 165; display: block; flex: 0 0 auto; background: linear-gradient(105deg, var(--text-primary) 0 68%, var(--accent-primary) 100%); -webkit-mask: url("../lapis-logo.png") center / contain no-repeat; mask: url("../lapis-logo.png") center / contain no-repeat; }
.lapis-logo--header { width: 97.5px; }
.lapis-logo--auth { width: min(117px, 70vw); }

/* ── LMail shell elements (SPEC-UI 2.4) ── */
.lm-brand-tag { margin-left: 8px; color: var(--lm-accent-ink); font: 700 12px/1 var(--font-mono); letter-spacing: .14em; }
.lm-sidebar-close { display: none; width: 44px; height: 44px; place-items: center; margin-left: auto; color: var(--text-secondary); }
.lm-compose-wrap { flex: 0 0 auto; padding: 14px 14px 0; }
.lm-compose-btn { width: 100%; min-height: 44px; justify-content: center; }
.lm-folder-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); }
.lm-folder { min-width: 0; }
.app-frame:not([data-collapsed="true"]) .lm-folder { padding-left: calc(13px + var(--lm-depth, 0) * 14px); }
.lm-folder__name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lm-folder[aria-disabled="true"] { opacity: .55; cursor: default; }
.lm-folder__more { position: absolute; right: 6px; top: 50%; translate: 0 -50%; width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: var(--r-sm); color: var(--text-muted); opacity: 0; }
.lm-folder-row:hover .lm-folder__more, .lm-folder-row:focus-within .lm-folder__more, .lm-folder__more[aria-expanded="true"] { opacity: 1; }
.lm-folder-row:hover .lm-badge, .lm-folder-row:focus-within .lm-badge { margin-right: 32px; }
.lm-folder__more:hover { color: var(--lm-accent-ink); background: var(--lm-nav-hover); }
.lm-folder-add { width: 28px; height: 28px; display: inline-grid; place-items: center; margin-left: auto; border-radius: var(--r-sm); color: var(--text-muted); }
.lm-folder-add:hover { color: var(--lm-accent-ink); }
/* Collapsed menu (desktop only): an unread dot on the icon instead of the badge */
@media (min-width: 821px) {
  .app-frame[data-collapsed="true"] .lm-compose-wrap { padding: 14px 12px 0; }
  .app-frame[data-collapsed="true"] .lm-compose-btn { width: 44px; padding: 0; } .app-frame[data-collapsed="true"] .lm-compose-btn > span { display: none; }
  .app-frame[data-collapsed="true"] :is(.lm-folder__more, .lm-folder-add, .lm-folder__name, .lm-badge) { display: none; }
  .app-frame[data-collapsed="true"] .lm-folder[data-has-unread="true"]::after { content: ""; position: absolute; top: 9px; right: 14px; width: 6px; height: 6px;
    border-radius: 50%; background: var(--accent-secondary); }
}
/* Search: an input inside .header-search */
.lm-search { background: var(--lm-control-bg); }
.lm-search:focus-within { border-color: var(--accent-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 15%, transparent); }
.lm-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text-primary); font: 14px/1 var(--font-sans); }
.lm-search input::-webkit-search-cancel-button { display: none; }
.lm-search__clear { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); color: var(--text-muted); }
.lm-search__open { display: none; }
.lm-search__back { width: 44px; height: 44px; flex: none; display: grid; place-items: center; margin-left: -10px; color: var(--text-secondary); }
.lm-offline, .lm-demo { margin: 10px 18px 0; }
.lm-tabbar__compose > svg { width: 44px; height: 44px; padding: 11px; border-radius: 50%; color: var(--lm-on-accent);
  background: linear-gradient(135deg, var(--accent-primary), var(--lm-accent-deep)); }
.lm-tabbar__badge { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; border-radius: 999px; background: var(--accent-secondary); color: var(--lm-on-accent); font: 700 12px/1 "JetBrains Mono", monospace; font-style: normal; }
@media (max-width: 820px) { .lm-sidebar-close { display: grid; } .sidebar-collapse { display: none; }
  .tech-sidebar .lm-folder { padding-left: calc(13px + var(--lm-depth, 0) * 14px); }
  .lm-folder__more { opacity: 1; width: 44px; height: 44px; right: 2px; } .lm-folder-row .lm-badge { margin-right: 46px; }
  .lm-folder-add { width: 44px; height: 44px; margin-block: -10px; }
  .lm-search input { font-size: 16px; } .lm-search__clear { width: 44px; height: 44px; } .lm-offline, .lm-demo { margin: 8px 10px 0; } }
/* The is-search-open class is set on .tech-header (it may also be set on .lm-search itself). */
@media (max-width: 560px) { .tech-header:not(.is-search-open) .lm-search:not(.is-search-open) { width: 44px; padding: 0; border: 0; background: transparent; box-shadow: none; }
  .tech-header:not(.is-search-open) .lm-search:not(.is-search-open) :is(input, kbd, .lm-search__clear) { display: none; }
  .tech-header:not(.is-search-open) .lm-search:not(.is-search-open) > svg { display: none; }
  .tech-header:not(.is-search-open) .lm-search:not(.is-search-open) .lm-search__open { display: grid; width: 44px; height: 44px; place-items: center; }
  .tech-header.is-search-open .lm-search { flex: 1; } .tech-header.is-search-open :is(.header-menu, .header-actions) { display: none; } }

/* ── Package B: layout by height (SPEC-UI 3.2 «Раскладка по высоте»), no calc() ── */
.app-frame { min-height: 0; height: 100vh; height: 100dvh; }
.app-main { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.app-main > main { min-height: 0; }
.tech-header, .lm-offline, .lm-demo { flex: none; }
#lm-main { flex: 1; min-height: 0; display: flex; flex-direction: column; outline: none; }
.lm-mail { flex: 1; min-height: 0; display: flex; padding: 14px 18px 18px; }
#lm-settings { flex: 1; min-height: 0; overflow-y: auto; }
.lm-search__back { margin-left: -6px; }
.lm-search:not(.is-search-open) .lm-search__back { display: none; }
.lm-folders__error { margin: 6px 13px; color: var(--lm-danger-ink); font-size: 12.5px; }
#lm-refresh.is-spinning > svg { animation: lm-spin 1s linear infinite; }
.tech-sidebar > nav a > span.lm-badge { flex: none; line-height: 1.3; }
.tech-sidebar > nav :is(a, span).lm-folder { padding-right: 10px; }
.sidebar-profile > div > strong { color: var(--text-primary); }
@media (min-width: 821px) and (max-width: 1199px) { .network-status span { display: none; } .network-status { margin-right: 0; } }
@media (min-width: 821px) {
  .app-frame[data-collapsed="true"] .tech-sidebar > nav :is(a, span).lm-folder { padding: 0; justify-content: center; }
}
@media (max-width: 820px) {
  .tech-brand > a { display: flex; }
  .header-actions > button#lm-help-btn { display: none; }
  .tech-header { padding-left: 14px; padding-right: 14px; gap: 10px; }
  .lm-mail { padding: 0; }
  /* an open message on the phone: the shell header and the tab bar give way to the message panels */
  #lm-frame[data-view="room"] .tech-header, #lm-frame[data-view="room"] .mobile-tabbar,
  #lm-frame[data-view="room"] .lm-offline, #lm-frame[data-view="room"] .lm-demo { display: none; }
  #lm-frame[data-view="room"] .app-main { padding-bottom: 0; }
  .mobile-tabbar :is(a, button) { min-height: 44px; }
}
@media (max-width: 560px) {
  .header-actions > button#lm-lang-btn span { display: none; }
}
