/* ---------- Токены ---------- */
:root {
  color-scheme: dark;
  --bg: #121318;
  --surface: #1b1d24;
  --surface-high: #242630;
  --surface-low: #17191f;
  --text: #f3f0f6;
  --muted: #b9b7c4;
  --muted2: #9998a7;
  --line: #393b48;
  --accent: #c9baff;
  --accent-text: #302454;
  --accent-soft: #3c3454;
  --accent-glow: rgba(201, 186, 255, .10);
  --danger: #ffb4ab;
  --success: #8bc9a7;
  --shadow: rgba(0, 0, 0, .14);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f9f8fd;
    --surface: #fff;
    --surface-high: #eeedf5;
    --surface-low: #f1f0f7;
    --text: #1c1b22;
    --muted: #5e5c6b;
    --muted2: #706e7c;
    --line: #dedce7;
    --accent: #6750a4;
    --accent-text: #fff;
    --accent-soft: #eaddff;
    --accent-glow: rgba(103, 80, 164, .07);
    --danger: #a12e28;
    --success: #2f8058;
    --shadow: rgba(36, 29, 49, .06);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f8fd;
  --surface: #fff;
  --surface-high: #eeedf5;
  --surface-low: #f1f0f7;
  --text: #1c1b22;
  --muted: #5e5c6b;
  --muted2: #706e7c;
  --line: #dedce7;
  --accent: #6750a4;
  --accent-text: #fff;
  --accent-soft: #eaddff;
  --accent-glow: rgba(103, 80, 164, .07);
  --danger: #a12e28;
  --success: #2f8058;
  --shadow: rgba(36, 29, 49, .06);
}

/* ---------- База ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; transition: transform .16s var(--ease-out), filter .16s, background-color .16s; }
button:active:not(:disabled) { transform: scale(.97); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: not-allowed; }
[hidden] { display: none !important; }
svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.shell { max-width: 560px; margin: auto; padding: 0 20px calc(36px + env(safe-area-inset-bottom)); }

/* ---------- Шапка ---------- */
.topbar { height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-icon { width: 42px; height: 42px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.brand-icon svg { width: 23px; height: 23px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.brand-caption { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.2; }
.top-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: pulse 2.4s ease-in-out infinite; }

/* ---------- Карточка адреса ---------- */
.hero {
  padding: 24px 22px 22px;
  background: radial-gradient(120% 90% at 100% 0, var(--accent-glow), transparent 60%), var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 4px 16px var(--shadow);
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; line-height: 1.3; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.pill { color: var(--accent); background: var(--accent-soft); border-radius: 100px; font-size: 12px; font-weight: 700; padding: 5px 10px; white-space: nowrap; }
.address-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.address { flex: 1; min-width: 0; font-size: clamp(19px, 5.2vw, 25px); line-height: 1.22; font-weight: 650; letter-spacing: -.035em; overflow-wrap: anywhere; user-select: all; }
.icon-btn { position: relative; width: 48px; height: 48px; display: grid; place-items: center; flex: none; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-high); color: var(--text); }
.icon-btn .icon-done { display: none; color: var(--success); }
.icon-btn.is-done .icon-copy { display: none; }
.icon-btn.is-done .icon-done { display: block; animation: pop .28s var(--ease-out); }
.icon-btn:hover:not(:disabled), .button.secondary:hover:not(:disabled), .refresh:hover { filter: brightness(1.1); }
.hero-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.hero-meta > span { display: flex; align-items: center; gap: 6px; }
.hero-meta svg { width: 15px; height: 15px; }
.hero-divider { height: 1px; background: var(--line); margin: 21px 0 18px; }
.actions { display: flex; gap: 10px; }
.button { min-height: 48px; border: 0; border-radius: 100px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; font-weight: 700; line-height: 1.2; }
.button svg { width: 18px; height: 18px; }
.button.primary { flex: 1; background: var(--accent); color: var(--accent-text); }
.button.secondary { background: var(--surface-high); color: var(--text); }
.button.delete { color: var(--danger); padding-inline: 17px; }
.quota { margin-top: 14px; min-height: 18px; color: var(--muted); font-size: 12px; }
.domain-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.domain-select { flex: 1; max-width: 260px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-low); color: var(--text); font: inherit; font-size: 14px; }
.domain-select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.label-input { width: 100%; min-height: 44px; margin-top: 14px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-low); color: var(--text); font: inherit; font-size: 14px; transition: border-color .16s; }
.label-input::placeholder { color: var(--muted2); }
.label-input:focus { outline: none; border-color: var(--accent); }
.label-input:disabled { opacity: .45; }
.text-action { display: block; min-height: 44px; margin-top: 8px; padding: 0 4px; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 700; }

/* ---------- Переключатель адресов ---------- */
.chips-wrap { margin-top: 20px; }
.chips-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 9px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 40px; padding: 0 14px; background: transparent; border: 1px solid var(--line); border-radius: 100px; color: var(--muted); font-size: 13px; font-weight: 600; }
.chip.active { color: var(--text); background: var(--accent-soft); border-color: transparent; }

/* ---------- Входящие ---------- */
.inbox-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 34px 0 14px; }
.inbox-heading h2 { font-size: 22px; line-height: 1.15; letter-spacing: -.035em; margin: 0; }
.inbox-heading p { font-size: 13px; color: var(--muted); margin: 5px 0 0; }
.refresh { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; border: 0; border-radius: 100px; background: transparent; color: var(--accent); font-size: 13px; font-weight: 700; padding: 0 4px 0 12px; }
.refresh svg { width: 18px; height: 18px; }
.mail-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.mail-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 76px; text-align: left; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
button.mail-item:hover { background: var(--surface-high); }
.mail-item.is-new { animation: slide-in .42s var(--ease-out); }
.mail-avatar { position: relative; width: 42px; height: 42px; flex: none; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 15px; font-size: 16px; font-weight: 700; text-transform: uppercase; }
.mail-avatar .dot { position: absolute; right: -2px; top: -2px; width: 10px; height: 10px; background: var(--accent); border: 2px solid var(--surface); border-radius: 50%; }
.mail-body { min-width: 0; flex: 1; }
.mail-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.mail-from { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mail-subject { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.skeleton .mail-avatar, .skeleton-lines { background: linear-gradient(100deg, var(--surface-high) 30%, var(--line) 50%, var(--surface-high) 70%) 0 0 / 220% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton-lines { display: block; flex: 1; height: 34px; border-radius: 10px; }

.empty { min-height: 218px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1px dashed var(--line); border-radius: 22px; padding: 26px 24px; background: var(--surface-low); }
.empty-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 19px; background: var(--accent-soft); color: var(--accent); margin-bottom: 15px; }
.empty-icon svg { width: 26px; height: 26px; }
.empty strong { font-size: 16px; letter-spacing: -.015em; }
.empty p { max-width: 250px; font-size: 13px; line-height: 1.5; color: var(--muted); margin: 6px 0 0; }
.referral { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 20px; padding: 18px; background: radial-gradient(120% 120% at 0 100%, var(--accent-glow), transparent 60%), var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.referral-copy { min-width: 0; }
.referral-copy strong { font-size: 15px; letter-spacing: -.015em; }
.referral-copy p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.referral .button { flex: none; }
.footnote { display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted2); font-size: 12px; margin: 22px 0 0; }
.footnote svg { width: 15px; height: 15px; }

/* ---------- Письмо ---------- */
.view { animation: view-in .32s var(--ease-out); }
.back-row { margin: 4px 0 24px; }
.back-button { background: transparent; border: 0; display: inline-flex; align-items: center; gap: 8px; color: var(--accent); min-height: 44px; padding: 0 12px 0 0; font-size: 14px; font-weight: 700; }
.msg-card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 22px; }
.msg-overline { color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.msg-subject { font-size: 24px; line-height: 1.2; letter-spacing: -.035em; overflow-wrap: anywhere; margin: 12px 0 18px; }
.sender-row { display: flex; gap: 12px; align-items: center; border-top: 1px solid var(--line); padding-top: 18px; }
.sender-icon { width: 40px; height: 40px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.sender-details { min-width: 0; }
.msg-from { font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.msg-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.message-content { margin-top: 12px; }
.images-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; padding: 10px 10px 10px 16px; background: var(--surface-low); border: 1px solid var(--line); border-radius: 16px; color: var(--muted); font-size: 13px; }
.images-notice button { flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 100px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; }
.msg-frame { width: 100%; min-height: 320px; border: 0; background: white; border-radius: 18px; display: block; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.6; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.toggle { color: var(--accent); font-size: 14px; font-weight: 700; background: none; border: 0; min-height: 48px; padding: 0 4px; display: block; }

/* ---------- Прочее ---------- */
.fatal { margin-top: 36px; }
.fatal .empty { min-height: 260px; }
.fatal .empty p { max-width: 300px; font-size: 14px; }
.fatal h2 { font-size: 20px; margin: 0; letter-spacing: -.03em; }
#toast { position: fixed; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 12px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s var(--ease-out); z-index: 50; max-width: calc(100vw - 32px); overflow-wrap: anywhere; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } }
@keyframes shimmer { to { background-position: -220% 0; } }
@keyframes pop { from { transform: scale(.5); } }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 360px) {
  .shell { padding-left: 16px; padding-right: 16px; }
  .hero { padding: 20px 18px; }
  .button { padding-inline: 13px; }
  .top-label { display: none; }
}

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