/*
 * host123 Webmail components (§29.2). Class names are binding; the DOM contract of each component
 * is documented in docs/packages/P04a.md. Tokens only, no !important, mobile first.
 */

/* ================================================================ buttons */

.btn {
  --btn-bg: var(--glass-bg);
  --btn-bg-hover: var(--surface-strong);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--btn-h);
  max-width: 100%;
  padding: 0 var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-lg);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  line-height: 1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}
.btn:hover {
  background: var(--btn-bg-hover);
  text-decoration: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.btn:disabled,
.btn[aria-disabled="true"]:not(.is-locked) {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}
.btn:disabled:hover,
.btn[aria-disabled="true"]:not(.is-locked):hover {
  background: var(--btn-bg);
}
.btn[aria-pressed="true"],
.btn[aria-expanded="true"].btn-ghost {
  --btn-bg: var(--brand-soft);
  --btn-bg-hover: var(--brand-soft);
  --btn-fg: var(--brand-text);
}

.btn-primary {
  --btn-bg: var(--btn-primary-bg);
  --btn-bg-hover: var(--btn-primary-bg-hover);
  --btn-fg: var(--text-inverse);
  --btn-border: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-secondary {
  --btn-bg: var(--glass-bg);
  --btn-bg-hover: var(--surface-strong);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.btn-ghost {
  --btn-bg: transparent;
  --btn-bg-hover: var(--row-hover);
  --btn-fg: var(--text);
  --btn-border: transparent;
}
.btn-danger {
  --btn-bg: var(--danger-solid);
  --btn-bg-hover: var(--danger-solid-hover);
  --btn-fg: var(--text-inverse);
  --btn-border: transparent;
}
.btn-danger:focus-visible {
  outline-color: var(--danger-solid);
}

.btn-sm {
  height: var(--btn-h-sm);
  padding: 0 var(--space-3);
  font-size: var(--fs-sm);
}
.btn-lg {
  height: var(--btn-h-lg);
  padding: 0 var(--space-6);
  font-size: var(--fs-lg);
}
.btn-lg .icon {
  width: var(--icon-md);
  height: var(--icon-md);
}
.btn-icon {
  width: var(--btn-h);
  padding: 0;
}
.btn-icon .icon {
  width: var(--icon-md);
  height: var(--icon-md);
}
.btn-icon.btn-sm {
  width: var(--btn-h-sm);
}
.btn-icon.btn-sm .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.btn-icon.btn-lg {
  width: var(--btn-h-lg);
}
.btn-block {
  display: flex;
  width: 100%;
}
.btn-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Busy state: the label hides behind a spinner in the button's own text colour. */
.btn[aria-busy="true"] {
  color: transparent;
  pointer-events: none;
}
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 16px;
  height: 16px;
  margin: auto;
  border: 2px solid var(--btn-fg);
  border-inline-end-color: transparent;
  border-radius: var(--radius-full);
  animation: wm-spin 700ms linear infinite;
}

/* Split button: send + schedule menu */
.btn-split {
  display: inline-flex;
  flex: none;
  align-items: stretch;
  max-width: 100%;
}
.btn-split > .btn:not(:last-child) {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
.btn-split > .btn-split-toggle {
  width: auto;
  min-width: 32px;
  padding: 0 var(--space-2);
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}
.btn-split > .btn + .btn-split-toggle {
  margin-inline-start: -1px;
}
.btn-split > .btn-primary + .btn-split-toggle,
.btn-split > .btn-danger + .btn-split-toggle {
  margin-inline-start: 0;
  border-inline-start: 1px solid var(--btn-split-sep);
}
.btn-split > .btn:focus-visible {
  z-index: 1;
}

/* Generic toolbar (role=toolbar) */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}
.toolbar-sep {
  flex: none;
  align-self: stretch;
  width: 1px;
  margin: var(--space-1);
  background: var(--border);
}
.toolbar-spacer {
  flex: 1 1 auto;
}

/* ================================================================ form controls */

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--btn-h);
  padding: 7px var(--space-3);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  background-color: var(--input-bg);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 20px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--input-border-hover);
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--focus-color);
  box-shadow: var(--focus-ring);
  outline: 2px solid transparent;
}
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger-solid);
}
.input[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus {
  box-shadow: var(--focus-ring-danger);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.input[readonly],
.textarea[readonly] {
  background-color: var(--surface-sunken);
}
.input-sm {
  min-height: var(--btn-h-sm);
  padding-block: 4px;
  font-size: var(--fs-sm);
}
.input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

.textarea {
  min-height: 96px;
  line-height: var(--lh);
  resize: vertical;
}

/* Native select with a token-coloured chevron drawn by two gradients (no image files, no literals). */
.select {
  padding-inline-end: 34px;
  -webkit-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.select[multiple],
.select[size]:not([size="1"]) {
  padding-inline-end: var(--space-3);
  background-image: none;
}
.select option {
  background-color: var(--bg-canvas);
  color: var(--text);
}

.input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}
.input-group > .input,
.input-group > .select {
  flex: 1 1 auto;
  width: 1%;
}
.input-group > * + * {
  margin-inline-start: -1px;
}
.input-group > :not(:first-child) {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}
.input-group > :not(:last-child) {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
.input-group > :focus,
.input-group > :focus-visible {
  position: relative;
  z-index: 1;
}
.input-group > .btn {
  height: auto;
  min-height: var(--btn-h);
}
.input-addon {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-3);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

/* Input with a leading icon (search fields) */
.input-icon {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}
.input-icon > .icon {
  position: absolute;
  top: 50%;
  inset-inline-start: 10px;
  width: var(--icon-sm);
  height: var(--icon-sm);
  color: var(--text-muted);
  pointer-events: none;
  transform: translateY(-50%);
}
.input-icon > .input {
  padding-inline-start: 34px;
}

/* Field: label + control + hint + error (errors are linked with aria-describedby) */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
.field + .field {
  margin-top: var(--space-4);
}
/* Form layouts: a vertical stack and a responsive row; both space fields with gaps instead. */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: var(--space-4);
  align-items: start;
}
.stack > .field,
.field-row > .field,
.grid-2 > .field,
.grid-3 > .field,
.toolbar > .field {
  margin-top: 0;
}
.field > label,
.field-label {
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.field-label.is-required::after {
  content: " *";
  color: var(--danger-text);
}
.field-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.field-error {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
  color: var(--danger-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}
.field-error:empty {
  display: none;
}
.field-error .icon {
  width: var(--icon-xs);
  height: var(--icon-xs);
}

/* Checkbox / radio: a <label class="check"><input type="checkbox"> text</label> */
.check,
.radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-2);
  min-height: 20px;
  color: var(--text);
  line-height: 20px;
  cursor: pointer;
}
.check > input,
.radio > input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  cursor: pointer;
}
.check.is-disabled,
.radio.is-disabled {
  opacity: .6;
  cursor: not-allowed;
}
/* Separate rule: an engine without :has() must not drop the class-based one above. */
.check:has(> input:disabled),
.radio:has(> input:disabled) {
  opacity: .6;
  cursor: not-allowed;
}

/* Switch: <button class="switch" role="switch" aria-checked="false"> (labelled by aria-labelledby) */
.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 40px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--switch-off);
  vertical-align: middle;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}
.switch::before {
  /* Enlarges the hit area to the 40 px touch target without changing the look. */
  content: "";
  position: absolute;
  inset: -8px -2px;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--switch-thumb);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease);
}
.switch[aria-checked="true"] {
  background: var(--switch-on);
}
.switch[aria-checked="true"]::after {
  transform: translateX(16px);
}
.switch:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--touch-min);
}
.switch-field > label,
.switch-field > .switch-label {
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}

/* Segmented control */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-sunken);
}
.seg-item {
  display: inline-flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-item .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.seg-item:hover {
  color: var(--text);
}
.seg-item[aria-pressed="true"],
.seg-item[aria-checked="true"],
.seg-item[aria-selected="true"] {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ================================================================ badges, chips, lock UI */

.badge {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.badge .icon {
  width: 12px;
  height: 12px;
}
.badge-success { background: var(--success-soft); border-color: var(--success-line); color: var(--success-text); }
.badge-warning { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning-text); }
.badge-danger  { background: var(--danger-soft);  border-color: var(--danger-line);  color: var(--danger-text); }
.badge-info    { background: var(--info-soft);    border-color: var(--info-line);    color: var(--info-text); }
.badge-brand   { background: var(--brand-soft);   border-color: var(--brand-line);   color: var(--brand-text); }

/* Lock badge of gated features (§9.6): <span class="badge-lock"><svg class="icon">lock</svg>PRO</span> */
.badge-lock {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 3px;
  height: 18px;
  margin-inline-start: var(--space-1);
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--badge-lock-bg);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: var(--fw-bold);
  letter-spacing: .03em;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.badge-lock .icon {
  width: 11px;
  height: 11px;
}
/* A square icon button cannot hold the full badge: it would overflow onto the neighbouring
   buttons. There it becomes a small corner tag; the plan name stays in the button's title. */
.btn-icon {
  position: relative;
}
.btn-icon > .badge-lock {
  position: absolute;
  inset-block-start: -3px;
  inset-inline-end: -3px;
  height: 13px;
  margin: 0;
  padding: 0 3px;
  gap: 0;
  font-size: 8px;
  letter-spacing: 0;
  pointer-events: none;
}
/* The corner tag keeps a small lock (P36: every gated place shows it). */
.btn-icon > .badge-lock {
  gap: 1px;
}
.btn-icon > .badge-lock .icon {
  width: 8px;
  height: 8px;
}
/* On a filled (gradient) button the gradient badge would disappear: a light translucent pill instead. */
.btn-primary > .badge-lock,
.btn-danger > .badge-lock {
  background: var(--badge-lock-on-fill);
  color: inherit;
}
/* A locked form control gets its badge right after it (controls cannot hold children). Inside a labelled field the
   badge sits at the end of the label row instead of stretching across the field under the control. */
.field:has(> .badge-lock) {
  position: relative;
}
.field > .badge-lock {
  align-self: flex-start;
  margin-inline-start: 0;
}
.field:has(> label, > .field-label) > .badge-lock {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
}

/* Locked (plan-gated) elements stay visible and focusable; a click opens the upgrade modal. */
.is-locked {
  opacity: .75;
  cursor: pointer;
}
.is-locked:hover,
.is-locked:focus-visible {
  opacity: .9;
}
.is-locked:disabled,
.is-locked input,
.is-locked select,
.is-locked textarea {
  cursor: pointer;
}

/* Recipient chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 30px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--surface-strong);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1;
  vertical-align: middle;
  white-space: nowrap;
}
.chip > .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.chip > .avatar {
  width: 22px;
  height: 22px;
  margin-inline-start: -8px;
  font-size: 10px;
}
.chip-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:focus-visible,
.chip.is-selected {
  border-color: var(--brand-line);
  background: var(--brand-soft);
}
.chip-remove {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-inline: 0 -8px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.chip-remove .icon {
  width: var(--icon-xs);
  height: var(--icon-xs);
}
.chip-remove:hover {
  background: var(--row-selected);
}
.chip-warn {
  border-color: var(--warning-line);
  background: var(--warning-soft);
  color: var(--warning-text);
}
.chip-error {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger-text);
}
.chip-warn:focus-visible,
.chip-warn.is-selected {
  border-color: var(--warning-text);
  background: var(--warning-soft);
}
.chip-error:focus-visible,
.chip-error.is-selected {
  border-color: var(--danger-text);
  background: var(--danger-soft);
}

/* ================================================================ surfaces: glass, card, popover */

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--glass-bg);
  box-shadow: var(--shadow-sm);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.card-body {
  padding: var(--space-5);
}
.card-body > :last-child {
  margin-bottom: 0;
}
.card-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
}

.popover {
  position: fixed;
  z-index: var(--z-popover);
  max-width: calc(100vw - var(--space-4));
  max-height: calc(100vh - var(--space-4));
  max-height: calc(100dvh - var(--space-4));
  padding: var(--space-3);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: wm-pop-in var(--dur-fast) var(--ease);
}

/* ================================================================ modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-6) 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--backdrop);
  animation: wm-fade-in var(--dur) var(--ease);
}
/* Opaque variant: for a dialog that must not leave the page behind it readable, e.g. the session-expired
   modal opened over a live mailbox after a 401 (§7.2). The app background replaces the translucent
   scrim; the forced-colours block below paints it with Canvas. */
.modal-backdrop.modal-backdrop-opaque {
  background: var(--bg-app);
  background-color: var(--bg-canvas);
}
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - var(--space-6));
  max-height: calc(100dvh - var(--space-6));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: wm-slide-up var(--dur) var(--ease);
}
.modal-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3) var(--space-3) var(--space-5);
}
.modal-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.modal-close {
  flex: none;
  margin-inline-start: auto;
}
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 var(--space-5) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-body:first-child {
  padding-top: var(--space-5);
}
.modal-footer {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--border);
}
.modal-footer > .btn {
  flex: 1 1 auto;
}
.modal-full {
  height: 100%;
  max-height: none;
  border-radius: 0;
}

@media (min-width: 768px) {
  .modal-backdrop {
    align-items: center;
    padding: var(--space-6) var(--space-4);
  }
  .modal {
    max-width: 560px;
    max-height: calc(100vh - var(--space-8) * 2);
    max-height: calc(100dvh - var(--space-8) * 2);
    padding-bottom: 0;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-xl);
    animation-name: wm-pop-in;
  }
  .modal-footer > .btn {
    flex: none;
  }
  .modal-sm { max-width: 400px; }
  .modal-md { max-width: 560px; }
  .modal-lg { max-width: 800px; }
  .modal-full {
    max-width: none;
    height: calc(100vh - var(--space-6) * 2);
    height: calc(100dvh - var(--space-6) * 2);
    max-height: none;
    border-radius: var(--radius-xl);
  }
}

/* ================================================================ drawer */

.drawer {
  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: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  border-inline-end: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  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);
}
.drawer-left {
  inset-inline: 0 auto;
  border-inline-end: 1px solid var(--border);
  border-inline-start: 0;
  transform: translateX(-105%);
}
.drawer-right {
  inset-inline: auto 0;
  border-inline-start: 1px solid var(--border);
  border-inline-end: 0;
  transform: translateX(105%);
}
.drawer.is-open {
  transform: none;
  visibility: visible;
  transition: transform var(--dur) var(--ease), visibility 0s;
}
.drawer-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);
}
.drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur) var(--ease), visibility 0s;
}
.drawer-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--topbar-h);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.drawer-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.drawer-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer-footer {
  display: flex;
  flex: none;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

/* ================================================================ combobox */

/* A search field with a list of matches below it (js/ui/combobox.js). */
.combobox {
  position: relative;
  min-width: 0;
}
.combobox-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: var(--z-dropdown);
  max-height: min(340px, 50vh);
  margin: 0;
  padding: var(--space-1);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.combobox-list[hidden] {
  display: none;
}
.combobox-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.combobox-option.is-active {
  background: var(--row-selected);
}
.combobox-option-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  overflow-wrap: anywhere;
}
.combobox-option-hint {
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.combobox-empty,
.combobox-more {
  padding: var(--space-2) var(--space-3);
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.combobox-more {
  border-top: 1px solid var(--border);
}

/* ================================================================ menu */

/* Menus, popovers and tooltips are position: fixed and must be appended to <body>: panes, cards, the
   dock and modals use backdrop-filter, which would turn them into the containing block. */
.menu {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 200px;
  max-width: min(340px, calc(100vw - var(--space-4)));
  max-height: min(480px, 70vh);
  margin: 0;
  padding: var(--space-1);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: wm-pop-in var(--dur-fast) var(--ease);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  line-height: var(--lh-tight);
  text-align: start;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.menu-item > .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
  color: var(--text-muted);
}
.menu-item:hover,
.menu-item.is-active {
  background: var(--row-hover);
}
.menu-item:focus-visible {
  background: var(--row-hover);
  outline-offset: -2px;
}
.menu-item[aria-checked="true"] {
  color: var(--brand-text);
  font-weight: var(--fw-medium);
}
.menu-item[aria-checked="true"] > .icon {
  color: inherit;
}
.menu-item:disabled,
.menu-item[aria-disabled="true"]:not(.is-locked) {
  opacity: .5;
  cursor: not-allowed;
}
.menu-item.is-danger,
.menu-item.is-danger > .icon {
  color: var(--danger-text);
}
.menu-item.is-locked .badge-lock {
  margin-inline-start: auto;
}
.menu-item-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-item-hint {
  flex: none;
  margin-inline-start: auto;
  padding-inline-start: var(--space-3);
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.menu-sep {
  height: 1px;
  margin: var(--space-1) 0;
  padding: 0;
  border: 0;
  background: var(--border);
}
.menu-label {
  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;
}

/* ================================================================ tabs */

.tabs {
  display: flex;
  gap: var(--space-1);
  min-width: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.tab {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.tab .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.tab:hover {
  background: var(--row-hover);
  color: var(--text);
}
.tab:focus-visible {
  outline-offset: -2px;
}
.tab[aria-selected="true"] {
  color: var(--brand-text);
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-2);
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}
.tab-panel:focus-visible {
  outline-offset: 2px;
}

/* ================================================================ toast */

.toast-region {
  position: fixed;
  inset-inline: var(--space-3);
  /* Phones: above the bottom bar and the floating compose button (56 px + its 16 px offset). */
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 56px + var(--space-4) + var(--space-3));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: 480px;
  min-height: 48px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: var(--fs-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: wm-slide-up var(--dur) var(--ease);
}
.toast > .icon,
.toast-icon {
  flex: none;
  width: var(--icon-md);
  height: var(--icon-md);
}
.toast-message {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding-block: var(--space-1);
}
.toast-success { border-inline-start: 4px solid var(--success-solid); }
.toast-error   { border-inline-start: 4px solid var(--danger-solid); }
.toast-warning { border-inline-start: 4px solid var(--warning-solid); }
.toast-action,
.toast-close {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
}
.toast-action {
  padding: 0 var(--space-3);
  color: var(--toast-action);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.toast-close {
  width: 32px;
  padding: 0;
  color: inherit;
}
.toast-action:hover,
.toast-close:hover {
  background: var(--on-inverse-hover);
}
.toast-action:focus-visible,
.toast-close:focus-visible {
  outline-color: var(--toast-action);
  outline-offset: 0;
}
.toast.is-leaving {
  animation: wm-fade-out var(--dur) var(--ease) forwards;
}

/* Phones with the bottom bar hidden (reader, compose): toasts drop to the bottom edge. */
@media (max-width: 767.98px) {
  .app-shell.is-immersive ~ .toast-region {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
  }
  .app-shell:has(.mail-layout.is-reading) ~ .toast-region {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
  }
}

@media (min-width: 768px) {
  .toast-region {
    inset-inline: calc(var(--nav-w) + var(--space-3)) auto;
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    align-items: flex-start;
    width: min(480px, calc(100vw - var(--nav-w) - var(--space-6)));
  }
}

/* ================================================================ banner */

.banner {
  --banner-accent: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  color: var(--text);
  font-size: var(--fs-sm);
}
.banner > .icon,
.banner-icon {
  flex: none;
  width: var(--icon-md);
  height: var(--icon-md);
  color: var(--banner-accent);
}
.banner-body {
  flex: 1 1 auto;
  min-width: 0;
}
.banner-title {
  margin: 0 0 2px;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}
.banner-text {
  margin: 0;
}
.banner-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.banner > .banner-actions {
  flex: none;
  align-self: center;
  margin-top: 0;
}
.banner-close {
  flex: none;
  margin-block: -4px;
  margin-inline-end: -8px;
}
.banner-info    { --banner-accent: var(--info-text);    border-color: var(--info-line);    background: var(--info-soft); }
.banner-warning { --banner-accent: var(--warning-text); border-color: var(--warning-line); background: var(--warning-soft); }
.banner-danger  { --banner-accent: var(--danger-text);  border-color: var(--danger-line);  background: var(--danger-soft); }
.banner-success { --banner-accent: var(--success-text); border-color: var(--success-line); background: var(--success-soft); }

/* Compact banner (global notices repeated on every page): one row with the text, the actions and the close button. */
.banner-compact {
  align-items: center;
  padding-block: var(--space-2);
}
.banner-compact .banner-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
}
.banner-compact .banner-text {
  flex: 1 1 280px;
}
.banner-compact .banner-actions {
  margin-top: 0;
}
.banner-compact .banner-close {
  margin-block: -2px;
}

@media (max-width: 767.98px) {
  .banner {
    flex-wrap: wrap;
  }
  /* The body shrinks next to the icon and the close button (a content-sized body wrapped to its own row and left
     the icon and the close button alone on theirs); only direct-child actions take a row of their own. */
  .banner-body {
    flex-basis: 0;
  }
  .banner > .banner-actions {
    order: 1;
    flex-basis: 100%;
    padding-inline-start: calc(var(--icon-md) + var(--space-3));
  }
}

/* ================================================================ tooltip, kbd, spinner */

.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 280px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.35;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  animation: wm-fade-in var(--dur-fast) var(--ease);
}
.tooltip .kbd {
  height: 18px;
  min-width: 18px;
  margin-inline-start: var(--space-1);
  border-color: transparent;
  background: var(--on-inverse-hover);
  color: inherit;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--kbd-border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--kbd-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}

.spinner {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--progress-track);
  border-top-color: var(--brand-text);
  border-radius: var(--radius-full);
  vertical-align: middle;
  animation: wm-spin 800ms linear infinite;
}
.spinner-sm {
  width: 14px;
  height: 14px;
}
.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

/* ================================================================ table */

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}
/* A table flush inside a card follows the card's rounded corners. */
.card > .table-wrap:first-child {
  border-start-start-radius: inherit;
  border-start-end-radius: inherit;
}
.card > .table-wrap:last-child {
  border-end-start-radius: inherit;
  border-end-end-radius: inherit;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--text);
  font-size: var(--fs-sm);
}
.table th,
.table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: start;
  vertical-align: middle;
}
.table th {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* Row headers (<th scope="row">) are content, not column captions: normal case, size and wrapping. */
.table tbody th {
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: normal;
  text-transform: none;
  white-space: normal;
}
.table tbody tr:hover {
  background: var(--row-hover);
}
.table tbody tr:last-child > td,
.table tbody tr:last-child > th {
  border-bottom: 0;
}
.table tr.is-selected,
.table tr[aria-selected="true"] {
  background: var(--row-selected);
}
.table .num {
  text-align: end;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table-compact th,
.table-compact td {
  padding: var(--space-1) var(--space-2);
}
.table-actions {
  text-align: end;
  white-space: nowrap;
}
th.table-actions,
td.table-actions {
  width: 1%;
}
.table-actions > * + * {
  margin-inline-start: var(--space-1);
}

/* ================================================================ list */

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  text-align: start;
  text-decoration: none;
}
.list-item:last-child {
  border-bottom: 0;
}
a.list-item,
button.list-item,
.list-item[role="option"],
.list-item[tabindex] {
  cursor: pointer;
}
a.list-item:hover,
button.list-item:hover,
.list-item[role="option"]:hover,
.list-item[tabindex]:hover {
  background: var(--row-hover);
}
.list-item:focus-visible {
  outline-offset: -2px;
}
.list-item.is-selected,
.list-item[aria-selected="true"] {
  background: var(--row-selected);
}
.list-item.is-unread {
  font-weight: var(--fw-semibold);
}
.list-item-body {
  flex: 1 1 auto;
  min-width: 0;
}
.list-item-title,
.list-item-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-title {
  font-weight: var(--fw-medium);
}
.list-item-meta {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.list-item-end {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  margin-inline-start: auto;
}

/* ================================================================ message list rows */

/* Container of the rows (role=listbox); enables the one-line layout on wide lists. */
.msg-list {
  container-type: inline-size;
  container-name: msglist;
  margin: 0;
  padding: 0;
  list-style: none;
}
.msg-list:focus-visible {
  outline-offset: -2px;
}

.msg-row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "check from    icons   date"
    "check subject subject flag"
    "check preview preview size";
  align-items: center;
  column-gap: var(--space-2);
  row-gap: 2px;
  min-height: var(--msg-row-h);
  padding-block: var(--space-2);
  padding-inline: calc(var(--space-4) + var(--msg-indent, 0px)) var(--space-3);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-md);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.msg-row:hover {
  background: var(--row-hover);
}
.msg-check {
  grid-area: check;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  min-width: 20px;
  min-height: 20px;
}
.msg-check > input {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}
.msg-from,
.msg-subject,
.msg-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-from {
  grid-area: from;
  font-weight: var(--fw-medium);
}
.msg-subject {
  grid-area: subject;
}
.msg-preview {
  grid-area: preview;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.msg-preview:empty {
  display: none;
}
.msg-date,
.msg-size {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-align: end;
  white-space: nowrap;
}
.msg-date {
  grid-area: date;
}
.msg-size {
  grid-area: size;
  display: none;
}
.msg-icons {
  grid-area: icons;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
}
.msg-icons .icon {
  width: var(--icon-xs);
  height: var(--icon-xs);
}
.msg-flag {
  grid-area: flag;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  min-height: 20px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}
.msg-flag .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
}
.msg-row:hover .msg-flag,
.msg-row.is-focused .msg-flag,
.msg-row:focus-visible .msg-flag,
.msg-flag:focus-visible {
  opacity: 1;
}
/* The flag and the conversation size share the right edge of the subject line (P38); the size is a pill. */
.msg-end {
  grid-area: flag;
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: var(--space-1);
}
.msg-count {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.msg-row.is-unread .msg-count {
  border-color: var(--brand-line);
  background: var(--brand-soft);
  color: var(--brand-text);
}
/* Two-line rows: the pill sits at the end of the row, not after the subject. */
.msg-subject .msg-count {
  display: none;
}

/* Row states */
.msg-row.is-unread .msg-from,
.msg-row.is-unread .msg-subject {
  font-weight: var(--fw-bold);
}
.msg-row.is-unread::before {
  content: "";
  position: absolute;
  top: calc(var(--space-2) + 6px);
  inset-inline-start: calc(5px + var(--msg-indent, 0px));
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--unread-dot);
}
.msg-row.is-flagged .msg-flag {
  color: var(--flag-color);
  opacity: 1;
}
.msg-row.is-flagged .msg-flag .icon {
  fill: currentColor;
}
.msg-row.is-selected,
.msg-row[aria-selected="true"],
.msg-row.is-selected:hover,
.msg-row[aria-selected="true"]:hover {
  background: var(--row-selected);
}
.msg-row.is-deleted .msg-from,
.msg-row.is-deleted .msg-subject,
.msg-row.is-deleted .msg-preview {
  color: var(--text-muted);
  text-decoration: line-through;
}
.msg-row.is-focused,
.msg-row:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
.msg-row.is-dragging {
  opacity: .5;
}

/* Compact list (pref mail.show_preview off, P38): no preview line, so narrow rows have two lines (60 px,
   ROW_HEIGHT_COMPACT in mailbox/state.js) and more messages fit; wide rows keep their height without the preview. */
.msg-list.is-compact {
  --msg-row-h: 60px;
}
.msg-list.is-compact .msg-row {
  grid-template-areas:
    "check from    icons   date"
    "check subject subject flag";
}
.msg-list.is-compact .msg-preview {
  display: none;
}

/* Wide lists (list_top / list_only layouts, big screens): one line per message. */
@container msglist (min-width: 720px) {
  .msg-row {
    grid-template-columns: auto auto minmax(120px, 22%) minmax(0, max-content) minmax(0, 1fr) auto auto auto;
    grid-template-areas: "check flag from subject preview icons size date";
    min-height: var(--msg-row-h-wide);
    padding-block: var(--space-1);
  }
  .msg-list.is-compact .msg-row {
    grid-template-areas: "check flag from subject preview icons size date";
  }
  /* One line: the flag column is on the left, the pill follows the subject. */
  .msg-end {
    justify-self: start;
  }
  .msg-end .msg-count {
    display: none;
  }
  .msg-subject .msg-count {
    display: inline-flex;
  }
  .msg-check {
    align-self: center;
  }
  .msg-row.is-unread::before {
    top: calc(50% - 4px);
  }
  .msg-preview {
    display: block;
  }
  .msg-preview:not(:empty)::before {
    content: "\2014\00a0";
  }
  .msg-size {
    display: block;
    min-width: 56px;
  }
  .msg-date {
    min-width: 72px;
  }
}

/* ================================================================ folder tree */

/* Flat ARIA tree: every folder is one row; nesting comes from aria-level (or --folder-depth). */
.folder-tree,
.folder-tree [role="group"] {
  margin: 0;
  padding: 0;
  list-style: none;
}
.folder {
  --folder-depth: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 34px;
  margin: 1px 0;
  padding-block: var(--space-1);
  padding-inline: calc(var(--space-2) + var(--folder-depth) * 14px) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--fs-md);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.folder[aria-level="2"] { --folder-depth: 1; }
.folder[aria-level="3"] { --folder-depth: 2; }
.folder[aria-level="4"] { --folder-depth: 3; }
.folder[aria-level="5"] { --folder-depth: 4; }
.folder[aria-level="6"] { --folder-depth: 5; }
.folder[aria-level="7"] { --folder-depth: 6; }
.folder[aria-level="8"] { --folder-depth: 7; }
.folder:hover {
  background: var(--row-hover);
}
.folder:focus-visible {
  outline-offset: -2px;
}
.folder > .icon,
.folder-icon {
  flex: none;
  width: var(--icon-sm);
  height: var(--icon-sm);
  color: var(--text-muted);
}
.folder[aria-selected="true"],
.folder.is-active {
  background: var(--row-selected);
  color: var(--brand-text);
  font-weight: var(--fw-semibold);
}
.folder[aria-selected="true"] > .icon,
.folder.is-active > .icon,
.folder[aria-selected="true"] .folder-icon,
.folder.is-active .folder-icon {
  color: inherit;
}
.folder.is-drop-target {
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 2px var(--focus-color);
}
.folder.is-muted,
.folder.is-unsubscribed {
  color: var(--text-muted);
}
.folder.has-unread .folder-name {
  font-weight: var(--fw-semibold);
}
.folder-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-inline: -4px -2px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.folder-toggle .icon {
  width: var(--icon-sm);
  height: var(--icon-sm);
  transition: transform var(--dur-fast) var(--ease);
}
.folder[aria-expanded="false"] > .folder-toggle .icon {
  transform: rotate(-90deg);
}
.folder:not([aria-expanded]) > .folder-toggle {
  visibility: hidden;
}
.folder-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-count {
  flex: none;
  min-width: 20px;
  margin-inline-start: auto;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.folder-count:empty {
  display: none;
}

/* ================================================================ avatar */

.avatar {
  --avatar-bg: var(--avatar-1);
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--avatar-bg);
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: var(--fw-semibold);
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.avatar > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-1 { --avatar-bg: var(--avatar-1); }
.avatar-2 { --avatar-bg: var(--avatar-2); }
.avatar-3 { --avatar-bg: var(--avatar-3); }
.avatar-4 { --avatar-bg: var(--avatar-4); }
.avatar-5 { --avatar-bg: var(--avatar-5); }
.avatar-6 { --avatar-bg: var(--avatar-6); }
.avatar-7 { --avatar-bg: var(--avatar-7); }
.avatar-8 { --avatar-bg: var(--avatar-8); }
.avatar-sm {
  width: 24px;
  height: 24px;
  font-size: 10px;
}
.avatar-lg {
  width: 40px;
  height: 40px;
  font-size: var(--fs-lg);
}
.avatar-xl {
  width: 64px;
  height: 64px;
  font-size: var(--fs-3xl);
}

/* ================================================================ skeleton */

.skeleton,
.skeleton-line {
  display: block;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 37%, var(--skeleton-base) 63%);
  background-size: 400% 100%;
  color: transparent;
  animation: wm-shimmer 1400ms ease infinite;
}
.skeleton-line {
  width: 100%;
  height: 12px;
  margin: var(--space-2) 0;
  border-radius: var(--radius-sm);
}
.skeleton-line:last-child:not(:first-child) {
  width: 60%;
}
.skeleton-circle {
  border-radius: var(--radius-full);
}

/* ================================================================ progress (quota, uploads) */

/* The fill width comes from --progress (set with el.style.setProperty('--progress', '42%')). */
.progress {
  position: relative;
  display: block;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--progress-track);
}
.progress-bar {
  display: block;
  width: var(--progress, 0%);
  max-width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--btn-primary-bg);
  transition: width var(--dur) var(--ease);
}
.progress.is-warning .progress-bar,
.progress-bar.is-warning {
  background: var(--warning-solid);
}
.progress.is-danger .progress-bar,
.progress-bar.is-danger {
  background: var(--danger-solid);
}
.progress.is-indeterminate .progress-bar {
  width: 40%;
  animation: wm-indeterminate 1200ms ease-in-out infinite;
}
.progress-lg {
  height: 10px;
}

/* ================================================================ empty state */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  max-width: 440px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
  text-align: center;
}
.pane-body > .empty,
.view-body > .empty {
  min-height: 100%;
}
.empty > .icon,
.empty-icon {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2);
  padding: 14px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-text);
}
.empty-title {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.empty-text {
  margin: 0;
  font-size: var(--fs-sm);
}
.empty-action {
  margin-top: var(--space-3);
}

/* ================================================================ dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-muted);
  text-align: center;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.dropzone.is-over {
  border-color: var(--focus-color);
  background: var(--dropzone-bg);
  color: var(--brand-text);
}
.dropzone.is-overlay {
  position: absolute;
  inset: var(--space-2);
  z-index: 2;
  background: var(--surface-strong);
}
.dropzone.is-overlay.is-over {
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 999px var(--dropzone-bg);
}

/* ================================================================ split pane */

/* <div class="split"> <div class="pane"> <div class="split-handle" role="separator" aria-orientation="vertical"> <div class="pane"> */
.split {
  display: flex;
  min-width: 0;
  min-height: 0;
}
.split-vertical {
  flex-direction: column;
}
.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.split > .pane:first-child {
  flex: 0 0 var(--pane-size, 50%);
}
.split > .pane:last-child {
  flex: 1 1 0;
}
.split-handle {
  position: relative;
  z-index: 1;
  flex: none;
  width: var(--space-2);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
}
.split-handle::before {
  content: "";
  position: absolute;
  top: var(--space-3);
  bottom: var(--space-3);
  inset-inline-start: calc(50% - 1px);
  width: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background-color var(--dur-fast) var(--ease);
}
.split-handle:hover::before,
.split-handle:focus-visible::before,
.split-handle.is-active::before,
.split.is-resizing > .split-handle::before {
  background: var(--focus-color);
}
.split-handle:focus-visible {
  outline-offset: -2px;
}
.split-vertical > .split-handle,
.split-handle[aria-orientation="horizontal"] {
  width: auto;
  height: var(--space-2);
  cursor: row-resize;
}
.split-vertical > .split-handle::before,
.split-handle[aria-orientation="horizontal"]::before {
  top: calc(50% - 1px);
  bottom: auto;
  inset-inline: var(--space-3);
  width: auto;
  height: 2px;
}
/* While dragging, iframes (message body, editor) must not swallow the pointer. */
.split.is-resizing,
.is-resizing {
  cursor: col-resize;
  user-select: none;
}
.is-resizing iframe {
  pointer-events: none;
}

/* ================================================================ shared animation */

@keyframes wm-fade-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(4px); }
}

/* ================================================================ touch targets (≥ 40 px on phones, §29.4) */

@media (max-width: 767.98px), (pointer: coarse) {
  .btn,
  .btn-sm {
    min-height: var(--touch-min);
  }
  .btn-icon,
  .btn-icon.btn-sm {
    min-width: var(--touch-min);
  }
  .input,
  .select,
  .textarea {
    min-height: var(--touch-min);
    /* 16 px keeps iOS Safari from zooming into focused fields. */
    font-size: var(--fs-lg);
  }
  .menu-item,
  .tab,
  .folder,
  .toast-action,
  .toast-close {
    min-height: 44px;
  }
  .toast-close {
    min-width: 44px;
  }
  .seg-item {
    min-height: 36px;
  }
  .list-item {
    min-height: 48px;
  }
  .chip {
    height: 36px;
  }
  .chip-remove {
    width: 32px;
    height: 32px;
  }
  .msg-check {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    margin-block: -10px;
    margin-inline-start: -10px;
  }
  .msg-flag {
    min-width: var(--touch-min);
    min-height: 28px;
  }
  .check,
  .radio {
    min-height: var(--touch-min);
    align-items: center;
  }
  .check > input,
  .radio > input {
    width: 20px;
    height: 20px;
    margin: 0;
  }
  .folder-toggle {
    width: 32px;
    height: 32px;
  }
}

/* ================================================================ reduced motion */

@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .skeleton-line {
    animation: none;
  }
  .spinner,
  .btn[aria-busy="true"]::after {
    animation-duration: 2000ms;
  }
  .progress.is-indeterminate .progress-bar {
    animation: none;
    width: 100%;
    opacity: .5;
  }
}

/* ================================================================ forced colours (Windows high contrast) */

@media (forced-colors: active) {
  .btn,
  .chip,
  .badge,
  .badge-lock,
  .seg,
  .card,
  .modal,
  .menu,
  .toast,
  .tooltip,
  .banner {
    border: 1px solid CanvasText;
  }
  .btn-primary,
  .btn-danger {
    border-color: ButtonText;
  }
  .msg-row.is-selected,
  .msg-row[aria-selected="true"],
  .list-item.is-selected,
  .list-item[aria-selected="true"],
  .folder[aria-selected="true"],
  .folder.is-active,
  .seg-item[aria-pressed="true"],
  .seg-item[aria-checked="true"],
  .seg-item[aria-selected="true"],
  .btn[aria-pressed="true"] {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
  .switch {
    border: 1px solid ButtonText;
    background: Canvas;
  }
  .switch::after {
    background: ButtonText;
  }
  .switch[aria-checked="true"] {
    background: Highlight;
  }
  .progress {
    border: 1px solid CanvasText;
  }
  .progress-bar {
    background: Highlight;
  }
  .modal-backdrop.modal-backdrop-opaque {
    background: Canvas;
  }
}
