/* TempMailer — Telegram mini app look. Dark is the default; .light on <html> switches to Telegram light. */

:root {
  --font-sans: "Google Sans Flex", "Google Sans", Roboto, system-ui, -apple-system, sans-serif;

  /* Dark (sampled from Telegram) */
  --tg-bg: #1b2026;
  --tg-section: #212a33;
  --tg-section-pressed: #2a3540;
  --tg-glass: rgba(33, 42, 51, 0.55);
  --tg-glass-pressed: rgba(53, 66, 80, 0.55);
  --tg-tabbar: rgba(28, 33, 39, 0.72);
  --tg-tab-active: rgba(77, 177, 253, 0.13);
  --tg-tab-text: #ffffff;
  --tg-text: #ffffff;
  --tg-hint: #97a4ad;
  --tg-hint-15: rgba(151, 164, 173, 0.15);
  --tg-link: #4db1fd;
  --tg-link-soft: rgba(77, 177, 253, 0.14);
  --tg-link-ring: rgba(77, 177, 253, 0.5);
  --tg-divider: #1a2129;
  --tg-chevron: #616d79;
  --tg-chevron-60: rgba(97, 109, 121, 0.6);
  --tg-destructive: #f45a56;
  --tg-overlay: rgba(0, 0, 0, 0.6);
  --tg-gold: #fabb41;
  --on-accent: #ffffff;

  --brand: #1059f0;
  --brand-white: #fcfcfc;

  /* Letter avatar gradients */
  --gradient-red: linear-gradient(180deg, #ff847d, #ed4a49);
  --gradient-orange: linear-gradient(180deg, #ffb95b, #fa8927);
  --gradient-violet: linear-gradient(180deg, #a3a0f3, #6588f0);
  --gradient-green: linear-gradient(180deg, #9ce66f, #4cc157);
  --gradient-aqua: linear-gradient(180deg, #5dedd1, #1ec8b4);
  --gradient-blue: linear-gradient(180deg, #59c5f5, #2b99e7);
  --gradient-pink: linear-gradient(180deg, #f594c3, #e5598e);

  /* Flat design: no shadows anywhere. */
  --elev-card: none;
  --elev-float: none;

  /* Compact grid: one side gutter and one card radius everywhere. */
  --gutter: 12px;
  --radius-card: 12px;

  /* Telegram sets these inside the app; the fallbacks cover a normal browser. */
  --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 32px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));

  color-scheme: dark;
}

.light {
  --tg-bg: #efeff4;
  --tg-section: #ffffff;
  --tg-section-pressed: #e9e9ee;
  --tg-glass: rgba(255, 255, 255, 0.55);
  --tg-glass-pressed: rgba(120, 120, 128, 0.16);
  --tg-tabbar: rgba(255, 255, 255, 0.72);
  --tg-tab-active: rgba(36, 129, 204, 0.12);
  --tg-tab-text: #121212;
  --tg-text: #121212;
  --tg-hint: #8e8e93;
  --tg-hint-15: rgba(142, 142, 147, 0.15);
  --tg-link: #2481cc;
  --tg-link-soft: rgba(36, 129, 204, 0.1);
  --tg-link-ring: rgba(36, 129, 204, 0.5);
  --tg-divider: #e3e3e8;
  --tg-chevron: #c4c4c7;
  --tg-chevron-60: rgba(196, 196, 199, 0.6);
  --tg-destructive: #ff3b30;
  --tg-overlay: rgba(0, 0, 0, 0.4);
  --tg-gold: #ea9602;

  --elev-card: none;
  --elev-float: none;

  color-scheme: light;
}

/* ---------- Base ---------- */

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--tg-bg);
  color: var(--tg-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

input,
textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
  font: inherit;
  color: inherit;
}

/* Nothing in the app can be selected, copied or saved by pressing and holding.
   Typing fields (notes, search, folder names) keep normal editing. */
*:not(input):not(textarea) {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}
a,
img,
svg {
  -webkit-user-drag: none;
}
img {
  pointer-events: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: inherit;
}

h1,
h2,
p {
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--tg-link);
  outline-offset: 2px;
}

::selection {
  background: var(--tg-link-soft);
}

[hidden] {
  display: none !important;
}

.icon {
  display: block;
  flex-shrink: 0;
}

/* ---------- Utilities ---------- */

.grow { flex: 1; min-width: 0; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--tg-hint); }
.link { color: var(--tg-link); }
.chev { color: var(--tg-chevron); }
.danger { color: var(--tg-destructive); }
.bold { font-weight: 500; }
.fs12 { font-size: 12px; }
.fs125 { font-size: 12.5px; line-height: 16px; }
.fs13 { font-size: 13px; }
.fs14 { font-size: 14px; }
.fs15 { font-size: 15px; }
.fs16 { font-size: 16px !important; }
.fs20 { font-size: 20px !important; }
.lh19 { line-height: 19px; }
.ml8 { margin-left: 8px; }
.px16 { padding-left: 16px; padding-right: 16px; }
.mt-3, .mt12 { margin-top: 12px; }
.mt-4, .mt16 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }

.g-red { background-image: var(--gradient-red); }
.g-orange { background-image: var(--gradient-orange); }
.g-violet { background-image: var(--gradient-violet); }
.g-green { background-image: var(--gradient-green); }
.g-aqua { background-image: var(--gradient-aqua); }
.g-blue { background-image: var(--gradient-blue); }
.g-pink { background-image: var(--gradient-pink); }

/* Tap feedback: a small squeeze, like native buttons. */
.pressable {
  transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
}
.pressable:active {
  transform: scale(0.97);
}

@keyframes page-in {
  from { opacity: 0.96; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  50% { opacity: 0.5; }
}
.spin { animation: spin 1s linear infinite; }

/* ---------- Layout ---------- */

.page {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--tg-bg);
  color: var(--tg-text);
}

.page-inner {
  max-width: 480px;
  margin: 0 auto;
  padding-top: calc(var(--safe-top) + 6px);
  padding-bottom: 40px;
  animation: page-in 0.16s ease-out;
}
.page-inner.has-tabs {
  padding-bottom: calc(var(--safe-bottom) + 76px);
}

.page-header { padding: 2px calc(var(--gutter) + 6px) 0; }
.ph-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-header h1 { font-size: 24px; font-weight: 500; line-height: 30px; letter-spacing: -0.01em; }
.ph-sub { margin-top: 4px; font-size: 13px; line-height: 18px; color: var(--tg-hint); }

.back-link { margin: -24px 0 8px; padding: 0 4px; }
.back-link button {
  display: inline-flex;
  height: 32px;
  align-items: center;
  padding-right: 8px;
  font-size: 15px;
  color: var(--tg-link);
}

.logo { border-radius: 999px; object-fit: cover; display: block; }

/* ---------- Lists ---------- */

.section-title {
  margin: 18px 0 6px;
  display: flex;
  min-height: 18px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 calc(var(--gutter) + 14px);
}
.section-title h2 {
  font-size: 12.5px;
  font-weight: 500;
  text-transform: uppercase;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--tg-hint);
}
.section-footer {
  margin-top: 6px;
  padding: 0 calc(var(--gutter) + 14px);
  font-size: 12.5px;
  line-height: 17px;
  color: var(--tg-hint);
}

.card {
  margin-left: var(--gutter);
  margin-right: var(--gutter);
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--tg-section);
}

.row {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  text-align: left;
  transition: background-color 0.15s;
}
.row:not(.first)::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: var(--inset, 14px);
  height: 1px;
  background: var(--tg-divider);
}
.row.clickable { cursor: pointer; }
.row.clickable:active { background: var(--tg-section-pressed); }

.list-row { min-height: 44px; gap: 12px; padding: 7px 12px 7px 14px; }
.list-row.has-icon { --inset: 54px; }
.lr-label { font-size: 15px; line-height: 20px; }
.lr-detail { font-size: 12px; line-height: 15px; color: var(--tg-hint); }
.row-value { max-width: 45%; font-size: 14px; color: var(--tg-hint); }

.tile {
  display: flex;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: var(--brand-white);
}

.avatar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 500;
  color: var(--brand-white);
  user-select: none;
}

.switch {
  display: inline-flex;
  height: 24px;
  width: 40px;
  flex-shrink: 0;
  align-items: center;
  border-radius: 999px;
  padding: 3px;
  background: var(--tg-chevron-60);
  transition: background-color 0.15s;
}
.switch[aria-checked="true"] { background: var(--tg-link); }
.switch .thumb {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--brand-white);
  transition: transform 0.15s;
}
.switch[aria-checked="true"] .thumb { transform: translateX(16px); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 24px;
  text-align: center;
}
.es-icon {
  display: flex;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-link-soft);
  color: var(--tg-link);
}
.es-title { margin-top: 12px; font-size: 15px; font-weight: 500; }
.es-text { margin-top: 4px; max-width: 270px; font-size: 13px; line-height: 18px; color: var(--tg-hint); }

.del-btn {
  display: flex;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  color: var(--tg-chevron);
}
.del-btn:active { color: var(--tg-destructive); }

.round-btn {
  display: flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-section);
  color: var(--tg-link);
}

/* ---------- Inbox ---------- */

.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 28px;
  text-align: center;
}
.profile h1 { margin-top: 12px; font-size: 20px; font-weight: 500; line-height: 1; }
.profile p { margin-top: 6px; font-size: 13px; line-height: 18px; color: var(--tg-hint); }
.learn-more { display: inline-flex; align-items: center; vertical-align: bottom; }
.learn-more .icon { margin-left: -1px; }

.addr-btn {
  display: flex;
  min-height: 48px;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  text-align: left;
  transition: background-color 0.15s;
}
.addr-btn:active { background: var(--tg-section-pressed); }
.addr-text { flex: 1; min-width: 0; font-size: 15px; line-height: 20px; word-break: break-all; }
.copy-dot {
  display: flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--tg-link);
  transition: background-color 0.15s, color 0.15s;
}
.copy-dot.done { background: var(--tg-link); color: var(--on-accent); }

.chips-2 {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 var(--gutter);
}
.chip {
  display: flex;
  height: 34px;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--tg-section);
  padding: 0 14px;
  font-size: 13.5px;
  color: var(--tg-link);
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.inbox-sec { margin-top: 18px; padding: 0 var(--gutter); }
.inbox-head {
  margin-bottom: 6px;
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 0 6px;
}
.inbox-head h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 500; line-height: 24px; }
.count {
  display: inline-flex;
  height: 20px;
  min-width: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-section);
  padding: 0 6px;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--tg-hint);
}
.icon-btn {
  display: flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-section);
  color: var(--tg-hint);
  transition: color 0.15s;
}
.icon-btn:hover { color: var(--tg-link); }
.icon-btn:disabled { pointer-events: none; opacity: 0.5; }

.inbox-empty {
  display: flex;
  min-height: 52px;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-card);
  background: var(--tg-section);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 20px;
  color: var(--tg-hint);
}
.inbox-empty .dot {
  display: flex;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-section-pressed);
}

.list {
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--tg-section);
}
.mail-row { min-height: 62px; gap: 12px; padding: 9px 14px; --inset: 60px; }
.mr-top { display: flex; align-items: baseline; gap: 8px; }
.mr-name { flex: 1; min-width: 0; font-size: 15px; line-height: 19px; }
.mr-time { flex-shrink: 0; font-size: 12px; color: var(--tg-hint); }
.mr-mid { display: flex; align-items: center; gap: 8px; }
.mr-subject { flex: 1; min-width: 0; font-size: 13.5px; line-height: 18px; }
.unread-dot { width: 8px; height: 8px; flex-shrink: 0; border-radius: 999px; background: var(--tg-link); }
.mr-excerpt { font-size: 13px; line-height: 17px; color: var(--tg-hint); }

.addr-row { height: 50px; gap: 12px; padding: 0 8px 0 14px; --inset: 58px; }
.addr-row.first { padding-right: 14px; }
.plus-dot {
  display: flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--tg-link-soft);
  color: var(--tg-link);
}
.in-use {
  margin-right: 4px;
  display: flex;
  height: 24px;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  background: var(--tg-link-soft);
  padding: 0 8px;
  font-size: 11.5px;
  color: var(--tg-link);
}

/* ---------- Email ---------- */

.subject { padding: 0 calc(var(--gutter) + 6px); font-size: 19px; font-weight: 500; line-height: 24px; overflow-wrap: anywhere; }
.sender-row { gap: 10px; padding: 8px 14px; }
.sender-name { font-size: 15px; font-weight: 500; line-height: 19px; }
.sender-email { font-size: 12.5px; line-height: 16px; color: var(--tg-hint); }
.sender-time { flex-shrink: 0; align-self: flex-start; padding-top: 2px; font-size: 12px; color: var(--tg-hint); }
.to-row { height: 36px; padding: 0 14px; font-size: 13px; }

.mail-body { margin: 0 var(--gutter); overflow: hidden; border-radius: var(--radius-card); background: var(--tg-section); }
.mail-plain {
  background: var(--tg-section);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 20px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.mail-frame { display: block; width: 100%; border: 0; background: #ffffff; transition: height 0.15s ease; }
.mail-frame.dark { background: var(--tg-section); }
.attachments {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 calc(var(--gutter) + 14px);
  font-size: 12.5px;
  color: var(--tg-hint);
}
.preview-text { padding: 12px 14px; font-size: 14px; line-height: 20px; }

.skeleton { padding: 0 var(--gutter); animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
.sk-line { margin: 0 4px; height: 20px; width: 66%; border-radius: 4px; background: var(--tg-section); }
.sk-box { margin-top: 12px; border-radius: var(--radius-card); background: var(--tg-section); }
.sk-box.h96 { margin-top: 20px; height: 96px; }
.sk-box.h220 { height: 220px; }

.not-found { padding: 64px 32px 0; text-align: center; }
.nf-title { font-size: 16px; font-weight: 500; }
.nf-text { margin: 4px 0 16px; font-size: 13px; color: var(--tg-hint); }

.note-input {
  display: block;
  min-height: 84px;
  width: 100%;
  resize: vertical;
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 21px;
  outline: none;
}
.note-input::placeholder,
.note-box textarea::placeholder,
.search input::placeholder,
.folder-form input::placeholder {
  color: var(--tg-hint);
  opacity: 1;
}

/* ---------- History ---------- */

.search {
  margin: 12px var(--gutter) 0;
  display: flex;
  height: 40px;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-card);
  background: var(--tg-section);
  padding: 0 12px;
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color 0.15s;
}
.search:focus-within { outline-color: var(--tg-link-ring); }
.search input {
  height: 100%;
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }

.fchips {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 var(--gutter) 2px;
  scrollbar-width: none;
}
.fchips::-webkit-scrollbar { display: none; }
.fchip {
  display: flex;
  height: 30px;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--tg-section);
  padding: 0 14px;
  font-size: 13.5px;
  color: var(--tg-text);
  white-space: nowrap;
}
.fchip .fchip-count { font-size: 12px; color: var(--tg-hint); }
.fchip.active { background: var(--tg-link); color: var(--on-accent); }
.fchip.active .fchip-count { color: inherit; opacity: 0.8; }
.fchip-add {
  display: flex;
  height: 30px;
  flex-shrink: 0;
  align-items: center;
  border-radius: 999px;
  border: 1px dashed var(--tg-chevron);
  padding: 0 14px;
  font-size: 13.5px;
  color: var(--tg-link);
  white-space: nowrap;
}

.history-list { --inset: 62px; }
.swipe { position: relative; overflow: hidden; }
.swipe:not(.first)::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: var(--inset, 16px);
  z-index: 2;
  height: 1px;
  background: var(--tg-divider);
}
.swipe-actions { position: absolute; top: 0; bottom: 0; right: 0; display: flex; }
.swipe-act {
  display: flex;
  width: 66px;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--brand-white);
}
.swipe-fg {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  cursor: pointer;
  touch-action: pan-y;
  align-items: center;
  background: var(--tg-section);
  text-align: left;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.15s;
}
.swipe-fg.pressed { background: var(--tg-section-pressed); }
.history-row { align-items: flex-start; gap: 12px; padding: 9px 12px 9px 14px; }
.hr-top { display: flex; align-items: center; gap: 6px; }
.pin-mini { color: var(--tg-hint); transform: rotate(45deg); fill: currentColor; }
.hr-note {
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  line-height: 17px;
  color: var(--tg-gold);
}
.folder-tag {
  margin-top: 4px;
  display: inline-flex;
  height: 18px;
  align-items: center;
  border-radius: 5px;
  background: var(--tg-link-soft);
  padding: 0 6px;
  font-size: 11px;
  color: var(--tg-link);
}

/* ---------- Settings ---------- */

.profile-card { margin-top: 12px; display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.pf-name { font-size: 16px; font-weight: 600; line-height: 22px; }
.pf-user { font-size: 14px; line-height: 18px; color: var(--tg-link); }
.pf-sub { margin-top: 2px; font-size: 13px; line-height: 17px; color: var(--tg-hint); }
.pf-photo { position: relative; display: block; width: 48px; height: 48px; flex-shrink: 0; border-radius: 999px; overflow: hidden; }
.pf-photo img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; border-radius: 999px; }
/* If Telegram's photo can't load, the letter avatar underneath shows instead. */
.pf-photo.failed img { display: none; }

/* ---------- Sheets ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  touch-action: none;
  overscroll-behavior: none;
  background: var(--tg-overlay);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  margin: 0 auto;
  display: flex;
  max-width: 480px;
  max-height: 88vh;
  flex-direction: column;
  border-radius: 14px 14px 0 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  overscroll-behavior: contain;
  will-change: transform;
}
.sheet.open { transform: translateY(0); }
.sheet.dragging { transition: none; }
/* Grab area at the top: drag it (or anywhere when the list is at the top) down to close. */
.sheet-grip {
  flex-shrink: 0;
  padding: 10px 0 4px;
  cursor: grab;
  touch-action: none;
}
.sheet-handle {
  margin: 0 auto;
  height: 5px;
  width: 40px;
  border-radius: 999px;
  background: var(--tg-chevron-60);
}
.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 6px var(--gutter) calc(18px + var(--safe-bottom));
}
.sheet-title { text-align: center; font-size: 16px; font-weight: 500; }
.sheet-desc { margin-top: 4px; text-align: center; font-size: 13px; color: var(--tg-hint); }
.sheet-list { margin-top: 14px; overflow: hidden; border-radius: var(--radius-card); background: var(--tg-section); }
.sheet-list.mt12 { margin-top: 12px; }
.sheet-empty { padding: 16px; text-align: center; font-size: 13px; color: var(--tg-hint); }

.pick-row {
  position: relative;
  display: flex;
  height: 44px;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  text-align: left;
  font-size: 15px;
  transition: background-color 0.15s;
}
.pick-row:active,
.sheet-row:active { background: var(--tg-section-pressed); }
.pick-row:not(.first)::before,
.folder-row:not(.first)::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 14px;
  height: 1px;
  background: var(--tg-divider);
}
.folder-pick { height: 44px; justify-content: flex-start; gap: 12px; }
.folder-pick.first::before { display: none; }
.folder-row { position: relative; display: flex; height: 44px; align-items: center; gap: 12px; padding: 0 6px 0 14px; font-size: 15px; }

.sheet-label {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tg-hint);
}
.sheet-label span { text-transform: none; letter-spacing: normal; }
.folder-form {
  margin-top: 6px;
  display: flex;
  height: 44px;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-card);
  background: var(--tg-section);
  padding: 0 6px 0 14px;
}
.folder-form input {
  height: 100%;
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 15px;
  outline: none;
}
.folder-form button {
  height: 34px;
  border-radius: 9px;
  background: var(--tg-link);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--on-accent);
}
.folder-form button:disabled { opacity: 0.4; }
.limit-note {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-card);
  background: var(--tg-section);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 18px;
  color: var(--tg-hint);
}
.limit-note svg { flex-shrink: 0; }

.note-box { border-radius: var(--radius-card); background: var(--tg-section); outline: 2px solid transparent; outline-offset: -2px; transition: outline-color 0.15s; }
.note-box:focus-within { outline-color: var(--tg-link-ring); }
.note-box textarea {
  display: block;
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 21px;
  outline: none;
}
.sheet-row {
  position: relative;
  display: flex;
  height: 46px;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 0 12px 0 14px;
  text-align: left;
  transition: background-color 0.15s;
}
.sheet-row:not(.first)::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 54px;
  height: 1px;
  background: var(--tg-divider);
}
.sr-detail { max-width: 40%; font-size: 14px; color: var(--tg-hint); }

/* ---------- Bottom tabs (compact Telegram-style floating pill) ---------- */

.tabbar {
  pointer-events: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 0 24px calc(var(--safe-bottom) + 10px);
}
.tabbar-box {
  pointer-events: auto;
  margin: 0 auto;
  max-width: 280px;
  border-radius: 999px;
  border: 1px solid var(--tg-hint-15);
  /* See-through, frosted glass: the page shows softly behind the bar. */
  background: var(--tg-tabbar);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  padding: 3px;
}
.tabbar-grid { position: relative; display: grid; height: 44px; grid-template-columns: repeat(3, 1fr); align-items: stretch; }
/* The highlight behind the active tab: a full pill around icon and label, like Telegram. */
.tab-ind {
  pointer-events: none;
  position: absolute;
  inset: 0 auto 0 0;
  width: 33.3333%;
  transition: transform 0.3s cubic-bezier(0.3, 1.3, 0.5, 1);
}
.tab-ind span { display: block; height: 100%; width: 100%; border-radius: 999px; background: var(--tg-tab-active); }
.tab {
  position: relative;
  z-index: 1;
  display: flex;
  min-width: 0;
  touch-action: manipulation;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 999px;
  color: var(--tg-tab-text);
  transition: color 0.2s;
}
.tab.active { color: var(--tg-link); }
.tab .ti { display: flex; height: 22px; align-items: center; justify-content: center; }
.tab svg { width: 20px; height: 20px; transition: transform 0.15s; }
.tab:active svg { transform: scale(0.86); }
.tab .tl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; font-weight: 600; line-height: 13px; letter-spacing: 0.01em; }

/* ---------- Toasts (stacked on top of each other) ---------- */

#toasts {
  pointer-events: none;
  position: fixed;
  left: 0;
  right: 0;
  top: calc(var(--safe-top) + 8px);
  z-index: 100;
  height: 0;
  transition: height 0.25s ease;
}
.toast {
  pointer-events: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  display: flex;
  width: calc(100% - 32px);
  max-width: 356px;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  border-radius: var(--radius-card);
  border: 1px solid var(--tg-hint-15);
  background: var(--tg-section);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 18px;
  color: var(--tg-text);
  transform-origin: bottom center;
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.25s ease, height 0.25s ease;
}
.toast.enter { opacity: 0; transform: translateY(-110%) !important; }
.toast.out { opacity: 0; pointer-events: none; }
/* Older toasts only peek out as cards; their text is hidden behind the front one. */
.toast.behind > * { opacity: 0; pointer-events: none; }
.toast > * { transition: opacity 0.2s ease; }
.toast-text { min-width: 0; flex: 1; }
.toast-title { font-weight: 500; }
.toast-desc { margin-top: 2px; font-size: 12.5px; color: var(--tg-hint); overflow-wrap: anywhere; }
.toast-action {
  flex-shrink: 0;
  height: 28px;
  border-radius: 8px;
  background: var(--tg-link);
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--on-accent);
}

/* ---------- 404 ---------- */

.nf-page {
  display: flex;
  min-height: 70vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  text-align: center;
}
.nf-page h1 { font-size: 72px; font-weight: 700; line-height: 1; }
.nf-page h2 { margin-top: 16px; font-size: 20px; font-weight: 600; }
.nf-page p { margin-top: 8px; font-size: 14px; color: var(--tg-hint); }
.big-link {
  margin-top: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  background: var(--tg-link);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--on-accent);
}

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

/* Tabs and in-app links are buttons (no web address on long press). */
button.tab { width: 100%; text-align: center; }
button.learn-more { display: inline-flex; font: inherit; color: var(--tg-link); }
button[data-link] { font: inherit; }
