/* Sbox Mail, the Telegram Mini App. Colours are the Sbox tokens of the main app
   (rn-shared/src/theme/brand.ts): black surfaces and lime in the dark scheme, ink with lime
   content in the light one. Motion: ease-out for what enters, the drawer curve for what slides. */

:root {
  --canvas: #0E0E0E; --panel: #161616; --raised: #1D1D1D; --pressed: #2D2D2D; --tertiary: #292929;
  --accent: #E3FF73; --accent-soft: rgba(227, 255, 115, .14); --on-accent: #0E0E0E; --link: #E3FF73;
  --hairline: #2D2D2D; --text: #F0F0F0; --text-2: #A3A3A3; --text-3: #858585;
  --shadow: 0 10px 34px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
}
[data-scheme=light] {
  --canvas: #F5F5F5; --panel: #FFFFFF; --raised: #FFFFFF; --pressed: #E4E4E4; --tertiary: #E7E7E7;
  --accent: #161616; --accent-soft: #F1FFB9; --on-accent: #E3FF73; --link: #4D5E00;
  --hairline: #E6E6E6; --text: #161616; --text-2: #666666; --text-3: #858585;
  --shadow: 0 10px 34px rgba(15, 20, 30, .16), 0 2px 6px rgba(15, 20, 30, .08);
}

* { box-sizing: border-box; margin: 0; scrollbar-width: thin; scrollbar-color: var(--pressed) transparent; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
html, body { height: 100%; background: var(--canvas); color: var(--text); }
body { font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: inherit; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
input, textarea { font: inherit; font-size: 16px; color: inherit; background: none; border: 0; outline: 0; min-width: 0; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
svg { display: block; }
button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

#app {
  position: fixed; inset: 0; overflow: hidden; background: var(--canvas);
  --top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

/* ---- views: a new one slides in from the right and the one under it steps back */
.view {
  position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--canvas);
  transition: transform .42s var(--ease-drawer), opacity .42s var(--ease-drawer);
}
.view[data-pos=right] { transform: translateX(100%); }
.view[data-pos=left] { transform: translateX(-26%); opacity: .5; }
.view.reader { box-shadow: -14px 0 40px rgba(0, 0, 0, .35); }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
/* What scrolls passes under the fixed header, and the header says so with a hairline once it has moved. */
.top, .nav { position: relative; z-index: 1; box-shadow: 0 1px 0 transparent; transition: box-shadow .2s ease; }
[data-scrolled] > .top, [data-scrolled] > .nav { box-shadow: 0 1px 0 var(--hairline); }

/* ---- inbox */
.top { flex: none; padding: calc(var(--top) + 8px) 16px 0; }
.bar { display: flex; align-items: center; gap: 10px; height: 44px; }
.mark { width: 22px; height: 22px; flex: none; color: var(--accent); }
h1 { flex: 1; font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -.02em; }
.me { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex: none; transition: transform .16s var(--ease-out); }
.me:active { transform: scale(.94); }
.me img, .me svg { width: 100%; height: 100%; object-fit: cover; }
.search { display: flex; align-items: center; height: 38px; margin-top: 8px; padding: 0 9px 0 12px; border-radius: 12px;
  background: var(--panel); color: var(--text-3); box-shadow: 0 0 0 1.5px transparent; transition: box-shadow .2s ease; }
.search:focus-within { box-shadow: 0 0 0 1.5px var(--link); }
.search label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 100%; }
.search input { flex: 1; color: var(--text); }
.clear { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--text-3); color: var(--panel); }
.clear[hidden] { display: none; }
/* While a search runs it covers both kinds of mail, so the two tabs step out of the way. */
.tabs { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s var(--ease-drawer), opacity .2s ease; }
.tabs > div { min-height: 0; overflow: hidden; }
.searching .tabs { grid-template-rows: 0fr; opacity: 0; }
.seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; margin: 10px 0 4px; padding: 3px; border-radius: 12px; background: var(--panel); }
.seg button { position: relative; z-index: 1; height: 32px; border-radius: 9px; text-align: center; font-size: 14px; font-weight: 600;
  color: var(--text-2); transition: color .2s ease; }
.seg button[aria-selected=true] { color: var(--text); }
.seg .n { margin-left: 6px; color: var(--link); font-variant-numeric: tabular-nums; }
.seg i { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 9px; background: var(--raised);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .28); transition: transform .3s var(--ease-drawer); }
[data-scheme=light] .seg { background: var(--tertiary); }
.seg[data-tab=updates] i { transform: translateX(100%); }

.list { padding: 4px 0 calc(var(--bottom) + 96px); }
.rw { position: relative; overflow: hidden; }
.act { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding-right: 26px; background: var(--tertiary);
  color: var(--text-2); transition: background-color .18s ease, color .18s ease; }
.act svg { transition: transform .22s var(--ease-out); }
.armed .act { background: var(--accent); color: var(--on-accent); }
.armed .act svg { transform: scale(1.15); }
.row { position: relative; display: flex; gap: 12px; width: 100%; padding: 10px 16px 0 24px; background: var(--canvas); touch-action: pan-y;
  transition: background-color .12s ease, transform .34s var(--ease-drawer); }
.row:active { background: var(--panel); }
.row:focus-visible { outline-offset: -2px; }
.row[data-opening] { background: var(--panel); }
.row .dot { position: absolute; left: 8px; top: 29px; width: 8px; height: 8px; border-radius: 50%; background: var(--link);
  opacity: 0; transform: scale(.5); transition: transform .25s var(--ease-out), opacity .25s ease; }
.row.unread .dot { opacity: 1; transform: none; }
.av { width: 46px; height: 46px; border-radius: 50%; flex: none; object-fit: cover; background: var(--raised); overflow: hidden; }
.av.logo { border-radius: 13px; }
.av.mono { display: grid; place-items: center; background: var(--tertiary); color: var(--text-2); font-size: 15px; font-weight: 600; letter-spacing: .02em; }
.av svg, .av img { display: block; width: 100%; height: 100%; object-fit: cover; }
.row .body { flex: 1; min-width: 0; padding-bottom: 11px; border-bottom: 1px solid var(--hairline); }
.rw:last-of-type .body { border-bottom-color: transparent; }
.l1 { display: flex; align-items: baseline; gap: 8px; }
.name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread .name { font-weight: 700; }
.time { flex: none; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.unread .time { color: var(--link); }
.subj { display: flex; align-items: center; gap: 6px; font-size: 15px; line-height: 20px; }
.subj .st { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { flex: none; padding: 0 6px; border-radius: 8px; background: var(--tertiary); color: var(--text-2); font-size: 12px; font-weight: 600; line-height: 18px; }
.subj svg { flex: none; width: 14px; height: 14px; color: var(--text-3); }
.prev i { font-style: normal; color: var(--link); }
.prev { display: block; font-size: 15px; line-height: 20px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note { display: block; padding: 18px 16px 0; text-align: center; font-size: 13px; color: var(--text-3); }
.list.first .rw { animation: rise .45s var(--ease-out) both; animation-delay: calc(var(--i) * 34ms); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.fab { position: absolute; right: 16px; bottom: calc(var(--bottom) + 18px); width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow);
  transition: transform .16s var(--ease-out); }
.fab:active { transform: scale(.93); }

/* ---- while the person's mail is on its way the mark beats where the list will be; and what is shown when there is no mail to show */
.wait { display: none; }
.waiting .wait { display: grid; place-items: center; height: 56%; color: var(--text-3); }
.wait .mark { width: 40px; height: 40px; color: inherit; }
.wait .mark rect { animation: beat 1.3s ease-in-out infinite; }
.wait .mark rect:nth-child(2) { animation-delay: .14s; }
.wait .mark rect:nth-child(1) { animation-delay: .28s; }
@keyframes beat { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }
.stop { display: grid; justify-items: center; gap: 16px; padding: 22% 32px 0; text-align: center; color: var(--text-2); }
.stop .mark { width: 40px; height: 40px; color: var(--text-3); }
.stopped .search, .stopped .tabs, .stopped .fab, .stopped .me { display: none; }

/* ---- reader: the subject and the mail's two actions share the first row, which stays while the mail scrolls */
.nav { flex: none; display: flex; align-items: flex-start; min-height: 44px; margin-top: var(--top); padding: 0 6px; }
.icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  transition: background-color .12s ease, transform .16s var(--ease-out); }
.icon:active { background: var(--panel); transform: scale(.93); }
.thread { padding: 0 16px 20px; }
h2 { flex: 1; min-width: 0; margin: 8px 6px 8px 2px; font-size: 22px; line-height: 28px; font-weight: 700; letter-spacing: -.01em;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; user-select: text; -webkit-user-select: text; }
h2:first-child { margin-left: 10px; }
.msg { border-top: 1px solid var(--hairline); }
.msg:first-of-type { border-top: 0; }
.msg.new { animation: rise .4s var(--ease-out) both; }
.who { display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 0; }
.who .av { width: 38px; height: 38px; }
.who .av.logo { border-radius: 11px; }
.who .av.mono { font-size: 13px; }
.who .id { flex: 1; min-width: 0; }
.who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: block; font-size: 13px; line-height: 18px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who time { flex: none; align-self: flex-start; padding-top: 2px; font-size: 13px; color: var(--text-3); }
.more { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .34s var(--ease-drawer), opacity .25s ease; }
.more > div { min-height: 0; overflow: hidden; }
.folded .more { grid-template-rows: 0fr; opacity: 0; }
.text { padding-bottom: 16px; font-size: 16px; line-height: 24px; white-space: pre-line; user-select: text; -webkit-user-select: text; }
.files { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 16px; }
.file { display: flex; align-items: center; gap: 10px; max-width: 100%; padding: 8px 14px 8px 8px; border-radius: 12px; background: var(--panel);
  transition: transform .16s var(--ease-out); }
.file:active { transform: scale(.97); }
.file i { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--accent-soft);
  color: var(--link); font-style: normal; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.file b { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file small { display: block; font-size: 12px; color: var(--text-2); }
.code { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding: 12px 12px 12px 16px; border-radius: 14px; background: var(--panel); }
.code b { flex: 1; font: 700 24px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; font-variant-numeric: tabular-nums;
  user-select: text; -webkit-user-select: text; }
.pill { height: 34px; padding: 0 16px; border-radius: 17px; background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 600;
  transition: transform .16s var(--ease-out); }
.pill:active { transform: scale(.95); }
.html { margin-bottom: 16px; border-radius: 14px; overflow: hidden; background: #fff; }
.html iframe { display: block; width: 100%; height: 320px; border: 0; }
.sent { display: block; padding-bottom: 14px; font-size: 13px; color: var(--text-3); }

/* The field runs from gutter to gutter. Its one button sits inside it and changes in place:
   draft a reply when the field is empty, stop while the draft is being written, send when there is text. */
.reply { flex: none; padding: 6px 12px calc(var(--bottom) + 10px); }
.field { display: flex; align-items: flex-end; min-height: 44px; padding: 0 4px 0 16px; border-radius: 22px; background: var(--panel);
  box-shadow: 0 0 0 1.5px transparent; transition: box-shadow .3s ease; }
.drafting .field { box-shadow: 0 0 0 1.5px var(--accent-soft); }
.field textarea { flex: 1; height: 44px; max-height: 132px; padding: 11px 0; line-height: 22px; resize: none; }
.slot { position: relative; width: 36px; height: 36px; margin: 4px 0; border-radius: 50%; flex: none; color: var(--text-2);
  transition: background-color .2s ease, color .2s ease, transform .16s var(--ease-out); }
.slot:active { transform: scale(.92); }
.slot span { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity .18s ease, transform .2s var(--ease-out), filter .18s ease; }
.slot .go, .slot .halt, .has .slot .ai, .drafting .slot .ai, .drafting .slot .go { opacity: 0; transform: scale(.7); filter: blur(2px); }
.has .slot { background: var(--accent); color: var(--on-accent); }
.has .slot .go, .drafting .slot .halt { opacity: 1; transform: none; filter: none; }
.drafting .slot { background: var(--tertiary); color: var(--text); }

/* ---- new mail: rises over the inbox and takes the whole view */
.scrim { position: absolute; inset: 0; z-index: 4; background: rgba(0, 0, 0, .42); opacity: 0; pointer-events: none; transition: opacity .35s ease; }
.scrim[data-open] { opacity: 1; pointer-events: auto; }
.sheet { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; padding-top: var(--top); background: var(--panel);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .4); transform: translateY(105%); transition: transform .46s var(--ease-drawer); }
.sheet[data-open] { transform: none; }
.sheet header { flex: none; display: flex; align-items: center; height: 54px; padding: 0 8px 0 4px; }
.sheet header b { flex: 1; padding-left: 4px; font-size: 17px; font-weight: 600; }
.go-disc { width: 36px; height: 36px; margin: 0 6px 0 2px; border-radius: 50%; display: grid; place-items: center; background: var(--accent);
  color: var(--on-accent); transition: transform .16s var(--ease-out), background-color .2s ease, color .2s ease; }
.go-disc:active { transform: scale(.93); }
.go-disc:disabled { background: var(--tertiary); color: var(--text-3); }
.line { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 48px; padding: 8px 16px; border-bottom: 1px solid var(--hairline); }
.line label { color: var(--text-3); font-size: 15px; }
.line input { flex: 1; min-width: 80px; height: 30px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 3px; border-radius: 15px; background: var(--tertiary);
  font-size: 14px; animation: pop .22s var(--ease-out); }
.chip.plain { padding-left: 12px; }
.chip img, .chip .av { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; font-size: 10px; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
/* People to write to appear over the fields below, so nothing under the finger moves. */
.towrap { position: relative; flex: none; z-index: 2; }
.sug { position: absolute; top: 100%; left: 0; right: 0; padding: 4px 0 6px; border-radius: 0 0 16px 16px; background: var(--panel);
  box-shadow: 0 18px 30px rgba(0, 0, 0, .3); opacity: 0; transform: translateY(-6px); pointer-events: none;
  transition: transform .22s var(--ease-out), opacity .16s ease; }
.sug[data-open] { opacity: 1; transform: none; pointer-events: auto; }
.sug button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 16px; transition: background-color .12s ease; }
.sug button:active { background: var(--raised); }
.sug .av { width: 36px; height: 36px; font-size: 13px; }
.sug b { display: block; font-size: 15px; font-weight: 500; }
.sug small { display: block; font-size: 13px; color: var(--text-2); }
.sheet textarea { flex: 1; min-height: 0; padding: 14px 16px calc(var(--bottom) + 16px); line-height: 24px; resize: none; }

/* ---- the account card under the picture */
.pop { position: absolute; z-index: 6; top: calc(var(--top) + 54px); right: 12px; width: min(300px, calc(100% - 24px)); padding: 6px; border-radius: 18px;
  background: var(--raised); box-shadow: var(--shadow); transform-origin: calc(100% - 20px) 0; opacity: 0; transform: scale(.94); pointer-events: none;
  transition: transform .2s var(--ease-out), opacity .16s ease; }
.pop[data-open] { opacity: 1; transform: none; pointer-events: auto; }
[data-scheme=light] .pop { border: 1px solid var(--hairline); }
.addr { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; border-radius: 13px; transition: background-color .12s ease; }
.addr:active { background: var(--pressed); }
.addr b { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.addr svg { flex: none; color: var(--text-2); }
.mine { padding: 12px; }
.mine b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mine small { display: block; margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--text-2); }
.space { padding: 4px 12px 12px; }
.space .track { height: 4px; border-radius: 2px; background: var(--tertiary); overflow: hidden; }
.space .track i { display: block; height: 100%; border-radius: 2px; background: var(--link); }
.space small { display: block; margin-top: 8px; font-size: 13px; color: var(--text-2); }
.catch { position: absolute; inset: 0; z-index: 5; display: none; }
.catch[data-open] { display: block; }

/* ---- a short notice at the bottom, with at most one action */
.toast { position: absolute; z-index: 9; left: 50%; bottom: calc(var(--bottom) + 22px); display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 104px); height: 44px; padding: 0 18px; border-radius: 22px; background: var(--raised); box-shadow: var(--shadow);
  font-size: 15px; white-space: nowrap; opacity: 0; transform: translate(-50%, 16px); pointer-events: none;
  transition: transform .3s var(--ease-out), opacity .2s ease; }
.toast[data-open] { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
[data-scheme=light] .toast { border: 1px solid var(--hairline); }
.toast button { color: var(--link); font-weight: 600; }

@media (hover: hover) and (pointer: fine) {
  .row:hover { background: var(--panel); }
  .sug button:hover { background: var(--raised); }
  .icon:hover, .addr:hover { background: var(--panel); }
}
.blank { display: none; }
@media (min-width: 760px) {
  /* A wide window: the inbox stays at the left and the mail opens beside it. */
  #app { --side: 384px; }
  .view:not(.reader) { right: auto; width: var(--side); border-right: 1px solid var(--hairline); }
  .view[data-pos=left] { transform: none; opacity: 1; }
  .view.reader { left: var(--side); box-shadow: none; transition: opacity .22s ease, transform .3s var(--ease-out); }
  .view.reader[data-pos=right] { transform: translateX(12px); opacity: 0; }
  /* The mail keeps a reading width and stands in the middle of its pane. Its subject is on the line of "Inbox" beside it. */
  .reader .nav, .reader .thread, .reader .reply { width: 100%; max-width: 720px; margin-inline: auto; }
  .reader .nav { margin-top: calc(var(--top) + 8px); }
  .reader .nav [data-act=back] { display: none; }
  .reader .nav h2 { margin-left: 10px; }
  .row[aria-current] { background: var(--panel); }
  .blank { position: absolute; inset: 0 0 0 var(--side); display: grid; place-items: center; color: var(--text); opacity: .05; }
  .blank .mark { width: 96px; height: 96px; color: inherit; }
  .pop { right: auto; left: calc(var(--side) - 312px); }
  /* A new mail is written in the pane where mail is read: the whole pane, nothing peeking round it. */
  .scrim { display: none; }
  .sheet { inset: 0 0 0 var(--side); padding-top: calc(var(--top) + 8px); box-shadow: none; background: var(--canvas);
    transform: translateX(12px); opacity: 0; transition: transform .3s var(--ease-out), opacity .22s ease; }
  .sheet[data-open] { transform: none; opacity: 1; }
  .sheet > * { width: 100%; max-width: 720px; align-self: center; }
  .sheet header { height: 44px; }
  .toast { left: calc(var(--side) / 2); max-width: calc(var(--side) - 104px); }
}
@media (prefers-reduced-motion: reduce) {
  .view, .sheet, .seg i, .more, .sug, .tabs, .row { transition-duration: .01s; }
  .list.first .rw, .msg.new, .chip, .wait .mark rect { animation: none; }
}
