/*
 * host123 Webmail layout (§29.3): the application shell, the mail panes, the compose dock, the
 * floating compose button and safe areas. Mobile first:
 *   < 768 px     single pane, bottom navigation bar, folder tree in a drawer, .fab, full-screen compose
 *   768–1023 px  nav rail + two panes (list + reader), folder tree in a drawer
 *   1024–1279 px nav rail + two panes, the sidebar stays collapsed (drawer on demand)
 *   ≥ 1280 px    nav rail + sidebar + list + reader
 * The DOM contract is documented in docs/packages/P04a.md ("Layout classes").
 * Safe areas need <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">.
 */

/* ---------------------------------------------------------------- shell grid */

.app-shell {
  display: grid;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows:
    var(--shell-top, calc(var(--topbar-h) + env(safe-area-inset-top, 0px)))
    minmax(0, 1fr)
    calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  grid-template-areas:
    "topbar"
    "content"
    "rail";
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
}

/* Full-screen views on phones (reader, compose): the bottom bar steps aside.
   (:has() rules are kept separate so older engines still apply the class-based ones.) */
.app-shell.is-immersive {
  grid-template-rows:
    var(--shell-top, calc(var(--topbar-h) + env(safe-area-inset-top, 0px)))
    minmax(0, 1fr)
    0;
}
.app-shell:has(.mail-layout.is-reading) {
  grid-template-rows:
    var(--shell-top, calc(var(--topbar-h) + env(safe-area-inset-top, 0px)))
    minmax(0, 1fr)
    0;
}
.app-shell.is-immersive .nav-rail {
  display: none;
}
.app-shell:has(.mail-layout.is-reading) .nav-rail {
  display: none;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  grid-area: topbar;
  position: relative;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: env(safe-area-inset-top, 0px) var(--space-2) 0;
}

.topbar-start,
.topbar-end {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}
/* The logo keeps one size while navigating. On phones the brand gives way only when the bar is crowded (e.g. the
   vacation badge, the AI credits and the app button at once) and then alike on every page: pages without search keep
   the search button's place (invisible, topbar.js), so the logo never changes size between the mail and other pages.
   From 768px the search field shrinks instead of the brand. */
.topbar-start {
  flex: 0 1 auto;
}
.topbar-end {
  margin-inline-start: auto;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow: hidden;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}
.topbar-logo {
  display: block;
  width: auto;
  height: 28px;
  max-width: min(160px, 100%);
  object-fit: contain;
  object-position: left center;
}

.topbar-search {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 720px;
}
.topbar .topbar-search-toggle {
  display: inline-flex;
}
/* A page without search keeps the button's place, so the logo has the same room on every page. */
.topbar .topbar-search-toggle.is-idle {
  visibility: hidden;
}

/* Phones: the search opens as a row of its own below the header; the header keeps its buttons and the content moves
   down by the row (the shell's first row grows through --shell-top, see the phone block). */
.topbar.is-searching {
  flex-wrap: wrap;
  align-content: flex-start;
  row-gap: 0;
}
.topbar.is-searching > .topbar-start,
.topbar.is-searching > .topbar-end {
  min-height: var(--topbar-h);
}
/* A wrapping line does not shrink its items: the brand starts from zero, so the header stays on the first line. */
.topbar.is-searching > .topbar-start {
  flex: 1 1 0;
}
.topbar.is-searching .topbar-search {
  display: flex;
  order: 3;
  flex: 1 1 100%;
  max-width: none;
  align-items: center;
  min-height: calc(var(--touch-min) + var(--space-3));
  padding-bottom: var(--space-2);
}

.topbar .topbar-menu-btn {
  display: inline-flex;
}

/* ---------------------------------------------------------------- navigation rail / bottom bar */

.nav-rail {
  grid-area: rail;
  z-index: var(--z-sticky);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-1) var(--space-1) env(safe-area-inset-bottom, 0px);
  background: var(--surface-strong);
  border-top: 1px solid var(--border);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

.nav-item {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: var(--touch-min);
  padding: var(--space-1);
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: var(--lh-tight);
  text-align: center;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item .icon {
  width: var(--icon-lg);
  height: var(--icon-lg);
  padding: 2px;
  border-radius: var(--radius-full);
}
.nav-item:hover {
  color: var(--text);
  background: var(--row-hover);
}
/* Inset ring: the rail scrolls (overflow) and would clip an outer one. */
.nav-item:focus-visible {
  outline-offset: -2px;
}
.nav-item[aria-current="page"],
.nav-item.is-active {
  color: var(--brand-text);
}
.nav-item[aria-current="page"] .icon,
.nav-item.is-active .icon {
  background: var(--brand-soft);
}
/* No extra child (a lock badge, §9.6) may shrink the label away: overflow: hidden makes its
   automatic min-height 0, so without flex-shrink: 0 the column flexbox squeezes it to nothing. */
.nav-label {
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The lock badge sits centred under the label (the rail); its inline start margin would push it off centre. */
.nav-item > .badge-lock {
  margin: 0;
}
/* Its lock is not a nav icon: without the nav icon's size and padding (which squeezed it to a dot). */
.nav-item > .badge-lock .icon {
  width: 11px;
  height: 11px;
  padding: 0;
  border-radius: 0;
}
.nav-badge {
  position: absolute;
  top: 2px;
  inset-inline-start: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--danger-solid);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  line-height: 18px;
  text-align: center;
}
.nav-spacer {
  display: none;
}
/* Rail-only items (registerNavItem bottomBar: false, e.g. the plan) stay out of the phone bottom bar. */
.nav-item[data-rail-only] {
  display: none;
}
/* "Atsijungti" at the end of the rail is a button styled like the links. */
button.nav-item {
  width: 100%;
  font-family: inherit;
  cursor: pointer;
}
/* Sign out next to the account button: phones keep it in the account menu (the bar has no room). */
.topbar .topbar-logout {
  display: none;
}

/* ---------------------------------------------------------------- sidebar (folder pane) */

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  width: min(var(--drawer-w), 86vw);
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-3)) 0 env(safe-area-inset-bottom, 0px);
  padding-inline-start: env(safe-area-inset-left, 0px);
  background: var(--surface-strong);
  border-inline-end: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
}
.sidebar.is-open {
  transform: none;
  visibility: visible;
  transition: transform var(--dur) var(--ease), visibility 0s;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-drawer) - 1);
  background: var(--backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}
.sidebar-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur) var(--ease), visibility 0s;
}

.sidebar-header {
  flex: none;
  padding: 0 var(--space-3) var(--space-3);
}
.sidebar-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 var(--space-2);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-footer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}
.sidebar-section + .sidebar-section {
  margin-top: var(--space-3);
}
.sidebar-heading {
  margin: 0;
  padding: var(--space-2) var(--space-3) var(--space-1);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- content area and generic views */

.content {
  grid-area: content;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.content:focus {
  outline: none;
}
.content:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

.view {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.view-header {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
}
.view-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
}
.view-toolbar {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}
/* A toolbar placed in the header row (e.g. a refresh button next to the title) is part of the header: no own
   padding or bottom line (that line looked like a stray underline below the button). */
.view-header > .view-toolbar {
  padding: 0;
  border-bottom: 0;
}
.view-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.view-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

/* ---------------------------------------------------------------- mail panes */

.mail-layout {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.list-pane,
.reader-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

/* Phones and list_only: one pane at a time. */
.list-pane {
  flex: 1 1 auto;
}
.reader-pane {
  display: none;
  flex: 1 1 auto;
}
.mail-layout.is-reading .list-pane {
  display: none;
}
.mail-layout.is-reading .reader-pane {
  display: flex;
}
.mail-layout > .split-handle {
  display: none;
}
.mail-layout .reader-back {
  display: inline-flex;
}

.pane-toolbar {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  min-height: 48px;
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border);
}
.pane-toolbar-spacer {
  flex: 1 1 auto;
}
.pane-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pane-footer {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* ---------------------------------------------------------------- compose dock */

.compose-dock {
  position: fixed;
  inset-inline-end: calc(var(--space-4) + env(safe-area-inset-right, 0px));
  bottom: 0;
  z-index: var(--z-dock);
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  gap: var(--space-3);
  max-width: calc(100vw - var(--space-8));
  pointer-events: none;
}
.compose-dock:empty {
  display: none;
}

.dock-window {
  display: flex;
  flex-direction: column;
  width: var(--compose-w);
  max-width: 100%;
  height: min(var(--compose-h), calc(100vh - var(--topbar-h) - var(--space-4)));
  height: min(var(--compose-h), calc(100dvh - var(--topbar-h) - var(--space-4)));
  overflow: hidden;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  pointer-events: auto;
  animation: wm-slide-up var(--dur) var(--ease);
}
.dock-window-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  height: var(--compose-bar-h);
  padding-inline: var(--space-4) var(--space-1);
  background: var(--btn-primary-bg);
  color: var(--text-inverse);
  cursor: default;
}
.dock-window-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  /* The bar's light text on the brand gradient (the heading rule of base.css would make it dark). */
  color: inherit;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dock-window-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
}
.dock-window-header .btn-ghost,
.dock-window-header .btn-icon {
  color: var(--text-inverse);
}
.dock-window-header .btn-ghost:hover,
.dock-window-header .btn-icon:hover {
  background: var(--on-brand-hover);
}
.dock-window-header :focus-visible {
  outline-color: var(--text-inverse);
}
.dock-window-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.dock-window-footer {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
}

.dock-window.is-minimized {
  width: 280px;
  height: var(--compose-bar-h);
}
.dock-window.is-minimized .dock-window-header {
  cursor: pointer;
}
.dock-window.is-minimized > :not(.dock-window-header) {
  display: none;
}

.dock-window.is-maximized {
  position: fixed;
  inset: max(var(--space-6), 4vh) max(var(--space-6), 5vw);
  z-index: var(--z-modal);
  width: auto;
  max-width: none;
  height: auto;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-xl);
  animation: wm-pop-in var(--dur) var(--ease);
}
/* The dock is a stacking context (z-index --z-dock), so a maximized window cannot rise above a
   backdrop placed higher than the dock: the backdrop sits right below it, above the shell. Modals,
   menus and toasts opened from the maximized window still stack above the whole dock. */
.dock-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-dock) - 1);
  background: var(--backdrop);
  animation: wm-fade-in var(--dur) var(--ease);
}

/* ---------------------------------------------------------------- floating compose button (< 768) */

.fab {
  position: fixed;
  inset-inline-end: calc(var(--space-4) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  z-index: var(--z-dock);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 56px;
  height: 56px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--btn-primary-bg);
  color: var(--text-inverse);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
/* Hidden outside the mail views (compose.js); the display above would otherwise beat the hidden attribute. */
.fab[hidden] {
  display: none;
}
.fab:hover {
  background: var(--btn-primary-bg-hover);
}
.fab:active {
  transform: scale(.96);
}
.fab .icon {
  width: var(--icon-lg);
  height: var(--icon-lg);
}
.app-shell.is-immersive ~ .fab {
  display: none;
}
.app-shell:has(.mail-layout.is-reading) ~ .fab {
  display: none;
}

/* ---------------------------------------------------------------- centred pages (login, installer, errors) */

.page-center {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding:
    calc(var(--space-6) + env(safe-area-inset-top, 0px))
    calc(var(--space-4) + env(safe-area-inset-right, 0px))
    calc(var(--space-6) + env(safe-area-inset-bottom, 0px))
    calc(var(--space-4) + env(safe-area-inset-left, 0px));
}
.page-center > * {
  width: 100%;
  max-width: 420px;
}
.page-center.is-wide > * {
  max-width: 720px;
}

/* ---------------------------------------------------------------- phones only (< 768) */

@media screen and (max-width: 767.98px) {
  .app-shell:has(.topbar.is-searching) {
    --shell-top: calc(var(--topbar-h) + var(--touch-min) + var(--space-3) + env(safe-area-inset-top, 0px));
  }
  /* One logo size on every phone page: 28px high, at most 140px wide. */
  .topbar-logo {
    max-width: min(140px, 100%);
  }
  .compose-dock {
    inset-inline: 0;
    max-width: none;
  }
  .dock-window:not(.is-minimized),
  .dock-window.is-maximized {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    width: auto;
    height: auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border: 0;
    border-radius: 0;
    animation: wm-slide-up var(--dur) var(--ease);
  }
  /* Only the full-screen window reaches the notch; the minimized bar sits at the bottom. */
  .dock-window:not(.is-minimized) .dock-window-header {
    height: calc(var(--compose-bar-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }
  .dock-window.is-minimized {
    position: fixed;
    inset-inline: 0;
    bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
    width: auto;
    border-radius: 0;
  }
  /* Without the bottom bar (reader, other full-screen views) the minimized bar drops to the edge. */
  .app-shell.is-immersive ~ .compose-dock .dock-window.is-minimized {
    bottom: env(safe-area-inset-bottom, 0px);
  }
  .app-shell:has(.mail-layout.is-reading) ~ .compose-dock .dock-window.is-minimized {
    bottom: env(safe-area-inset-bottom, 0px);
  }
  .compose-dock:has(.dock-window.is-minimized) ~ .fab {
    bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + var(--compose-bar-h) + var(--space-4));
  }
  /* A full-screen compose window covers the shell; the floating button must not float over it. */
  .compose-dock:has(.dock-window:not(.is-minimized)) ~ .fab {
    display: none;
  }
  /* Locked nav items (§9.6): the 60 px bottom bar only fits icon + label, so the lock badge becomes a
     small corner tag on the icon (like .btn-icon > .badge-lock, placed like .nav-badge); the plan name
     stays in the item's title. The ≥ 768 rail keeps the full badge under the label. */
  .nav-item > .badge-lock {
    position: absolute;
    top: 2px;
    inset-inline-start: calc(50% + 6px);
    height: 13px;
    margin: 0;
    padding: 0 3px;
    gap: 1px;
    font-size: 8px;
    letter-spacing: 0;
    pointer-events: none;
  }
  .nav-item > .badge-lock .icon {
    width: 8px;
    height: 8px;
  }
}

/* ---------------------------------------------------------------- ≥ 768: nav rail, two panes */

@media screen and (min-width: 768px) {
  .app-shell {
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
    grid-template-rows: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "rail   content";
  }
  .app-shell.is-immersive {
    grid-template-rows: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) minmax(0, 1fr);
  }
  .app-shell:has(.mail-layout.is-reading) {
    grid-template-rows: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) minmax(0, 1fr);
  }
  .app-shell.is-immersive .nav-rail {
    display: flex;
  }
  .app-shell:has(.mail-layout.is-reading) .nav-rail {
    display: flex;
  }

  .topbar {
    gap: var(--space-3);
    padding-inline: var(--space-3);
  }
  /* The search field shrinks, never the logo. */
  .topbar-start {
    flex-shrink: 0;
  }
  .topbar-search {
    display: flex;
    align-items: center;
  }
  .topbar .topbar-search-toggle {
    display: none;
  }
  .topbar.is-searching {
    flex-wrap: nowrap;
  }
  .topbar.is-searching > .topbar-start,
  .topbar.is-searching > .topbar-end {
    min-height: 0;
  }
  .topbar.is-searching > .topbar-start {
    flex: none;
  }
  .topbar.is-searching .topbar-search {
    order: 0;
    flex: 1 1 auto;
    max-width: 720px;
    min-height: 0;
    padding-bottom: 0;
  }

  .nav-rail {
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--space-1);
    padding: var(--space-2) 2px calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    background: transparent;
    border-top: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    overflow-y: auto;
    /* overflow-y alone makes x "auto" as well: a badge sticking out ("99+", MAX) gave the narrow rail a sideways
       scroll bar. The rail only ever scrolls vertically. */
    overflow-x: hidden;
  }
  /* 11 px labels fit about 58 px (≈ 10 Latin letters); longer labels end with an ellipsis, so the
     shell also exposes the full label as a tooltip. */
  .nav-item {
    flex: none;
    min-height: 56px;
    padding-inline: 0;
    font-size: 11px;
    letter-spacing: -.01em;
  }
  .nav-item .icon {
    width: 32px;
    height: 32px;
    padding: 4px;
  }
  /* The unread badge stays inside the rail: a wide "99+" next to the icon would be cut off at the rail edge. */
  .nav-badge {
    inset-inline-start: auto;
    inset-inline-end: 2px;
  }
  .nav-spacer {
    display: block;
    flex: 1 1 auto;
  }
  .nav-item[data-rail-only] {
    display: flex;
  }
  .topbar .topbar-logout {
    display: inline-flex;
  }

  .content {
    padding: 0 var(--space-2) var(--space-2) 0;
  }

  .view-panel,
  .list-pane,
  .reader-pane {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
  }

  /* Default and three_pane: list + reader side by side, the list width is resizable (--list-w). */
  .mail-layout {
    gap: var(--space-2);
  }
  .list-pane {
    flex: 0 0 min(var(--list-w), 48%);
    min-width: 280px;
  }
  .reader-pane,
  .mail-layout.is-reading .reader-pane {
    display: flex;
    flex: 1 1 0;
  }
  .mail-layout.is-reading .list-pane {
    display: flex;
  }
  .mail-layout > .split-handle {
    display: block;
    margin-inline: calc(var(--space-2) * -1);
  }
  .mail-layout .reader-back {
    display: none;
  }

  /* list_top: the list above the reader (Roundcube "desktop"); --list-h is resizable. */
  .mail-layout[data-layout="list_top"] {
    flex-direction: column;
  }
  .mail-layout[data-layout="list_top"] .list-pane {
    flex: 0 0 var(--list-h);
    min-width: 0;
    min-height: 160px;
  }
  /* The handle is horizontal here even if the markup keeps aria-orientation="vertical". */
  .mail-layout[data-layout="list_top"] > .split-handle {
    width: auto;
    height: var(--space-2);
    margin-inline: 0;
    margin-block: calc(var(--space-2) * -1);
    cursor: row-resize;
  }
  .mail-layout[data-layout="list_top"] > .split-handle::before {
    top: calc(50% - 1px);
    bottom: auto;
    inset-inline: var(--space-3);
    width: auto;
    height: 2px;
  }

  /* list_only: the message replaces the list (Roundcube "list"). */
  .mail-layout[data-layout="list_only"] .list-pane {
    flex: 1 1 auto;
  }
  .mail-layout[data-layout="list_only"] .reader-pane,
  .mail-layout[data-layout="list_only"] > .split-handle {
    display: none;
  }
  .mail-layout[data-layout="list_only"].is-reading .list-pane {
    display: none;
  }
  .mail-layout[data-layout="list_only"].is-reading .reader-pane {
    display: flex;
  }
  .mail-layout[data-layout="list_only"] .reader-back {
    display: inline-flex;
  }

  .fab {
    display: none;
  }
}

/* 768–1023: the list takes a little less room so the reader stays readable. */
@media screen and (min-width: 768px) and (max-width: 1023.98px) {
  .list-pane {
    flex-basis: min(var(--list-w), 42%);
    min-width: 260px;
  }
}

/* ---------------------------------------------------------------- ≥ 1280: three panes */

@media screen and (min-width: 1280px) {
  .app-shell {
    grid-template-columns: var(--nav-w) var(--sidebar-w) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar  topbar"
      "rail   sidebar content";
  }
  .app-shell > .sidebar {
    grid-area: sidebar;
    position: static;
    z-index: auto;
    width: auto;
    padding: var(--space-2) 0 calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    background: transparent;
    border-inline-end: 0;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: none;
    visibility: visible;
    transition: none;
  }
  .app-shell > .sidebar-backdrop {
    display: none;
  }
  .app-shell > .topbar .topbar-menu-btn {
    display: none;
  }

  /* The user can still collapse the sidebar; it then behaves like the drawer of smaller screens. */
  .app-shell.is-sidebar-collapsed {
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "rail   content";
  }
  .app-shell.is-sidebar-collapsed > .sidebar {
    position: fixed;
    z-index: var(--z-drawer);
    width: min(var(--drawer-w), 86vw);
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-3));
    background: var(--surface-strong);
    border-inline-end: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  }
  .app-shell.is-sidebar-collapsed > .sidebar.is-open {
    transform: none;
    visibility: visible;
    transition: transform var(--dur) var(--ease), visibility 0s;
  }
  .app-shell.is-sidebar-collapsed > .sidebar-backdrop {
    display: block;
  }
  .app-shell.is-sidebar-collapsed > .topbar .topbar-menu-btn {
    display: inline-flex;
  }
}

/* Very wide screens: keep the reading measure comfortable. */
@media screen and (min-width: 1680px) {
  :root {
    --list-w: 420px;
  }
}
