/* Тема: светлая или тёмная по data-theme на <html>. Его ставит theme.js до отрисовки:
   выбор пользователя, а пока выбора нет — тёмная. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --surface-hover: #eceff3;
  --border: #e4e7ec;
  --border-strong: #d4d9e1;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #eef0fe;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --toast-bg: #111827;
  --toast-text: #f9fafb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-raised: 0 8px 28px rgba(16, 24, 40, 0.14);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d0f13;
  --surface: #15181e;
  --surface-muted: #1c2028;
  --surface-hover: #222731;
  --border: #262b35;
  --border-strong: #343a46;
  --text: #e8eaee;
  --muted: #8d95a3;
  --accent: #8b87ff;
  --accent-hover: #a29fff;
  --accent-text: #0d0f13;
  --accent-soft: #23234a;
  --danger: #f87171;
  --danger-soft: #3a1c1f;
  --toast-bg: #e8eaee;
  --toast-text: #0d0f13;
  --shadow: none;
  --shadow-raised: 0 8px 28px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

:root {
  --radius: 14px;
  --radius-small: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s, color 0.2s;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small-text {
  font-size: 13px;
}

.error {
  color: var(--danger);
  font-size: 14px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Иконки */

.icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-fill {
  fill: currentColor;
  stroke: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-mark.large {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.brand-mark.large svg {
  width: 26px;
  height: 26px;
}

/* Кнопки */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled) {
  transform: scale(0.97);
}

.button:disabled,
.icon-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.button.primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
}

.button.ghost:hover {
  background: var(--surface-hover);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.button.block {
  width: 100%;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.05s;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button.small {
  width: 32px;
  height: 32px;
}

/* В шапке кнопки одной высоты с обычными кнопками и с теми же 20px иконками, что у боковых. */
.topbar .icon-button {
  width: 38px;
  height: 38px;
  color: var(--text);
}

.topbar .button.small {
  min-height: 38px;
  font-size: 14px;
}

.topbar .icon {
  width: 20px;
  height: 20px;
}

.icon-button.spinning .icon {
  animation: spin 0.8s linear infinite;
}

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

.theme-button .icon {
  display: none;
}

.theme-button[data-choice="light"] .icon-light,
.theme-button[data-choice="dark"] .icon-dark {
  display: block;
}

button:focus-visible,
input:focus-visible,
.field-value:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Вход */

.login {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 16px;
}

.login-card {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-heading {
  display: grid;
  gap: 4px;
}

.input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--accent);
}

/* Каркас */

/* Три колонки: поле, контент шириной до 1240px с отступами, поле. В левом поле стоит кнопка индексов. */
.app {
  display: grid;
  grid-template-columns: minmax(16px, 1fr) minmax(0, 1208px) minmax(16px, 1fr);
  grid-template-rows: auto auto 1fr;
  row-gap: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px 0 16px;
}

.app > * {
  grid-column: 2;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
}

/* Вкладки Random и Gmail вместо названия: подложка плавно переезжает под выбранную. */
.mail-tabs {
  position: relative;
  display: inline-grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.mail-tabs-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 2);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 0 0 1px var(--border);
  transition: transform 0.24s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.mail-tabs[data-count="1"] .mail-tabs-indicator {
  width: calc(100% - 6px);
}

.mail-tabs[data-active="gmail"] .mail-tabs-indicator {
  transform: translateX(100%);
}

:root[data-theme="dark"] .mail-tabs-indicator {
  background: var(--surface-hover);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.mail-tab {
  position: relative;
  min-width: 78px;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.18s, transform 0.05s;
}

.mail-tab:hover {
  color: var(--text);
}

.mail-tab:active {
  transform: scale(0.97);
}

.mail-tab[aria-selected="true"] {
  color: var(--accent);
  cursor: default;
}

/* В полной версии вкладки чуть шире и отступают от значка почты. */
@media (min-width: 561px) {
  .mail-tabs {
    margin-left: 6px;
  }

  .mail-tab {
    min-width: 92px;
    padding: 0 18px;
  }
}

/* Содержимое вкладки при переключении проявляется с лёгким сдвигом снизу. */
.kind-enter {
  animation: kind-enter 0.22s ease-out;
}

@keyframes kind-enter {
  from {
    opacity: 0.35;
    transform: translateY(4px);
  }
}

/* Часы — кнопка копирования времени: без рамки и фона, подсветка при наведении как у кнопок шапки. */
.utc-clock {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--text);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.05s;
}

.utc-clock:hover {
  background: var(--surface-hover);
}

.utc-clock:active {
  transform: scale(0.97);
}

/* Цифры времени сидят в своей строке ниже середины, поэтому плашку опускаем на 1px вровень с ними. */
.utc-clock-zone {
  position: relative;
  top: 1px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
}

.utc-clock-time {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.user-name {
  min-width: 0;
  margin-right: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Ящик */

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 48px 20px;
  text-align: center;
}

.empty-state p {
  max-width: 420px;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

.mailbox {
  display: grid;
  gap: 14px;
  padding: 18px 20px;
}

/* Адрес, пароль и кнопки в одну строку; кнопки — справа, на уровне значений. */
.mailbox-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
}

.mailbox-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 24px;
  min-width: 0;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.label {
  /* Отступ равен внутреннему отступу значения: подпись начинается над первым символом. */
  padding-left: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.field-value {
  min-width: 0;
  overflow: hidden;
  padding: 7px 10px;
  /* Одна высота строки у адреса и пароля: поля и кнопки стоят на одной линии. */
  line-height: 24px;
  border-radius: var(--radius-small);
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-value.address {
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* Короткая подсветка после смены адреса: фон и рамка акцентного цвета плавно гаснут. */
.field-value.changed {
  animation: field-changed 1.4s ease-out;
}

@keyframes field-changed {
  from {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
    color: var(--accent);
  }
}

/* Пустая строка под разделителем: высота прежней строки с кнопками (14 + 1 + 38).
   Без неё карточка стала бы ниже и сдвинула кнопки в левом поле.
   Строка заходит на нижний отступ карточки (18px), чтобы срок стоял по центру
   между линией и краем карточки; общая высота карточки не меняется. */
.mailbox-footer {
  display: flex;
  align-items: center;
  height: 71px;
  margin-bottom: -18px;
  border-top: 1px solid var(--border);
}

.mailbox-expiry {
  /* Как у подписей полей: текст начинается над первым символом адреса. */
  padding-left: 10px;
  color: var(--muted);
  font-size: 15px;
}

/* Вровень с адресом: срок заметен, но не крупнее главного в карточке. */
.mailbox-expiry-time {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mailbox-expiry-time.ending {
  color: var(--danger);
}

.mailbox-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Выбор формата нового адреса: список выпадает с лёгким проявлением, стрелка переворачивается. */
.format-picker {
  position: relative;
}

.format-trigger {
  gap: 6px;
  padding: 0 10px 0 13px;
}

.format-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.format-picker.open .format-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.format-picker.open .format-chevron {
  color: var(--accent);
  transform: rotate(180deg);
}

.format-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 15;
  display: grid;
  gap: 2px;
  min-width: 300px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s 0.14s;
}

.format-picker.open .format-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

/* Справа в карточке список раскрывается влево, чтобы не уйти за край. */
.mailbox-actions .format-menu {
  right: 0;
  left: auto;
  transform-origin: top right;
}

.format-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s, transform 0.05s;
}

.format-option:hover {
  background: var(--surface-hover);
}

.format-option:active {
  transform: scale(0.99);
}

.format-option:focus-visible {
  outline-offset: -2px;
}

.format-option[aria-selected="true"] {
  background: var(--accent-soft);
}

.format-option-title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 600;
}

.format-check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--accent);
  opacity: 0;
}

.format-option[aria-selected="true"] .format-check {
  opacity: 1;
}

/* Письма */

.layout {
  display: grid;
  flex: 1;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.inbox {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.count {
  display: inline-block;
  min-width: 22px;
  margin-left: 4px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  vertical-align: 1px;
}

.count:empty {
  display: none;
}

.message-list {
  flex: 1;
  margin: 0;
  padding: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  list-style: none;
}

.message-list li + li {
  margin-top: 2px;
}

.message-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  width: 100%;
  padding: 10px 12px 10px 22px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}

.message-item:hover {
  background: var(--surface-hover);
}

.message-item.selected {
  background: var(--accent-soft);
}

/* Шеврон «открыть» нужен только на узком экране, где письмо открывается вместо списка. */
.message-chevron {
  display: none;
}

.message-item.unread::before {
  content: "";
  position: absolute;
  top: 18px;
  left: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.message-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.message-from {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-item.unread .message-from,
.message-item.unread .message-subject {
  font-weight: 650;
}

.message-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.message-subject {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-preview {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Плашка с кодом подтверждения: нажатие копирует код. */
.code-chip {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
  margin: 4px 0 2px;
  padding: 3px 8px 3px 10px;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  cursor: copy;
  transition: box-shadow 0.12s;
}

.code-chip:hover {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.code-chip-value {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.code-chip .icon {
  width: 15px;
  height: 15px;
}

.code-chip.large {
  align-self: flex-start;
  margin: 0;
  padding: 6px 12px 6px 14px;
}

.code-chip.large .code-chip-value {
  font-size: 20px;
}

.inbox-empty {
  display: grid;
  gap: 4px;
  padding: 32px 20px;
  text-align: center;
}

/* Просмотр */

.viewer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 70vh;
}

.viewer-placeholder {
  margin: auto;
  padding: 24px;
}

.viewer-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  min-height: 0;
}

.back {
  display: none;
  align-self: flex-start;
  margin-left: -6px;
}

.viewer-subject {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.viewer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  overflow-wrap: anywhere;
}

.viewer-from {
  font-size: 14px;
  font-weight: 550;
}

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

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-small);
  background: var(--surface-muted);
}

.tab {
  min-height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.tab:disabled {
  opacity: 0.4;
  cursor: default;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.attachments li {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

/* Письма рассчитаны на белый фон, поэтому HTML-версия остаётся светлой и в тёмной теме.
   Рамка занимает остаток окна письма, а не меньше 60vh: вместе с заголовком она выходила выше
   экрана, и с открытием письма у страницы появлялась прокрутка. Высоту и так держит .viewer. */
.viewer-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: #ffffff;
}

.viewer-text {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.viewer-text a {
  color: var(--accent);
}

/* Панель индексов: fixed и transform, поэтому страница под ней не сдвигается */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 12, 16, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0s 0.25s;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(440px, 100vw);
  border-right: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s 0.25s;
}

.drawer-open .drawer-backdrop {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s;
}

.drawer-open .drawer {
  transform: none;
  visibility: visible;
  transition: transform 0.25s ease;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-body {
  display: grid;
  align-content: start;
  gap: 20px;
  flex: 1;
  padding: 16px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tools-button-label {
  font-size: 14px;
}

/* Кнопки в левом поле отсчитываются от верха карточки ящика, а не от колонки «Входящие»,
   поэтому не прыгают, когда адрес создают или удаляют. Высота карточки ящика на широком
   экране постоянная — 165px, отступ между карточками 16px, ещё 4px ставят середину первой
   кнопки (50px) ровно напротив заголовка «Входящие». Ширина — по полю, с запасом по краям:
   на самом узком экране с этими кнопками (1560px) поле всего 176px. */
.app > .side-tools {
  display: none;
  grid-column: 1;
  grid-row: 2 / 4;
  align-self: start;
  justify-self: center;
  gap: 12px;
  width: min(196px, calc(100% - 24px));
  margin-top: 185px;
}

.side-tool-button {
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 0 10px 0 8px;
  border-radius: 12px;
  font-size: 15px;
  box-shadow: var(--shadow);
}

/* Значок в цветном квадрате, стрелка справа подсказывает, что откроется панель. */
.side-tool-icon {
  box-sizing: content-box;
  width: 18px;
  height: 18px;
  padding: 7px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.side-tool-chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.15s, color 0.15s;
}

.side-tool-button:hover .side-tool-chevron {
  color: var(--text);
  transform: translateX(2px);
}

/* Сбоку кнопкам хватает места только на широких экранах, на остальных они остаются в шапке. */
@media (min-width: 1560px) {
  .app > .side-tools {
    display: grid;
  }

  .tools-topbar-button {
    display: none;
  }
}

.country-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.country-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}

.country-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.country-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.country-code {
  flex-shrink: 0;
  min-width: 28px;
  padding: 1px 0;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.country-chip[aria-pressed="true"] .country-code {
  background: var(--accent);
  color: var(--accent-text);
}

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

.postcodes-result {
  display: grid;
  gap: 10px;
}

.postcodes-result-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.postcodes-result-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.postcode-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.postcode-item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
}

.postcode-fields {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 12px;
  margin: 0;
}

.postcode-fields dt {
  color: var(--muted);
  font-size: 12px;
}

.postcode-fields dd {
  min-width: 0;
  margin: 0;
}

.copy-value {
  max-width: 100%;
  padding: 1px 6px;
  overflow: hidden;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: copy;
  transition: background-color 0.12s, color 0.12s;
}

.copy-value:hover {
  background: var(--surface-hover);
}

.copy-value.postcode {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 650;
}

.postcodes-hint {
  text-align: center;
}

/* Вид с ISO кодами: поиск закреплён сверху, прокручивается только список. */
.drawer-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.iso-search {
  display: grid;
  gap: 6px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.iso-search .input {
  font-size: 15px;
}

.drawer-view .drawer-body {
  padding-top: 0;
}

.iso-list {
  margin: 0 -8px;
  padding: 0;
  list-style: none;
}

.iso-letter {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 8px 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.iso-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: copy;
  transition: background-color 0.12s;
}

.iso-item:hover {
  background: var(--surface-hover);
}

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

.iso-code {
  flex-shrink: 0;
  min-width: 34px;
  padding: 2px 0;
  border-radius: 6px;
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

/* AI чат: та же выдвижная панель, но шире — в узкой колонке переписку и код читать неудобно */

.drawer.drawer-wide {
  width: min(780px, 100vw);
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-cost {
  margin-right: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.ai-cost-value {
  color: var(--text);
  font-family: var(--mono);
  font-weight: 600;
}

.ai-fab {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  z-index: 15;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-raised);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.05s;
}

.ai-fab:hover {
  background: var(--accent-hover);
}

.ai-fab:active {
  transform: scale(0.97);
}

.ai-fab .icon {
  width: 20px;
  height: 20px;
}

/* Место под плавающей кнопкой, чтобы она не закрывала низ списка писем. */
@media (max-width: 1559px) {
  .app:has(> .ai-fab:not([hidden])) {
    padding-bottom: 76px;
  }
}

/* На широком экране чат открывает боковая кнопка, плавающая не нужна. */
@media (min-width: 1560px) {
  .ai-fab {
    display: none;
  }
}

.ai-view {
  position: relative;
}

.ai-messages {
  flex: 1;
  min-height: 0;
  padding: 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ai-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 420px;
  margin: 12vh auto 0;
  text-align: center;
}

.ai-empty h3 {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 650;
}

.ai-message-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-message.user {
  align-self: flex-end;
  max-width: 85%;
}

.ai-bubble {
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--accent-soft);
}

.ai-user-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-user-text a {
  color: var(--accent);
}

.ai-message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-message-files + .ai-user-text {
  margin-top: 8px;
}

.ai-message.assistant {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.ai-answer-badge {
  justify-self: start;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.ai-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.ai-dots {
  display: inline-flex;
  gap: 4px;
}

.ai-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: ai-dot 1.2s ease-in-out infinite;
}

.ai-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-dot {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }

  40% {
    opacity: 1;
  }
}

/* Ответ модели в Markdown */

.ai-markdown {
  min-width: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ai-markdown > :first-child {
  margin-top: 0;
}

.ai-markdown > :last-child {
  margin-bottom: 0;
}

.ai-markdown p,
.ai-markdown ul,
.ai-markdown ol,
.ai-markdown blockquote,
.ai-markdown .md-code,
.ai-markdown .md-table-wrap {
  margin: 0 0 12px;
}

.ai-markdown ul,
.ai-markdown ol {
  padding-left: 1.5em;
}

.ai-markdown li + li {
  margin-top: 4px;
}

.ai-markdown li > p,
.ai-markdown li > ul,
.ai-markdown li > ol {
  margin: 0;
}

.ai-markdown li > p + *,
.ai-markdown li > ul,
.ai-markdown li > ol {
  margin-top: 4px;
}

.ai-markdown .md-heading {
  margin: 18px 0 8px;
  font-weight: 650;
  line-height: 1.3;
}

.ai-markdown h3 {
  font-size: 18px;
}

.ai-markdown h4 {
  font-size: 16px;
}

.ai-markdown h5,
.ai-markdown h6 {
  font-size: 15px;
}

.ai-markdown a {
  color: var(--accent);
}

.ai-markdown hr {
  margin: 16px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.ai-markdown blockquote {
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.ai-markdown code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 0.88em;
}

.md-code {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-muted);
}

.md-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.md-code-copy {
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.md-code-copy:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.md-code pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
}

.ai-markdown .md-code code {
  padding: 0;
  background: none;
  font-size: 13px;
  white-space: pre;
  overflow-wrap: normal;
}

.md-table-wrap {
  overflow-x: auto;
}

.ai-markdown table {
  border-collapse: collapse;
  font-size: 14px;
}

.ai-markdown th,
.ai-markdown td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: normal;
}

.ai-markdown th {
  background: var(--surface-muted);
  font-weight: 600;
}

/* Мигающий курсор, пока ответ печатается. */
.ai-markdown.streaming::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.1em;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: ai-caret 1s steps(1) infinite;
}

@keyframes ai-caret {
  50% {
    opacity: 0;
  }
}

/* Ошибки: в ответе и над полем ввода — заметно, с причиной текстом */

.ai-error,
.ai-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-small);
  background: var(--danger-soft);
  color: var(--text);
  font-size: 14px;
}

.ai-error-text {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ai-error-text strong {
  color: var(--danger);
}

.ai-error .button {
  flex-shrink: 0;
}

.ai-alert {
  margin-bottom: 10px;
}

.ai-alert > .icon {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  color: var(--danger);
}

.ai-alert-text {
  flex: 1;
  min-width: 0;
  font-weight: 550;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.ai-alert .icon-button {
  width: 26px;
  height: 26px;
  margin: -3px -6px -3px 0;
}

.ai-alert.shake {
  animation: ai-shake 0.35s ease;
}

@keyframes ai-shake {
  25% {
    transform: translateX(-4px);
  }

  50% {
    transform: translateX(4px);
  }

  75% {
    transform: translateX(-2px);
  }
}

.ai-answer-note {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.ai-answer-note.warning {
  color: var(--danger);
  font-style: normal;
}

.ai-sources {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  font-size: 13px;
}

.ai-sources-title {
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 600;
}

.ai-sources-list {
  display: grid;
  gap: 3px;
  margin: 0;
  padding-left: 1.4em;
}

.ai-sources-list a {
  color: var(--accent);
}

.ai-source-host {
  margin-left: 6px;
  color: var(--muted);
}

.ai-answer-actions {
  display: flex;
  gap: 4px;
}

.ai-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ai-action:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.ai-action .icon {
  width: 15px;
  height: 15px;
}

.ai-memory-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.ai-memory-divider::before,
.ai-memory-divider::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--border-strong);
}

/* Поле ввода */

.ai-composer {
  padding: 12px 24px 14px;
  border-top: 1px solid var(--border);
}

.ai-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.ai-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.ai-attachment > .icon {
  width: 22px;
  height: 22px;
  margin: 0 2px 0 6px;
  color: var(--muted);
}

.ai-attachment.blocked {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.ai-attachment-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
}

.ai-attachment-label {
  display: grid;
  min-width: 0;
  line-height: 1.3;
}

.ai-attachment-name {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-attachment-size {
  color: var(--muted);
  font-size: 12px;
}

.ai-attachment-remove {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.ai-attachment-remove:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.ai-input-box {
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg);
  transition: border-color 0.15s;
}

.ai-input-box:focus-within {
  border-color: var(--accent);
}

.ai-input {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 12px 14px 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.ai-input-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 8px;
}

.ai-bar-spacer {
  flex: 1;
}

.ai-chip-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.ai-chip-button:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.ai-chip-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.ai-chip-button .icon {
  width: 16px;
  height: 16px;
}

.ai-chip-button .chevron {
  width: 14px;
  height: 14px;
}

.ai-model {
  position: relative;
  min-width: 0;
}

.ai-model-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-model-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 5;
  min-width: 260px;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
  list-style: none;
}

.ai-model-option {
  display: grid;
  gap: 1px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ai-model-option:hover {
  background: var(--surface-hover);
}

.ai-model-option[aria-selected="true"] {
  background: var(--accent-soft);
}

.ai-model-option-name {
  font-size: 14px;
  font-weight: 600;
}

.ai-model-option-note {
  color: var(--muted);
  font-size: 12px;
}

.ai-send {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

.ai-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.ai-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.ai-send.stop {
  background: var(--text);
  color: var(--surface);
}

.ai-chip-button:focus-visible,
.ai-send:focus-visible,
.ai-fab:focus-visible,
.ai-model-option:focus-visible,
.ai-action:focus-visible,
.md-code-copy:focus-visible,
.ai-attachment-remove:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ai-footnote {
  margin-top: 6px;
  font-size: 12px;
  text-align: center;
}

.ai-drop-overlay {
  position: absolute;
  inset: 10px;
  z-index: 6;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
}

.ai-view.dragging .ai-drop-overlay {
  display: grid;
}

/* На телефоне Enter переносит строку, подсказка про него лишняя. */
@media (max-width: 800px) {
  .ai-footnote {
    display: none;
  }
}

@media (max-width: 480px) {
  .ai-messages {
    padding: 16px;
  }

  .ai-composer {
    padding: 10px 12px 12px;
  }

  .ai-message.user {
    max-width: 92%;
  }

  .ai-web-label,
  .ai-cost-label {
    display: none;
  }

  .ai-model-name {
    max-width: 120px;
  }

  .ai-model-menu {
    min-width: min(260px, calc(100vw - 40px));
  }
}

/* Уведомления */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--radius-small);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 14px;
  box-shadow: var(--shadow-raised);
  transform: translateX(-50%);
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.copy-buffer {
  position: fixed;
  top: -1000px;
  left: -1000px;
  opacity: 0;
}

/* Кот в левом поле */

/* Спит, свернувшись клубком, в левом поле под боковыми кнопками, чуть выше надписи
   «Писем пока нет». Нарисован линиями цвета подписей и залит цветом карточек, глаза — акцентом,
   поэтому сам следует теме. Рамка рисунка начинается ровно с кота, а отступ слева — как у боковых
   кнопок (.side-tools), поэтому кот стоит вровень с их левым краем.
   Состояние задаёт data-phase, его меняет cat.js; мелкие движения во сне — data-action.
   Всё движение остаётся внутри рисунка (overflow: hidden), поэтому анимация не меняет размеров
   страницы и не вызывает прокрутку. */
.app > .mail-cat {
  display: none;
  grid-column: 1;
  grid-row: 3;
  align-self: end;
  justify-self: start;
  width: min(185px, calc(100% - 24px));
  height: auto;
  margin-left: calc((100% - min(196px, 100% - 24px)) / 2);
  margin-bottom: 104px;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

/* Только на больших экранах, как и боковые кнопки над котом. Виден и до создания адреса:
   третья строка сетки занимает остаток высоты страницы, поэтому кот стоит на том же месте. */
@media (min-width: 1600px) and (min-height: 760px) {
  .app > .mail-cat {
    display: block;
  }
}

.cat-part {
  fill: var(--surface);
  stroke: var(--muted);
  stroke-width: 3;
  stroke-linejoin: round;
}

/* Хвост — две линии: широкая цвета контура и поуже цвета заливки поверх неё. */
.cat-limb,
.cat-limb-fill {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cat-limb {
  stroke: var(--muted);
  stroke-width: 14;
}

.cat-limb-fill {
  stroke: var(--surface);
  stroke-width: 8;
}

.cat-stroke,
.cat-whisker,
.cat-z {
  fill: none;
  stroke: var(--muted);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cat-whisker {
  stroke-width: 2.4;
  opacity: 0.7;
}

.cat-shadow {
  fill: var(--muted);
  opacity: 0.14;
}

.cat-ear-inner {
  fill: var(--accent);
  opacity: 0.2;
}

.cat-eye,
.cat-nose {
  fill: var(--accent);
}

.cat-nose {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.cat-glint {
  fill: #fff;
}

.cat-alert-mark {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
}

/* Точки вращения — от рамки самой части рисунка. */
.cat-body,
.cat-head-motion,
.cat-tail-tip,
.cat-paw,
.cat-ear,
.cat-eyes-wide,
.cat-z,
.cat-alert-mark {
  transform-box: fill-box;
}

/* Глаза и рот по состояниям: во сне закрыты, разбуженный — круглые, засыпая — полуприкрыты. */
.cat-eyes-wide,
.cat-eyes-sleepy,
.cat-mouth-wide,
.cat-alert-mark,
.mail-cat:not([data-phase="sleep"]) .cat-eyes-closed,
.mail-cat:not([data-phase="sleep"]) .cat-zzz,
.mail-cat[data-phase="awake"] .cat-mouth-closed {
  display: none;
}

.mail-cat[data-phase="awake"] .cat-eyes-wide,
.mail-cat[data-phase="awake"] .cat-mouth-wide,
.mail-cat[data-phase="awake"] .cat-alert-mark,
.mail-cat[data-phase="settle"] .cat-eyes-sleepy {
  display: inline;
}

/* Сон: бока поднимаются от дыхания, голова покачивается вместе с ними, над головой плывут «z». */
.cat-body {
  transform-origin: 50% 100%;
  animation: cat-breathe 3.6s ease-in-out infinite;
}

@keyframes cat-breathe {
  50% {
    transform: scaleY(1.06);
  }
}

.cat-head-motion {
  transform-origin: 50% 100%;
  animation: cat-head-breathe 3.6s ease-in-out infinite;
}

@keyframes cat-head-breathe {
  50% {
    transform: translateY(-2.5px);
  }
}

.cat-z {
  stroke-width: 2.5;
  opacity: 0;
  animation: cat-z 3.6s ease-out infinite;
}

.cat-z:nth-child(2) {
  animation-delay: 1.2s;
}

.cat-z:nth-child(3) {
  animation-delay: 2.4s;
}

@keyframes cat-z {
  0% {
    transform: translate(-4px, 6px) scale(0.6);
    opacity: 0;
  }

  30%,
  60% {
    opacity: 0.8;
  }

  100% {
    transform: translate(4px, -6px) scale(1);
    opacity: 0;
  }
}

/* Голова: во сне лежит на лапах, разбуженный кот быстро поднимает её и смотрит на окно письма,
   засыпая — медленно опускает обратно. */
.cat-head {
  transform-origin: 136px 132px;
  transition: transform 0.9s ease-in-out;
}

.mail-cat[data-phase="awake"] .cat-head {
  transform: translate(2px, -30px) rotate(-12deg);
  transition-duration: 0.22s;
  transition-timing-function: cubic-bezier(0.2, 1.4, 0.4, 1);
}

/* Мелкие движения во сне, вразнобой: дёрнуть ухом, кончиком хвоста или лапой. */
.cat-ear {
  transform-origin: 100% 100%;
}

.mail-cat[data-action="ear"] .cat-ear {
  animation: cat-ear 0.45s ease-in-out 2;
}

@keyframes cat-ear {
  40% {
    transform: rotate(-22deg);
  }
}

/* Кончик хвоста поворачивается вокруг стыка с остальным хвостом — левого нижнего угла кончика.
   Во сне он медленно покачивается в такт дыханию, изредка — взмахивает. */
.cat-tail-tip {
  transform-origin: 0% 100%;
  animation: cat-tail-sway 3.6s ease-in-out infinite;
}

@keyframes cat-tail-sway {
  50% {
    transform: rotate(-7deg);
  }
}

.mail-cat[data-action="tail"] .cat-tail-tip {
  animation: cat-tail 1.4s ease-in-out;
}

@keyframes cat-tail {
  25% {
    transform: rotate(-20deg);
  }

  50% {
    transform: rotate(6deg);
  }

  75% {
    transform: rotate(-12deg);
  }
}

.cat-paw {
  transform-origin: 0% 50%;
}

.mail-cat[data-action="paw"] .cat-paw {
  animation: cat-paw 0.4s ease-in-out 2;
}

@keyframes cat-paw {
  50% {
    transform: translateX(6px) rotate(-14deg);
  }
}

/* Разбуженный кот не замирает: моргает, с любопытством наклоняет голову, поводит ухом и хвостом. */
.mail-cat[data-phase="awake"] .cat-alert-mark {
  transform-origin: 50% 100%;
  animation:
    cat-pop 0.3s cubic-bezier(0.3, 1.6, 0.5, 1),
    cat-alert-wobble 1.2s ease-in-out 0.3s infinite;
}

@keyframes cat-pop {
  from {
    transform: scale(0);
    opacity: 0;
  }
}

@keyframes cat-alert-wobble {
  25% {
    transform: rotate(8deg);
  }

  75% {
    transform: rotate(-6deg);
  }
}

.cat-eyes-wide {
  transform-origin: 50% 50%;
}

.mail-cat[data-phase="awake"] .cat-eyes-wide {
  animation: cat-blink 1.7s ease-in-out 0.6s infinite;
}

@keyframes cat-blink {
  0%,
  78%,
  96%,
  100% {
    transform: none;
  }

  85%,
  89% {
    transform: scaleY(0.1);
  }
}

.mail-cat[data-phase="awake"] .cat-head-motion {
  animation: cat-head-tilt 2.4s ease-in-out 0.25s infinite;
}

@keyframes cat-head-tilt {
  30% {
    transform: rotate(-6deg);
  }

  65% {
    transform: rotate(4deg);
  }
}

.mail-cat[data-phase="awake"] .cat-ear {
  animation: cat-ear 0.4s ease-in-out 1.1s 2;
}

.mail-cat[data-phase="awake"] .cat-tail-tip {
  animation: cat-tail 1.2s ease-in-out 0.2s infinite;
}

/* Не укорачиваем, а выключаем переходы: короткий переход у элементов без своего transition
   анимировал бы и унаследованную видимость содержимого панели. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Узкие экраны: список и письмо показываются по очереди */

@media (max-width: 900px) {
  .mailbox-fields {
    flex: 1 1 100%;
    flex-direction: column;
    align-items: stretch;
  }

  /* Здесь кнопки и так уходят под поля: строка нужна только под срок адреса, без запаса высоты. */
  /* Отступ над сроком равен нижнему отступу карточки: срок по центру строки. */
  .mailbox-footer {
    height: auto;
    margin-bottom: 0;
    padding-top: 18px;
  }

  .mailbox-footer:not(:has(.mailbox-expiry:not([hidden]))) {
    display: none;
  }
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout .viewer {
    display: none;
  }

  .layout.show-viewer .viewer {
    display: flex;
  }

  .layout.show-viewer .inbox {
    display: none;
  }

  .back {
    display: inline-flex;
  }

  .message-item {
    padding-right: 40px;
  }

  .message-chevron {
    position: absolute;
    top: 50%;
    right: 12px;
    display: block;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    color: var(--muted);
    transition: transform 0.15s, color 0.15s;
  }

  .message-item:hover .message-chevron,
  .message-item:active .message-chevron {
    color: var(--accent);
    transform: translateX(3px);
  }

  .viewer {
    min-height: 0;
  }

  .viewer-content {
    padding: 16px;
  }

  /* Окно письма почти во весь экран: прокрутка письма не теснится в маленькой рамке. */
  .viewer-frame {
    flex: none;
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    min-height: 0;
  }

  /* Текст растёт вместе со страницей, без своей прокрутки внутри. */
  .viewer-text {
    flex: none;
    min-height: 0;
    overflow: visible;
  }
}

/* Часы занимают середину шапки, поэтому подписи кнопок и название убираются заранее. */
@media (max-width: 800px) {
  .tools-button-label {
    display: none;
  }
}

/* На телефоне вкладки уходят во вторую строку шапки и занимают её целиком. */
@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  .brand {
    order: 3;
    flex-basis: 100%;
  }

  .brand .brand-mark {
    display: none;
  }

  .mail-tabs {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .app {
    grid-template-columns: minmax(12px, 1fr) minmax(0, 1208px) minmax(12px, 1fr);
    padding: 8px 0 12px;
  }

  .brand {
    font-size: 15px;
  }

  .utc-clock {
    gap: 6px;
  }

  .utc-clock-zone {
    padding: 2px 7px;
    font-size: 12px;
  }

  .utc-clock-time {
    font-size: 18px;
  }

  .topbar .icon-button {
    width: 34px;
  }

  .topbar .button.small {
    padding: 0 7px;
  }

  .user-name {
    display: none;
  }

  .drawer-header {
    padding-left: 16px;
  }

  .drawer-body {
    padding: 14px 16px 20px;
  }

  .iso-search {
    padding: 14px 16px 12px;
  }

  .mailbox {
    padding: 16px;
  }

  .mailbox-actions,
  .mailbox-actions .button {
    flex: 1;
  }

  /* Длинный Gmail-адрес переносится, а не обрезается многоточием: его видно целиком. */
  .field-value.address {
    white-space: normal;
    overflow-wrap: break-word;
  }

  /* В пустом состоянии выбор формата и кнопка — во всю ширину, одна под другой. */
  .empty-actions {
    flex-direction: column;
    justify-self: stretch;
  }

  .format-trigger {
    width: 100%;
    justify-content: space-between;
  }

  /* Выбор формата — отдельной строкой над кнопками, список во всю ширину карточки. */
  .mailbox-actions .format-picker {
    flex: 1 1 100%;
  }

  .format-menu,
  .mailbox-actions .format-menu {
    right: 0;
    left: 0;
    min-width: 0;
  }
}
