/* Letterbox — Field direction.
   SF Pro (system), ember orange, warm paper / warm deep grey.
   Compact, flat, tight. No bottom nav. FAB compose. */

:root {
  --paper: #f7f3ec;
  --paper-2: #fffdf8;
  --ink: #1c1915;
  --ink-soft: #57534b;
  --muted: #a39e92;
  --hair: #e6ded1;
  --accent: #ff5c1a;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, var(--paper));
  --accent-ink: color-mix(in srgb, var(--accent) 78%, var(--ink));
  --chip: #efe9dc;
  --field: #f1ece1;
  --shadow: 0 18px 50px -18px rgba(28, 25, 21, 0.35);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

body.dark {
  --paper: #1c1915;
  --paper-2: #242019;
  --ink: #f5f0e8;
  --ink-soft: #b8b0a1;
  --muted: #7d7668;
  --hair: #38322a;
  --chip: #2b2620;
  --field: #2b2620;
  --shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

#inbox, #ctxMenu, .sheet {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  transition: background-color 0.3s ease, color 0.3s ease;
  overscroll-behavior-y: none;
}

button { font-family: inherit; }

#app { max-width: 1280px; margin: 0 auto; position: relative; min-height: 100dvh; }

/* background scroll stays locked while anything is open on top */
body.sheet-open, body.search-open, body.settings-page-open { overflow: hidden; }
@media (max-width: 959px) {
  body.thread-open { overflow: hidden; }
}

/* ---------- header ---------- */
#topbar { padding: calc(18px + var(--sat)) 20px 2px; }

.kick {
  font-size: 11px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent);
}

.title-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }

.title-btn { background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); text-align: left; }
.title-btn .t {
  margin: 0; font-size: 29px; font-weight: 700; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 8px;
}
.title-btn .t em { font-style: normal; color: var(--muted); font-weight: 500; }
.title-btn .t svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }
.title-btn:active { opacity: 0.55; }

.head-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-soft); background: transparent; border: 0; cursor: pointer;
  transition: transform 0.18s var(--ease), background-color 0.2s ease;
}

.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { transform: scale(0.88); background: var(--chip); }

/* ---------- filter chips ---------- */
.chips {
  display: flex; gap: 6px; padding: 10px 16px 2px;
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--hair); background: var(--paper-2); color: var(--ink-soft);
  font-size: 13.5px; font-weight: 600; padding: 7px 14px; border-radius: 99px;
  cursor: pointer; transition: all 0.22s var(--ease); flex-shrink: 0;
  white-space: nowrap; font-family: inherit;
}

.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip:active { transform: scale(0.94); }
#chips.selbar { justify-content: space-between; align-items: center; }
.selbar-btn {
  background: none; border: 0; cursor: pointer; font-family: inherit;
  font-size: 15px; font-weight: 600; color: var(--ink); padding: 8px 4px;
}
.selbar-btn.accent { color: var(--accent); font-weight: 700; }
.selbar-btn:active { opacity: 0.55; }
.selbar-count { font-size: 13.5px; font-weight: 700; color: var(--muted); }

/* ---------- rows ---------- */
#rows { padding: 6px 0 0; }
/* rows open our own long-press menu — never iOS text selection */
.row { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; }
.ptr-spin {
  width: 22px; height: 22px; border-radius: 50%; margin-bottom: 12px;
  border: 2.5px solid var(--hair); border-top-color: var(--accent); opacity: .35;
}
.ptr.ready .ptr-spin { opacity: 1; }
.ptr.spin .ptr-spin { opacity: 1; animation: ptrspin .7s linear infinite; }
@keyframes ptrspin { to { transform: rotate(360deg); } }

.sec {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 20px 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted);
}

.sec i { width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }

.row {
  position: relative; cursor: pointer; overflow: hidden;
  border-bottom: 1px solid var(--hair);
  animation: rise 0.5s var(--ease) both;
  touch-action: pan-y;
}

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

.row-fg {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; background: var(--paper);
  transition: transform 0.3s var(--ease), opacity 0.25s ease;
}

.row-fg.drag { transition: none; }
.row-fg:active { background: var(--chip); }

.av {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
}

body.no-avatars #rows .av, body.no-avatars #searchResults .av { display: none; }

.row .mid { flex: 1; min-width: 0; }

.row .l1 { display: flex; align-items: baseline; gap: 8px; }
.row .name { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.read .name { font-weight: 500; color: var(--ink-soft); }
.row .time { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 500; flex-shrink: 0; }

.row .l2 { display: flex; align-items: center; gap: 8px; margin-top: 2px; min-width: 0; }
.row .subj { font-size: 15px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.read .subj { color: var(--muted); }
.row.unread .subj { font-weight: 600; color: var(--ink); }

.pill {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  padding: 2px 7px; border-radius: 99px; flex-shrink: 0;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.row.read .dot { visibility: hidden; }

.empty {
  padding: 60px 32px; text-align: center; color: var(--muted);
  font-size: 15px; font-weight: 500;
}

.list-end { height: calc(110px + var(--sab)); }

/* ---------- FAB ---------- */
#fab {
  position: fixed; right: 22px; bottom: calc(26px + var(--sab)); z-index: 40;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 28px -8px color-mix(in srgb, var(--accent) 55%, transparent);
  transition: transform 0.25s var(--ease), opacity 0.25s ease;
}

#fab svg { width: 24px; height: 24px; }
#fab:active { transform: scale(0.88); }
body.sheet-open #fab, body.search-open #fab, body.thread-open #fab, body.selecting #fab { transform: scale(0); opacity: 0; pointer-events: none; }

/* ---------- thread ---------- */
#threadPane {
  position: fixed; inset: 0; z-index: 30;
  background: var(--paper);
  transform: translateX(102%);
  transition: transform 0.38s var(--ease);
  display: flex; flex-direction: column;
  max-width: 560px; margin-left: auto;
  box-shadow: -20px 0 60px -30px rgba(0,0,0,0.3);
}

body.thread-open #threadPane { transform: none; }
#threadPane.dragging { transition: none; }
/* edge swipe capture: invisible strip above iframes so the back gesture
   works even when the touch starts on email HTML content */
#threadEdge {
  position: absolute; left: 0; top: 0; bottom: 0; width: 28px;
  z-index: 60;
}

.th-head {
  display: flex; align-items: center; gap: 4px;
  padding: calc(14px + var(--sat)) 12px 8px;
  border-bottom: 1px solid var(--hair);
}

.th-subject { padding: 16px 20px 4px; font-size: 21px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; }
.th-n { padding: 0 20px 2px; font-size: 12.5px; color: var(--muted); font-weight: 500; }

/* thread message cards: flat, no borders — the email's own design carries it */
.tm-card {
  background: none; border: 0; border-radius: 0;
  margin: 0 0 14px;
  animation: rise 0.4s var(--ease) both;
}
/* HTML email cards allow the body to bleed full-width */
.tm-card.html { overflow: visible; }
.tm-card:not(.html) { overflow: hidden; }
.tm-head {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 13px 14px; background: none; border: 0; cursor: pointer;
  font-family: inherit; text-align: left; color: var(--ink);
}
.tm-head .av { width: 38px; height: 38px; font-size: 14px; flex-shrink: 0; }
.tm-who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tm-name { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-to { font-size: 12.5px; color: var(--muted); }
.tm-date { font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.tm-card:not(.open) .tm-sub { border-top: 0; }
.tm-dbtn {
  background: none; border: 0; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  padding: 10px 16px 0; display: block;
}
.tm-detail { padding: 10px 16px 0; font-size: 13px; line-height: 1.7; color: var(--ink); }
.tm-detail div span {
  display: inline-block; width: 46px; flex-shrink: 0;
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted);
}
.tm-body { padding: 10px 16px 4px; overflow-wrap: break-word; overflow-x: hidden; }
/* plain-text mail gets the clean reader style; HTML mail renders in the frame */
.tm-card:not(.html) .tm-body p { font-size: 15px; line-height: 1.65; margin: 0 0 12px; color: var(--ink); }
.tm-card:not(.html) .tm-body a { color: var(--accent); }
/* sandboxed email iframe: the email's own design, sized to its content */
.tm-card.html .tm-body { padding: 0; }
/* plain-text mail keeps the safe padding */
.tm-card:not(.html) .tm-body { padding: 10px 16px 4px; }
.email-frame { width: 100%; border: 0; display: block; background: transparent; }
.tm-body pre { white-space: pre-wrap; }
.tm-retry { display: block; width: 100%; padding: 18px 12px; background: none; border: 0;
  color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; text-align: center; }
.load-more { display: block; width: calc(100% - 32px); margin: 12px 16px 24px; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; }
.load-more:disabled { opacity: 0.6; }
/* fullscreen image viewer for attachments + body images */
.img-viewer { position: fixed; inset: 0; z-index: 200; background: rgba(10, 8, 6, .94);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: iv-in .18s ease-out; }
.img-viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; object-fit: contain; }
.img-viewer-x { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 18px;
  color: #fff; font-size: 15px; font-weight: 600; background: rgba(255,255,255,.16);
  padding: 8px 16px; border-radius: 999px; }
@keyframes iv-in { from { opacity: 0; } to { opacity: 1; } }
/* loading skeleton while a real message body downloads */
.tm-shimmer { display: block; padding: 4px 0 10px; }
.tm-shimmer i { display: block; height: 10px; border-radius: 5px; background: var(--line); margin: 8px 0; animation: tm-pulse 1.2s ease-in-out infinite; }
.tm-shimmer i:nth-child(2) { width: 88%; }
.tm-shimmer i:nth-child(3) { width: 64%; }
@keyframes tm-pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
.tm-atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 16px 14px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--field); border: 1px solid var(--hair); border-radius: 12px;
  padding: 9px 12px; font-family: inherit; color: var(--ink);
  transition: transform 0.18s var(--ease);
}
.att:active { transform: scale(0.96); }
.att svg { width: 17px; height: 17px; color: var(--accent); flex-shrink: 0; }
.att-n { font-size: 13.5px; font-weight: 600; }
.att-s { font-size: 12px; color: var(--muted); }

/* thread count badge on rows */
.tcount {
  font-size: 11px; font-weight: 600; color: var(--muted);
  margin-left: 6px; vertical-align: 1px;
}

.th-meta { display: flex; align-items: center; gap: 10px; padding: 10px 20px 14px; border-bottom: 1px solid var(--hair); }
.th-meta .who { font-size: 14px; font-weight: 650; }
.th-meta .addr { font-size: 12.5px; color: var(--muted); }
.th-meta .pill { margin-left: auto; }

.th-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
/* HTML email body breaks out of the thread padding for true edge-to-edge,
   like Spark: the email's own design fills the screen */
.tm-card.html .tm-body { padding: 0; margin-left: -20px; margin-right: -20px; }
.th-body p { font-size: 15.5px; line-height: 1.65; margin: 0 0 14px; color: var(--ink); }

.sum-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px; margin-bottom: 14px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--hair); background: var(--field); color: var(--ink);
  font-size: 14px; font-weight: 650; font-family: inherit;
  transition: transform 0.18s var(--ease);
}
.sum-btn svg { width: 16px; height: 16px; color: var(--accent); }
.sum-btn:active { transform: scale(0.97); }

.sum-card {
  background: var(--field); border-radius: 14px; padding: 14px 16px; margin-bottom: 16px;
  animation: rise 0.4s var(--ease) both;
}
.sum-card .kick {
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
}
.sum-card ul { margin: 0; padding-left: 18px; }
.sum-card li { font-size: 14px; line-height: 1.55; margin-bottom: 6px; color: var(--ink); }
.sum-card li:last-child { margin-bottom: 0; }
.sum-card .fine { font-size: 11.5px; color: var(--muted); margin-top: 10px; }

.th-actions { display: flex; gap: 8px; padding: 12px 20px calc(16px + var(--sab)); border-top: 1px solid var(--hair); }

.tbtn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px; border-radius: 14px; border: 1px solid var(--hair);
  background: var(--paper-2); color: var(--ink); font-size: 14px; font-weight: 650; cursor: pointer;
  transition: transform 0.18s var(--ease);
}
.tbtn:active { transform: scale(0.96); }
/* ensure the hidden attribute works even when display is set by a class */
[hidden] { display: none !important; }
/* move-to-folder action sheet */
.move-sheet { position: fixed; inset: 0; z-index: 200; }
.move-sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.move-sheet-box {
  position: absolute; left: 16px; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--paper); border-radius: 20px; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
  animation: sheetUp 0.25s var(--ease);
}
.move-sheet-title { font-size: 17px; font-weight: 700; text-align: center; margin-bottom: 4px; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
.tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn svg { width: 17px; height: 17px; }

/* ---------- scrim + sheets ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 48; background: rgba(20, 16, 12, 0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
body.sheet-open .scrim { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--paper-2); color: var(--ink);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(24px + var(--sab));
  transform: translateY(103%);
  transition: transform 0.42s var(--ease);
  max-width: 560px; margin: 0 auto;
  box-shadow: var(--shadow);
  max-height: 92dvh; overflow-y: auto;
}

body.sheet-open-compose #composeSheet,
body.sheet-open-settings #settingsSheet,
body.sheet-open-inbox #inboxSheet,
body.sheet-open-option #optionSheet { transform: none; }

.grab { width: 40px; height: 4px; border-radius: 99px; background: var(--hair); margin: 6px auto 4px; }

.sheet-head { display: flex; align-items: center; margin-bottom: 6px; }
.sheet-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-head .icon-btn { margin-left: auto; }

.field { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--hair); }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); width: 52px; flex-shrink: 0; }
.field input { flex: 1; border: 0; background: none; font: inherit; font-size: 15px; color: var(--ink); outline: none; min-width: 0; }
.field input::placeholder { color: var(--muted); }

#cBody {
  width: 100%; min-height: 180px; border: 0; background: none; resize: none;
  font: inherit; font-size: 15.5px; line-height: 1.6; color: var(--ink);
  padding: 14px 0; outline: none;
}
#cBody::placeholder { color: var(--muted); }

.send-btn {
  width: 100%; padding: 15px; border: 0; border-radius: 16px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  transition: transform 0.18s var(--ease);
  margin-top: 6px;
}
.send-btn:active { transform: scale(0.97); }

.send-row { display: flex; gap: 10px; margin-top: 6px; }
.send-row .send-btn { margin-top: 0; }
.clock-btn {
  width: 56px; border-radius: 16px; border: 1px solid var(--hair);
  background: var(--paper-2); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: transform 0.18s var(--ease);
}
.clock-btn svg { width: 20px; height: 20px; }
.clock-btn:active { transform: scale(0.92); }

.sched-custom { padding: 14px 4px 4px; display: flex; gap: 10px; }
.sched-custom input {
  flex: 1; border: 1px solid var(--hair); border-radius: 12px; padding: 10px 12px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--field); min-width: 0;
}
.sched-custom .send-btn { width: auto; padding: 10px 18px; margin: 0; font-size: 14px; }

/* ---------- settings sheet ---------- */
.acct {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 4px; background: none; border: 0; border-bottom: 1px solid var(--hair);
  cursor: pointer; text-align: left; color: var(--ink);
}
.acct .av { width: 40px; height: 40px; font-size: 13px; }
.acct .a-name { font-size: 15px; font-weight: 650; }
.acct .a-addr { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.acct .check {
  margin-left: auto; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(0.6); transition: all 0.25s var(--ease);
}
.acct .check svg { width: 13px; height: 13px; }
.acct.off { opacity: 0.45; }
.acct.on .check { opacity: 1; transform: none; }

.set-sec {
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); margin: 22px 0 10px;
}

.seg {
  display: flex; background: var(--field); border-radius: 14px; padding: 4px; gap: 4px;
}
.seg button {
  flex: 1; border: 0; background: none; border-radius: 10px; cursor: pointer;
  padding: 10px; font-size: 14px; font-weight: 650; color: var(--ink-soft);
  transition: all 0.25s var(--ease);
}
.seg button.on { background: var(--paper-2); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }

.set-row {
  display: flex; align-items: center; width: 100%; gap: 12px;
  background: none; border: 0; padding: 14px 4px; cursor: pointer; text-align: left; color: var(--ink);
}
.set-label { font-size: 15px; font-weight: 650; flex: 1; }
.set-sub { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin-top: 2px; }

.switch {
  width: 50px; height: 30px; border-radius: 99px; background: var(--hair);
  position: relative; flex-shrink: 0; transition: background-color 0.25s ease;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.28s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

.set-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 26px; }

/* ---------- search ---------- */
#searchOverlay {
  position: fixed; inset: 0; z-index: 60; background: var(--paper);
  opacity: 0; pointer-events: none; transition: opacity 0.28s ease;
  display: flex; flex-direction: column;
}
body.search-open #searchOverlay { opacity: 1; pointer-events: auto; }

.search-top { display: flex; align-items: center; gap: 10px; padding: calc(14px + var(--sat)) 16px 10px; }
.search-box {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--field); border-radius: 14px; padding: 11px 14px;
}
.search-box svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search-box input {
  flex: 1; border: 0; background: none; outline: none;
  font: inherit; font-size: 16px; color: var(--ink); min-width: 0;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input::-webkit-search-cancel-button { display: none; }

.text-btn {
  background: none; border: 0; color: var(--accent); font-size: 15px; font-weight: 650;
  cursor: pointer; padding: 8px 4px; flex-shrink: 0;
}

#searchResults { flex: 1; overflow-y: auto; }
.search-hint { padding: 40px 32px; text-align: center; color: var(--muted); font-size: 14.5px; }

/* rich search */
.search-filters {
  display: flex; align-items: center; gap: 8px; overflow-x: auto;
  padding: 2px 16px 12px; scrollbar-width: none;
}
.search-filters::-webkit-scrollbar { display: none; }
.fchip {
  flex-shrink: 0; border: 1px solid var(--hair); background: var(--paper-2);
  color: var(--ink); font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 99px; cursor: pointer;
  transition: all 0.2s var(--ease);
}
.fchip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.fsep { width: 1px; align-self: stretch; background: var(--hair); flex-shrink: 0; margin: 4px 2px; }
.sr-count { padding: 4px 20px 2px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
#searchResults .sec { margin-top: 6px; }
#searchResults mark, .srp-n mark, .srp-a mark {
  background: none; color: var(--accent); font-weight: 700;
}
.sr-person {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 0; padding: 10px 20px; cursor: pointer; text-align: left;
  font: inherit; color: var(--ink);
}
.sr-person .av { width: 40px; height: 40px; font-size: 15px; flex-shrink: 0; }
.srp-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.srp-n { font-size: 15px; font-weight: 650; }
.srp-a { font-size: 12.5px; color: var(--muted); }
.srp-go { font-size: 13px; font-weight: 600; color: var(--accent); flex-shrink: 0; }
.sr-recent {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 0; padding: 11px 20px; cursor: pointer; text-align: left;
  font: inherit; font-size: 15px; color: var(--ink);
}
.sr-recent svg { width: 17px; height: 17px; color: var(--muted); flex-shrink: 0; }
.sr-recent span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-clear {
  display: block; margin: 6px auto 0; background: none; border: 0; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); padding: 8px;
}
.sr-tips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 20px 30px; }
.tip {
  border: 1px dashed var(--hair); background: none; border-radius: 12px;
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink);
  padding: 9px 14px; cursor: pointer;
}
.tip:active { transform: scale(0.96); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--sab)); z-index: 70;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 600; padding: 12px 20px; border-radius: 99px;
  transition: all 0.3s var(--ease); white-space: nowrap;
  box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* undo send bar */
#undoBar {
  position: fixed; left: 0; right: 0; bottom: calc(100px + var(--sab)); z-index: 70;
  width: fit-content; max-width: calc(100vw - 48px); margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: #2b2b2b; color: #f5f5f5;
  font-size: 14px; font-weight: 500; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); white-space: nowrap; box-sizing: border-box;
}
#undoBar[hidden] { display: none; }
#undoBar .u-msg { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#undoBar .u-count { opacity: 0.6; font-variant-numeric: tabular-nums; font-size: 13px; }
#undoBtn {
  border: 0; cursor: pointer; font: inherit; font-weight: 700; font-size: 14px;
  background: none; color: var(--accent); padding: 4px 8px; text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* settings hub groups */
.group-card { margin-bottom: 20px; }
.group-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); padding: 0 22px 8px;
}
.group {
  background: var(--paper-2); border: 1px solid var(--hair); border-radius: 20px;
  margin: 0 14px; overflow: hidden;
}
.group .menu-row, .group .set-row { border-bottom: 1px solid var(--hair); padding-left: 16px; padding-right: 14px; }
.group .menu-row:last-child, .group .set-row:last-child { border-bottom: 0; }
.fine-pad { padding: 2px 22px 14px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.ver { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0 30px; }

/* signatures */
.sig-field { margin: 0 0 16px; }
.sig-name { display: block; font-size: 13px; font-weight: 650; color: var(--ink); margin-bottom: 8px; }
.sig-ta {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 74px;
  border: 1px solid var(--hair); border-radius: 14px; background: var(--paper-2);
  padding: 12px 14px; font: inherit; font-size: 14.5px; line-height: 1.55; color: var(--ink);
  outline: none;
}
.sig-ta:focus { border-color: var(--accent); }

/* templates */
.tpl-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--paper-2); border: 1px solid var(--hair); border-radius: 16px;
  padding: 12px 8px 12px 16px; margin-bottom: 8px;
}
.tpl-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tpl-title { font-size: 14.5px; font-weight: 650; }
.tpl-body { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-del {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 8px 10px; flex-shrink: 0;
}
.art.wn { margin-bottom: 14px; }

/* ---------- row swipe actions ---------- */
.swipe-bg {
  position: absolute; top: 0; bottom: 0; width: 110px; z-index: 0;
  display: flex; align-items: center; gap: 8px; padding: 0 20px;
  font-size: 13px; font-weight: 700; color: #fff;
  opacity: 0; transition: opacity 0.15s ease;
}
.swipe-bg.show { opacity: 1; }
.swipe-bg.left { left: 0; justify-content: flex-start; }
.swipe-bg.right { right: 0; justify-content: flex-end; }
.swipe-bg svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- density + preview ---------- */
body.d-compact .row-fg { padding: 8px 20px; gap: 10px; }
body.d-compact .av { width: 34px; height: 34px; font-size: 12px; }
body.d-compact .row .name { font-size: 14px; }
body.d-compact .row .subj { font-size: 13px; }

.row .snip {
  display: none; font-size: 14px; color: var(--muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.show-preview .row .snip { display: block; }

/* ---------- accent swatches ---------- */
.swatches { display: flex; gap: 12px; flex-wrap: wrap; padding: 6px 4px 12px; }
.swatch {
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  transition: transform 0.2s var(--ease); position: relative; flex-shrink: 0;
}
.swatch:active { transform: scale(0.88); }
.swatch.on { box-shadow: 0 0 0 3px var(--paper-2), 0 0 0 5px var(--ink); }
.swatch.custom { background: var(--field); color: var(--ink-soft); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.swatch.custom input { position: absolute; inset: -10px; opacity: 0; cursor: pointer; }
.swatch.custom svg { width: 18px; height: 18px; pointer-events: none; }

/* ---------- option rows + sheets ---------- */
.opt-row .set-value {
  margin-left: auto; color: var(--muted); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 5px; flex-shrink: 0;
}
.opt-row .set-value svg { width: 14px; height: 14px; }

.opt {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 4px; background: none; border: 0; border-bottom: 1px solid var(--hair);
  font-size: 15.5px; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left;
}
.opt .cnt { color: var(--muted); font-weight: 500; font-size: 13.5px; }
.opt .radio {
  margin-left: auto; width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--hair); display: flex; align-items: center; justify-content: center;
}
.opt.on .radio { border-color: var(--accent); }
.opt.on .radio::after { content: ""; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.opt:active { opacity: 0.6; }

/* ---------- settings pages ---------- */
.settings-page {
  position: fixed; inset: 0; z-index: 45;
  background: var(--paper); color: var(--ink);
  transform: translateX(103%);
  transition: transform 0.38s var(--ease);
  display: flex; flex-direction: column;
}
.settings-page.open { transform: none; }
.settings-page.dragging { transition: none; }

.sp-head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(14px + var(--sat)) 12px 10px;
  border-bottom: 1px solid var(--hair); flex-shrink: 0;
}
.sp-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.sp-body { flex: 1; overflow-y: auto; padding: 4px 20px calc(30px + var(--sab)); }
.sp-body .set-sec:first-child { margin-top: 14px; }

.menu-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 0; padding: 13px 4px; cursor: pointer; text-align: left;
  border-bottom: 1px solid var(--hair); color: var(--ink);
}
.menu-row:active { opacity: 0.55; }
.menu-row .m-text { flex: 1; min-width: 0; }
.menu-row .m-label { display: block; font-size: 15.5px; font-weight: 600; }
.menu-row .m-sub { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin-top: 1px; }
.menu-row > svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.menu-row .m-ico {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: var(--field); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.menu-row .m-ico svg { width: 19px; height: 19px; }

/* ---------- accounts page ---------- */
.acct-card {
  background: var(--paper-2); border: 1px solid var(--hair); border-radius: 18px;
  padding: 6px 16px; margin-bottom: 14px;
}
.acct-head { display: flex; align-items: center; gap: 12px; padding: 12px 0 6px; }
.acct-head .av { width: 40px; height: 40px; font-size: 14px; }
.acct-id { min-width: 0; }
.acct-id .a-name { font-size: 16px; font-weight: 700; }
.acct-id .a-addr { font-size: 12.5px; color: var(--muted); margin-top: 1px; display: block; }
.acct-card .set-row { border-bottom: 0; padding-left: 0; padding-right: 0; }
.acct-card .set-row + .set-row { border-top: 1px solid var(--hair); }
.set-label.danger { color: #e5484d; }

.add-acct {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 1px dashed var(--hair); border-radius: 18px;
  padding: 15px 16px; cursor: pointer; color: var(--ink);
  font-size: 15.5px; font-weight: 600; font-family: inherit; margin-bottom: 14px;
}
.add-acct:active { opacity: 0.6; }
.add-acct .plus {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.add-acct .plus svg { width: 15px; height: 15px; }
.page-note { font-size: 12.5px; line-height: 1.55; color: var(--muted); padding: 0 4px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.field input {
  width: 100%; border: 1px solid var(--hair); border-radius: 14px; padding: 13px 14px;
  font: inherit; font-size: 15.5px; color: var(--ink); background: var(--paper-2);
  outline: none; -webkit-appearance: none; appearance: none;
}
.field input:focus { border-color: var(--accent); }

/* ---------- help ---------- */
.help-search { margin-top: 14px; }
.art { padding-top: 6px; }
.art p { font-size: 15.5px; line-height: 1.65; color: var(--ink); margin: 0 0 14px; }
.art p b { font-weight: 700; }

.danger-row {
  display: block; width: 100%; background: none; border: 0; cursor: pointer;
  padding: 14px 20px; font-size: 14px; font-weight: 700; color: #e5484d; text-align: center;
  border-bottom: 1px solid var(--hair);
}
.danger-row:active { opacity: 0.55; }

/* ---------- long-press context menu ---------- */
#ctxScrim { position: fixed; inset: 0; z-index: 88; background: transparent; }
.ctx-menu {
  position: fixed; z-index: 89; min-width: 248px; max-width: 300px;
  background: color-mix(in srgb, var(--paper-2) 88%, transparent);
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-radius: 20px; padding: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  animation: ctxIn 0.22s var(--ease) both;
  max-height: 70vh; overflow-y: auto;
}
@keyframes ctxIn { from { opacity: 0; transform: scale(0.92); } }
.ctx-menu button {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 11px 12px; border: 0; background: none; cursor: pointer;
  font-size: 16px; color: var(--ink); border-radius: 13px; text-align: left; font-family: inherit;
}
.ctx-menu button:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.ctx-menu button svg { width: 21px; height: 21px; flex-shrink: 0; color: var(--ink-soft); }
.ctx-menu button.danger { color: #e5484d; }
.ctx-menu button.danger svg { color: #e5484d; }
.ctx-sep { height: 1px; background: var(--hair); margin: 5px 12px; }

.pinbadge { display: inline-flex; vertical-align: -2px; margin: 0 6px 0 2px; color: var(--ink-soft); flex-shrink: 0; }
.pinbadge svg { width: 13px; height: 13px; }
.pinbadge.big { vertical-align: -2px; margin-right: 8px; color: var(--ink-soft); }
.pinbadge.big svg { width: 16px; height: 16px; }

/* ---------- bulk select ---------- */
.selbox {
  position: absolute; left: 16px; top: 50%; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--muted); background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(-50%) scale(0.6);
  transition: all 0.25s var(--ease); pointer-events: none;
}
.selbox svg { width: 12px; height: 12px; color: #fff; opacity: 0; }
body.selecting .selbox { opacity: 1; transform: translateY(-50%) scale(1); }
.selbox.on { background: var(--accent); border-color: var(--accent); }
.selbox.on svg { opacity: 1; }
body.selecting .row-fg { padding-left: 50px; }
body.selecting .swipe-bg { display: none; }

#bulkBar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 42;
  background: color-mix(in srgb, var(--paper-2) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--hair);
  padding: 10px 12px calc(14px + var(--sab));
  display: flex; align-items: center; gap: 4px;
  transform: translateY(110%); transition: transform 0.35s var(--ease);
}
body.selecting #bulkBar { transform: none; }
#bulkCount { font-size: 13px; font-weight: 700; color: var(--muted); padding: 0 8px; white-space: nowrap; }
.bulk-actions { flex: 1; display: flex; justify-content: space-around; }
.bulk-actions button {
  background: none; border: 0; cursor: pointer; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; padding: 6px 10px;
}
.bulk-actions button:active { opacity: 0.55; }
.bulk-actions button svg { width: 20px; height: 20px; }
.bulk-actions button.danger { color: #e5484d; }
#bulkDone {
  color: var(--accent); font-weight: 700; font-size: 15px;
  background: none; border: 0; padding: 10px 8px; cursor: pointer; flex-shrink: 0;
}

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  #app { display: flex; }
  #listPane { width: 430px; flex-shrink: 0; border-right: 1px solid var(--hair); min-height: 100dvh; }
  #threadPane {
    position: static; transform: none; flex: 1; max-width: none;
    box-shadow: none; min-height: 100dvh; border: 0;
  }
  #threadPane:empty { display: flex; align-items: center; justify-content: center; }
  #threadPane:empty::after {
    content: "Pick a thread"; color: var(--muted); font-size: 15px; font-weight: 500;
  }
  .th-back { display: none; }
  #fab { right: calc(50% - 610px); }
  body.thread-open #fab { transform: none; opacity: 1; pointer-events: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- font size prefs ---------- */
body.f-small { font-size: 14px; }
body.f-small .row .name { font-size: 15px; }
body.f-small .row .subj { font-size: 13px; }
body.f-small .row .snip { font-size: 12px; }
body.f-medium { font-size: 16px; }
body.f-large { font-size: 18px; }
body.f-large .row .name { font-size: 19px; }
body.f-large .row .subj { font-size: 17px; }
body.f-large .row .snip { font-size: 15px; }
body.f-large .row .time { font-size: 14px; }

/* ---------- font family prefs ---------- */
body.ff-serif { font-family: "New York", Georgia, "Times New Roman", serif; }
body.ff-rounded { font-family: "SF Pro Rounded", ui-rounded, "SF Pro", system-ui, sans-serif; }
