/* ─────────────────────────────────────────────────────────────
 * tgmail Mini App stylesheet
 * Brand: ink + paper + ultramarine. Flat, type-led, no gradients.
 * Follows the user's light/dark scheme, rendered in brand colors.
 * ──────────────────────────────────────────────────────────── */

:root {
  /* Brand tokens: light (paper) */
  --bg: #faf9f6;
  --surface: #ffffff;
  --press: rgba(26, 28, 32, 0.07);
  --text: #1a1c20;
  --muted: #70737a;
  --separator: rgba(26, 28, 32, 0.1);
  --accent: #2b4ee6;
  --accent-solid: #2b4ee6;
  --on-accent: #ffffff;
  --danger: #d7372f;
  --tone-warn: #c77d0a;

  /* Safe areas (mirrored by JS in safeAreaChanged/contentSafeAreaChanged) */
  --tg-safe-area-inset-top: 0px;
  --tg-safe-area-inset-right: 0px;
  --tg-safe-area-inset-bottom: 0px;
  --tg-safe-area-inset-left: 0px;
  --tg-content-safe-area-inset-top: 0px;
  --tg-content-safe-area-inset-right: 0px;
  --tg-content-safe-area-inset-bottom: 0px;
  --tg-content-safe-area-inset-left: 0px;

  /* Effective insets: max of system, Telegram chrome, and iOS env() */
  --safe-top: max(
    env(safe-area-inset-top, 0px),
    var(--tg-safe-area-inset-top),
    var(--tg-content-safe-area-inset-top)
  );
  --safe-bottom: max(
    env(safe-area-inset-bottom, 0px),
    var(--tg-safe-area-inset-bottom),
    var(--tg-content-safe-area-inset-bottom)
  );
  --safe-left: max(
    env(safe-area-inset-left, 0px),
    var(--tg-safe-area-inset-left),
    var(--tg-content-safe-area-inset-left)
  );
  --safe-right: max(
    env(safe-area-inset-right, 0px),
    var(--tg-safe-area-inset-right),
    var(--tg-content-safe-area-inset-right)
  );

  /* Spacing scale */
  --gutter: 16px;
  --row-pad-y: 14px;
  --row-pad-x: var(--gutter);

  /* Type */
  --font-stack:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-serif:
    ui-serif, "New York", Georgia, "Iowan Old Style", "Times New Roman",
    serif;
  --font-mono:
    ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Mono", Consolas,
    monospace;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
}

/* Brand tokens: dark (ink) */
[data-color-scheme="dark"] {
  --bg: #0e1116;
  --surface: #161b22;
  --press: rgba(236, 238, 242, 0.09);
  --text: #eceef2;
  --muted: #8b919b;
  --separator: rgba(236, 238, 242, 0.1);
  --accent: #8aa3ff;
  --accent-solid: #3d5df0;
  --on-accent: #ffffff;
  --danger: #f26b5e;
  --tone-warn: #e5a50a;
}

/* ── Base ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute must always win; author display rules
   (e.g. .icon-button { display: grid }) silently defeat the UA
   stylesheet otherwise. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-stack);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "ss01" 1;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  -webkit-appearance: none;
  appearance: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ── App shell ──────────────────────────────────────────── */
.app {
  min-height: 100%;
  display: block;
  position: relative;
  background: var(--bg);
}

.screen {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Apply side safe-area to scrollable content, not the screen itself,
   so sticky headers can stretch edge-to-edge. */
.inbox,
.detail,
.detail__actions {
  padding-left: max(var(--gutter), var(--safe-left));
  padding-right: max(var(--gutter), var(--safe-right));
}

/* ── Boot screen ────────────────────────────────────────── */
.screen--boot {
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: max(var(--safe-top), 24px) max(var(--gutter), var(--safe-right))
    max(var(--safe-bottom), 24px) max(var(--gutter), var(--safe-left));
}

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  max-width: 320px;
}

.boot__mark {
  display: grid;
  place-items: center;
  transform: rotate(-4deg);
}

/* The stamp adapts: ultramarine on paper themes, paper on ink themes */
.stamp-paper {
  fill: var(--accent-solid);
}

.stamp-ink {
  stroke: var(--on-accent);
}

.stamp-glyph {
  fill: var(--on-accent);
  font-family: var(--font-serif);
}

[data-color-scheme="dark"] .stamp-paper {
  fill: #faf9f6;
}

[data-color-scheme="dark"] .stamp-ink {
  stroke: var(--accent-solid);
}

[data-color-scheme="dark"] .stamp-glyph {
  fill: var(--accent-solid);
}

.boot__title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.boot__hint {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.boot__cta {
  margin-top: 12px;
  padding: 0 24px;
  text-decoration: none;
}

/* ── Header (inbox) ─────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.app-header__inner {
  padding: 12px var(--gutter) 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Tighten the header when folder tabs are shown below the meter */
.app-header:has(.folders:not([hidden])) .app-header__inner {
  padding-bottom: 6px;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.masthead__wordmark {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

.masthead__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0;
}

.address-pill {
  align-self: flex-start;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid var(--separator);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  transition: background-color 0.15s ease;
}

.address-pill > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.address-pill__icon {
  flex: 0 0 auto;
  opacity: 0.45;
}

.address-pill:active {
  background: var(--press);
}

/* Search bar (replaces the address pill while searching) */
.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.searchbar__icon {
  flex: 0 0 auto;
  color: var(--muted);
}

.searchbar__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  /* ≥16px: iOS WebKit auto-zooms on focus for anything smaller */
  font-size: 16px;
  color: var(--text);
  padding: 8px 0;
  outline: none;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.searchbar__input::placeholder {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}

.searchbar__input::-webkit-search-cancel-button {
  display: none;
}

.searchbar__cancel {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  padding: 8px 2px;
}

/* Storage banner: shown at 90% (warn) and 100% (danger) */
.quota-banner {
  margin: 10px max(var(--gutter), var(--safe-right)) 0
    max(var(--gutter), var(--safe-left));
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  line-height: 1.45;
  background: color-mix(in srgb, var(--tone-warn) 14%, var(--bg));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--tone-warn) 35%, transparent);
}

.quota-banner[data-tone="danger"] {
  background: color-mix(in srgb, var(--danger) 12%, var(--bg));
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

/* On touch clients pull-to-refresh (plus refresh-on-activate) makes the
   refresh icon redundant chrome; only pointer devices keep it. */
@media (pointer: coarse) {
  [data-role="refresh"] {
    display: none !important;
  }
}

.icon-button {
  flex: 0 0 auto;
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--text);
  opacity: 0.7;
  transition:
    background-color 0.15s ease,
    opacity 0.15s ease,
    transform 0.15s ease;
}

.icon-button:active {
  background: var(--press);
  opacity: 1;
  transform: scale(0.94);
}

.icon-button[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.icon-button[data-busy="true"] svg {
  animation: spin 0.9s linear infinite;
}

.icon-button--accent {
  color: var(--accent);
  opacity: 0.95;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Folder tabs (Inbox / Sent), Telegram chat-folder styling */
.folders {
  position: relative;
  display: flex;
  gap: 20px;
  padding: 0 var(--gutter);
  padding-left: max(var(--gutter), var(--safe-left));
  padding-right: max(var(--gutter), var(--safe-right));
}

.folders__tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0 11px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--muted);
  transition: color 0.18s ease;
  -webkit-user-select: none;
  user-select: none;
}

.folders__tab[aria-selected="true"] {
  color: var(--accent);
}

.folders__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-solid);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.folders__indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  opacity: 0;
  transition:
    transform 0.26s cubic-bezier(0.3, 0.8, 0.3, 1),
    width 0.26s cubic-bezier(0.3, 0.8, 0.3, 1);
  will-change: transform, width;
}

.folders__indicator[data-ready="true"] {
  opacity: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: color-mix(
    in srgb,
    var(--accent-solid) 14%,
    transparent
  );
  color: var(--accent-solid);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Storage meter (lives in Settings) */
.meter__track {
  height: 3px;
  border-radius: 3px;
  background: var(--separator);
  overflow: hidden;
  margin: 10px 0 4px;
}

.meter__fill {
  height: 100%;
  background: var(--accent-solid);
  border-radius: inherit;
  transition: width 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.meter__fill[data-tone="warn"] {
  background: var(--tone-warn);
}

.meter__fill[data-tone="danger"] {
  background: var(--danger);
}

/* ── Inbox list ─────────────────────────────────────────── */
.inbox {
  position: relative;
  padding-bottom: calc(var(--safe-bottom) + 24px);
  background: var(--bg);
  min-height: 60vh;
  will-change: transform;
}

/* Pull-to-refresh indicator: revealed when the list is dragged down */
.ptr {
  position: absolute;
  top: -42px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 32px;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
}

.ptr__spinner {
  display: block;
  will-change: transform;
}

.ptr[data-spin="true"] .ptr__spinner {
  animation: spin 0.8s linear infinite;
}

.inbox__list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg);
}

.inbox__list > li {
  position: relative;
  overflow: hidden; /* clips the swipe action */
  isolation: isolate;
}

/* Swipe-to-delete: the action sits behind the sliding row */
.row-action {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 96px;
  display: grid;
  place-items: center;
  background: var(--danger);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  border: 0;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
}

.inbox__list > li[data-action-visible="true"] > .row-action {
  opacity: 1;
  visibility: visible;
}

.inbox__list > li[data-open="true"] > .row-action {
  pointer-events: auto;
}

.row {
  will-change: transform;
  z-index: 1;
}

/* Infinite-scroll sentinel */
.list-sentinel {
  display: flex;
  justify-content: center;
  padding: 18px 0 26px;
  color: var(--muted);
}

.list-sentinel svg {
  animation: spin 0.8s linear infinite;
}

/* Trash footer: retention note + empty action */
.trash-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px var(--gutter) 30px;
  text-align: center;
}

.trash-footer__note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.trash-footer .btn {
  min-height: 38px;
  font-size: 13px;
}

/* Date group labels */
.group-label {
  padding: 18px var(--row-pad-x) 6px calc(var(--row-pad-x) + 10px);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}

.row {
  display: block;
  padding: var(--row-pad-y) var(--row-pad-x) var(--row-pad-y)
    calc(var(--row-pad-x) + 10px);
  width: 100%;
  position: relative;
  transition: background-color 0.12s ease;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

/* hairline between rows, inset to the text edge */
.inbox__list > li + li > .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: calc(var(--row-pad-x) + 10px);
  right: var(--row-pad-x);
  height: 1px;
  background: var(--separator);
}

/* …but not on the first row after a date label */
.inbox__list > li.group-label + li > .row::before {
  display: none;
}

.row:active {
  background: color-mix(
    in srgb,
    var(--text) 8%,
    var(--bg)
  );
}

@media (hover: hover) {
  .row:hover {
    background: color-mix(
      in srgb,
      var(--text) 4%,
      var(--bg)
    );
  }
}

.row:focus-visible {
  background: color-mix(
    in srgb,
    var(--text) 6%,
    var(--bg)
  );
  outline: none;
}

/* Unread indicator: a single dot at the leading edge of the row.
   Uses ::after; ::before is taken by the row hairline. */
.row[data-unread="true"]::after {
  content: "";
  position: absolute;
  left: 6px;
  top: calc(var(--row-pad-y) + 10px); /* centered on the sender line */
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent-solid);
  transform: translateY(-50%);
}

.row__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row__head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 8px;
  min-width: 0;
}

.row__from {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.row__time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* "To" prefix on sent rows */
.row__to-tag {
  color: var(--muted);
  font-weight: 400;
}

.row__subject {
  font-size: 14px;
  color: var(--text);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.row__subject-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.row__paperclip {
  flex: 0 0 auto;
  color: var(--muted);
  opacity: 0.7;
}

.row__snippet {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* Unread row emphasis */
.row[data-unread="true"] .row__from,
.row[data-unread="true"] .row__subject {
  font-weight: 600;
  color: var(--text);
}

.row[data-unread="true"] .row__snippet {
  color: color-mix(in srgb, var(--text) 72%, transparent);
}

/* Empty + error + skeleton states */
.placeholder {
  padding: 56px 32px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.placeholder__icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: color-mix(
    in srgb,
    var(--text) 6%,
    var(--bg)
  );
  display: grid;
  place-items: center;
  color: var(--muted);
  margin-bottom: 10px;
}

.placeholder__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.placeholder__body {
  font-size: 13px;
  margin: 0;
  max-width: 280px;
  line-height: 1.5;
  color: var(--muted);
}

.placeholder__address {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--press);
}

/* Skeleton */
.skeleton {
  display: block;
  padding: var(--row-pad-y) var(--row-pad-x) var(--row-pad-y)
    calc(var(--row-pad-x) + 10px);
}

.skeleton + .skeleton {
  border-top: 1px solid var(--separator);
  margin-left: calc(var(--row-pad-x) + 10px);
  padding-left: 0;
  padding-right: var(--row-pad-x);
}

.skeleton__lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.skeleton__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.skeleton__bar {
  height: 10px;
  border-radius: 4px;
  background: var(--separator);
}

.skeleton__bar--from {
  width: 40%;
  min-width: 80px;
  flex: 0 1 auto;
}

.skeleton__bar--time {
  width: 32px;
  height: 8px;
  flex: 0 0 auto;
  opacity: 0.6;
}

.skeleton__bar--subject {
  width: 75%;
}

.skeleton__bar--snippet {
  width: 90%;
  height: 8px;
  opacity: 0.7;
}

/* ── Detail screen ──────────────────────────────────────── */
.screen--detail {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.detail {
  flex: 1 1 auto;
  padding-top: calc(var(--safe-top) + 18px);
  padding-bottom: 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.detail__subject {
  font-family: var(--font-serif);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 1.22;
  margin: 0 0 16px;
  color: var(--text);
}

.detail__subject:focus {
  outline: none;
}

/* Editorial sender block: ruled lines, no avatar */
.sender-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 0 14px;
  border-top: 1px solid var(--separator);
  border-bottom: 1px solid var(--separator);
}

.sender-block__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.sender-block__address {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-mono);
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.35;
}

/* Which of the user's addresses the mail went to (or left from) */
.sender-block__route {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.sender-block__time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.detail__body {
  margin: 20px 0 8px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.detail__body--empty {
  color: var(--muted);
  font-style: italic;
}

.detail__body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.detail__html-frame {
  display: block;
  width: 100%;
  height: 1px;
  border: 0;
  background: var(--bg);
  margin: 20px 0 8px;
  border-radius: var(--r-md);
  transition: height 0.18s ease;
}

/* Remote-content banner above HTML mail */
.remote-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 0;
  padding: 9px 9px 9px 12px;
  border: 1px solid var(--separator);
  border-radius: var(--r-md);
  background: var(--surface);
}

.remote-banner__note {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.remote-banner__show {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 8px;
  border-radius: var(--r-sm);
}

.remote-banner__show:active {
  background: var(--press);
}

.remote-banner:not([hidden]) + .detail__html-frame {
  margin-top: 12px;
}

/* Small screens: HTML mail runs edge to edge. The app gutter plus the
   email's own framing costs too much width on a phone; the subject and
   sender block above keep their margins. */
@media (max-width: 600px) {
  .detail__html-frame {
    /* iframes are replaced elements: width auto would collapse to the
       intrinsic 300px, so the bleed must be added explicitly. */
    width: calc(
      100% + max(var(--gutter), var(--safe-left)) +
        max(var(--gutter), var(--safe-right))
    );
    margin-left: calc(-1 * max(var(--gutter), var(--safe-left)));
    margin-right: calc(-1 * max(var(--gutter), var(--safe-right)));
    border-radius: 0;
  }
}

.section-heading {
  margin: 28px 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.attachments {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--separator);
  border-radius: var(--r-md);
  overflow: hidden;
}

.attachment {
  display: grid;
  grid-template-columns: 36px 1fr 32px;
  column-gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg);
  width: 100%;
  transition: background-color 0.12s ease;
}

.attachment:active {
  background: var(--press);
}

.attachment__icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: color-mix(
    in srgb,
    var(--text) 6%,
    var(--bg)
  );
  display: grid;
  place-items: center;
  color: var(--text);
}

.attachment__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.attachment__name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment__size {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.attachment__chev {
  color: var(--muted);
  opacity: 0.7;
  justify-self: end;
}

.attachment[data-busy="true"] .attachment__chev svg {
  animation: spin 0.9s linear infinite;
}

/* Bottom actions on detail */
.detail__actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--separator);
  padding-top: 10px;
  padding-bottom: calc(var(--safe-bottom) + 10px);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  background: color-mix(
    in srgb,
    var(--text) 8%,
    transparent
  );
  color: var(--text);
  transition:
    background-color 0.12s ease,
    transform 0.12s ease,
    opacity 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn--danger {
  color: var(--danger);
}

.btn--danger:active {
  background: color-mix(
    in srgb,
    var(--danger) 16%,
    transparent
  );
}

.btn--primary {
  background: var(--accent-solid);
  color: var(--on-accent);
}

.btn--primary:active {
  background: color-mix(in srgb, var(--accent-solid) 86%, #000000);
}

/* In the detail action bar, Reply takes the remaining width */
.detail__actions .btn--primary {
  flex: 1 1 auto;
}

.btn--wide {
  width: 100%;
}

.btn[data-busy="true"] {
  opacity: 0.7;
  pointer-events: none;
}

/* ── Compose screen ─────────────────────────────────────── */
.screen--compose {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.compose {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding-top: calc(var(--safe-top) + 20px);
}

.compose__head {
  padding: 0 max(var(--gutter), var(--safe-right)) 14px
    max(var(--gutter), var(--safe-left));
}

.compose__title {
  margin: 0 0 3px;
  font-family: var(--font-serif);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--text);
}

.compose__title:focus {
  outline: none;
}

.compose__from {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  min-width: 0;
}

.compose__from-addr {
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* From picker: an invisible native select sits over the address text,
   so tapping it opens the platform picker. Only shown with aliases. */
.compose__from-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.compose__from-chev {
  flex: 0 0 auto;
  color: var(--muted);
}

.compose__from-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  /* ≥16px: iOS WebKit auto-zooms on focus for anything smaller */
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.compose__form {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.field {
  display: grid;
  grid-template-columns: 68px 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 0 max(var(--gutter), var(--safe-right)) 0
    max(var(--gutter), var(--safe-left));
  border-top: 1px solid var(--separator);
}

.field__label {
  font-size: 14px;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}

.field__input {
  border: 0;
  background: transparent;
  font-family: inherit;
  /* ≥16px: iOS WebKit auto-zooms on focus for anything smaller */
  font-size: 16px;
  color: var(--text);
  padding: 14px 0;
  min-width: 0;
  outline: none;
  border-radius: 0;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.field__input::placeholder,
.compose__body::placeholder {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}

.compose__body {
  flex: 1 1 auto;
  border: 0;
  border-top: 1px solid var(--separator);
  background: transparent;
  font-family: inherit;
  /* ≥16px: iOS WebKit auto-zooms on focus for anything smaller */
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  padding: 14px max(var(--gutter), var(--safe-right))
    calc(var(--safe-bottom) + 28px) max(var(--gutter), var(--safe-left));
  min-height: 38vh;
  resize: none;
  outline: none;
  border-radius: 0;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
  overflow: hidden;
}

.compose__fallback {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--separator);
  padding: 10px max(var(--gutter), var(--safe-right))
    calc(var(--safe-bottom) + 10px) max(var(--gutter), var(--safe-left));
}

/* Text fields carry a caret; the focus ring would double up */
.field__input:focus-visible,
.compose__body:focus-visible {
  outline: none;
}

/* ── Settings screen ────────────────────────────────────── */
.screen--settings {
  background: var(--bg);
}

.settings {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 20px) max(var(--gutter), var(--safe-right))
    calc(var(--safe-bottom) + 24px) max(var(--gutter), var(--safe-left));
}

.settings__title {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--text);
}

.settings__title:focus {
  outline: none;
}

.settings .section-heading {
  margin-top: 8px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--separator);
  border: 1px solid var(--separator);
  border-radius: var(--r-md);
  overflow: hidden;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  /* True card on paper: surface + hairline, no gray tint */
  background: var(--surface);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.setting__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.setting__label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.setting__hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.setting--column {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  cursor: text;
}

.setting--column .setting__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.setting__input {
  border: 0;
  background: transparent;
  font-family: inherit;
  /* ≥16px: iOS WebKit auto-zooms on focus for anything smaller */
  font-size: 16px;
  color: var(--text);
  padding: 2px 0;
  min-width: 0;
  outline: none;
  border-radius: 0;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.setting__input::placeholder {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}

.setting__input:focus-visible {
  outline: none;
}

.setting__input:disabled {
  opacity: 0.55;
}

.settings__note {
  margin: 10px 4px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* Segmented control (theme picker). Active segment is inverted ink,
   echoing the toast and the stamp: one color system, no extra hues. */
.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  margin-top: 8px;
  border: 1px solid var(--separator);
  border-radius: 10px;
}

.segmented__option {
  flex: 1 1 0;
  text-align: center;
  padding: 7px 0;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--muted);
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.segmented__option:active {
  background: var(--press);
}

.segmented__option[aria-checked="true"] {
  background: var(--text);
  color: var(--bg);
}

/* iOS-style switch driven by a real checkbox */
.switch {
  position: relative;
  flex: 0 0 auto;
  display: inline-block;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch__track {
  display: block;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: color-mix(
    in srgb,
    var(--text) 16%,
    var(--bg)
  );
  transition: background-color 0.2s ease;
}

.switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.25),
    0 2px 6px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s cubic-bezier(0.3, 0.8, 0.3, 1);
}

.switch input:checked ~ .switch__track {
  background: var(--accent-solid);
}

.switch input:checked ~ .switch__track .switch__thumb {
  transform: translateX(20px);
}

.switch input:disabled ~ .switch__track {
  opacity: 0.55;
}

.switch input:focus-visible ~ .switch__track {
  outline: 2px solid var(--accent-solid);
  outline-offset: 2px;
}

/* Addresses list (default + partner aliases) */
.address-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
}

.address-row__value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.address-row__tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  border: 1px solid var(--separator);
  border-radius: 999px;
  padding: 1px 8px;
}

/* Blocked senders list */
.blocked-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
}

.blocked-row__value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.blocked-row__unblock {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 2px;
}

/* Block action inside the sender block */
.sender-block {
  position: relative;
}

.sender-block__block {
  position: absolute;
  top: 10px;
  right: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: var(--r-sm);
}

.sender-block__block:active {
  background: var(--press);
  color: var(--danger);
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.18s ease,
    transform 0.22s cubic-bezier(0.25, 0.1, 0.25, 1);
  border: 1px solid
    color-mix(in srgb, var(--bg) 18%, transparent);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  max-width: 80vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast[data-visible="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.toast[data-actionable="true"] {
  pointer-events: auto;
}

.toast__action {
  margin-left: 12px;
  font-weight: 700;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Screen transitions ─────────────────────────────────── */
.screen[data-entering="true"] {
  animation: fadeIn 0.18s ease-out both;
}

/* Detail and settings push in from the right, like a native stack */
.screen--detail[data-entering="true"],
.screen--settings[data-entering="true"] {
  animation: slideInRight 0.24s cubic-bezier(0.3, 0.8, 0.3, 1) both;
}

/* Compose rises like a sheet */
.screen--compose[data-entering="true"] {
  animation: slideUp 0.26s cubic-bezier(0.3, 0.8, 0.3, 1) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(26px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Accessibility / motion ────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── Focus visibility (keyboard) ───────────────────────── */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--accent-solid);
  outline-offset: 2px;
  border-radius: inherit;
}

/* ── Dark scheme refinements ───────────────────────────── */
[data-color-scheme="dark"] .toast {
  border-color: color-mix(in srgb, var(--bg) 28%, transparent);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}
