:root {
  color-scheme: dark;
  --bg: #0f1012;
  --surface: #17181b;
  --surface-2: #202126;
  --surface-3: #292b31;
  --line: #34363d;
  --line-soft: #27292e;
  --text: #f3f3f5;
  --muted: #9a9da6;
  --accent: #d9293b;
  --accent-hover: #ed3b4d;
  --accent-soft: rgba(217, 41, 59, 0.14);
  --success: #45c878;
  --warning: #f2b84b;
  --radius: 7px;
  --header-height: 68px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

input,
textarea,
select {
  outline: 0;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--surface);
}

::-webkit-scrollbar-thumb {
  border: 2px solid var(--surface);
  border-radius: 6px;
  background: var(--accent);
}

.auth-view {
  display: grid;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-rows: 1fr auto;
  overflow-y: auto;
  background: var(--bg);
}

.auth-shell {
  width: min(440px, calc(100% - 36px));
  margin: auto;
  padding: 54px 0 36px;
}

.auth-brand,
.mail-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
}

.auth-brand img,
.mail-brand img {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
}

.auth-brand strong,
.mail-brand strong {
  color: var(--accent);
}

.auth-heading {
  margin: 54px 0 26px;
}

.auth-heading p,
.modal-header p {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

.auth-heading h1 {
  margin: 0;
  font-size: 31px;
  line-height: 1.15;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.auth-tab {
  height: 44px;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

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

.auth-tab.active {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.auth-form,
.settings-form {
  display: grid;
  gap: 17px;
}

.auth-form label,
.settings-form label {
  display: grid;
  gap: 7px;
}

.auth-form label > span:first-child,
.settings-form label > span:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-form input,
.settings-form input,
.logout-options select {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition:
    border-color 140ms ease,
    background-color 140ms ease;
}

.auth-form input:focus,
.settings-form input:focus,
.logout-options select:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}

.address-input {
  display: grid !important;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

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

.address-input input {
  border: 0;
  background: transparent;
}

.address-input b {
  min-width: 0;
  padding-right: 12px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.primary-button,
.outline-button,
.danger-button {
  min-height: 42px;
  padding: 9px 17px;
  border-radius: var(--radius);
  font-weight: 800;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

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

.outline-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

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

.danger-button {
  background: var(--accent);
  color: #fff;
}

.auth-form .primary-button {
  width: 100%;
  margin-top: 5px;
}

.auth-footer {
  padding: 20px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.mail-app {
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: 244px minmax(0, 1fr);
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  background: var(--bg);
  overflow: hidden;
}

.mail-header {
  position: relative;
  z-index: 40;
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 244px minmax(260px, 720px) 1fr auto;
  align-items: center;
  gap: 18px;
  height: var(--header-height);
  padding: 0 22px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.header-brand-block {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.mobile-menu {
  display: none !important;
}

.mail-search {
  display: grid;
  width: 100%;
  height: 44px;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition:
    border-color 140ms ease,
    background-color 140ms ease;
}

.mail-search:focus-within {
  border-color: var(--accent);
  background: var(--surface-3);
}

.mail-search > span {
  color: var(--muted);
  font-size: 23px;
  text-align: center;
}

.mail-search input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
}

.mail-search input::placeholder {
  color: var(--muted);
}

.mail-search button {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 21px;
}

.mail-search button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.avatar-button,
.large-avatar,
.small-avatar,
.sender-avatar {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.avatar-button {
  width: 40px;
  height: 40px;
  border: 2px solid transparent;
}

.avatar-button:hover,
.avatar-button[aria-expanded="true"] {
  border-color: #fff;
}

.account-popover {
  position: absolute;
  top: 58px;
  right: 18px;
  width: min(380px, calc(100vw - 28px));
  max-height: calc(100vh - 76px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
  overflow-y: auto;
}

.current-account {
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 22px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.large-avatar {
  width: 58px;
  height: 58px;
  margin-bottom: 11px;
  font-size: 23px;
}

.current-account strong {
  font-size: 17px;
}

.current-account > span:not(.large-avatar) {
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.account-list {
  max-height: 190px;
  overflow-y: auto;
}

.account-switch,
.popover-action {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.account-switch:hover,
.popover-action:hover {
  background: var(--surface-3);
}

.small-avatar {
  width: 36px;
  height: 36px;
}

.account-switch > span:last-child {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.account-switch strong,
.account-switch small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-switch small {
  color: var(--muted);
}

.popover-action > span {
  width: 36px;
  color: var(--muted);
  font-size: 22px;
  text-align: center;
}

.danger-action {
  color: #ff8791;
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 18px 12px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.compose-button {
  display: inline-flex;
  width: 164px;
  height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 0 6px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.compose-button:hover {
  background: var(--accent-hover);
}

.compose-button span {
  font-size: 22px;
}

.folder-nav {
  display: grid;
  gap: 3px;
}

.folder-button {
  display: grid;
  width: 100%;
  height: 42px;
  grid-template-columns: 35px minmax(0, 1fr) auto;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
}

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

.folder-button.active {
  background: var(--accent-soft);
  color: #fff;
}

.folder-button.active span {
  color: var(--accent-hover);
}

.folder-button span {
  font-size: 18px;
}

.folder-button b {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-button em {
  color: inherit;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.sidebar-account {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 14px 10px 2px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
}

.sidebar-account span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
}

.mail-content {
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

.message-panel,
.reader {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.list-toolbar,
.reader-toolbar {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.list-toolbar h1 {
  margin: 0 0 3px;
  font-size: 20px;
}

.list-toolbar > div > span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

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

.icon-button.active {
  color: var(--warning);
}

.message-list {
  min-height: 0;
  overflow-y: auto;
}

.message-row {
  display: grid;
  min-height: 54px;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(32, 33, 38, 0.52);
}

.message-row.unread {
  background: var(--surface-2);
}

.message-row:hover {
  position: relative;
  z-index: 1;
  background: var(--surface-3);
  box-shadow: inset 3px 0 0 var(--accent);
}

.star-button {
  width: 42px;
  background: transparent;
  color: #6e717a;
  font-size: 20px;
}

.star-button:hover,
.star-button.active {
  color: var(--warning);
}

.message-open {
  display: grid;
  min-width: 0;
  grid-template-columns:
    minmax(150px, 0.34fr) minmax(150px, 0.42fr) minmax(120px, 1fr)
    62px;
  align-items: center;
  gap: 13px;
  padding: 0 19px 0 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.message-open strong,
.message-open span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-open strong,
.row-subject {
  font-size: 13px;
}

.message-row:not(.unread) .message-open strong,
.message-row:not(.unread) .row-subject {
  font-weight: 500;
}

.row-snippet {
  color: var(--muted);
  font-size: 12px;
}

.message-open time {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.empty-state {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-state > span {
  display: inline-flex;
  width: 54px;
  height: 54px;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
  font-size: 23px;
  font-weight: 900;
}

.empty-state strong {
  color: var(--text);
  font-size: 17px;
}

.empty-state p {
  margin: 7px 0 0;
  font-size: 13px;
}

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

.reader-content {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 35px 38px 60px;
  overflow-y: auto;
}

.reader-content h1 {
  margin: 0 0 28px;
  font-size: 25px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.reader-sender-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
}

.sender-avatar {
  width: 42px;
  height: 42px;
  background: var(--surface-3);
  color: var(--accent-hover);
}

.reader-sender-row > div {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.reader-sender-row strong,
.reader-sender-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-sender-row span,
.reader-sender-row time {
  color: var(--muted);
  font-size: 12px;
}

.reader-content pre {
  min-height: 200px;
  margin: 28px 0 0;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.compose-window {
  position: fixed;
  z-index: 60;
  right: 24px;
  bottom: 0;
  display: grid;
  width: min(560px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 95px));
  grid-template-rows: 44px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
}

.compose-window.collapsed {
  height: 44px;
}

.compose-window.collapsed form {
  display: none;
}

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface-3);
  color: var(--text);
  font-size: 13px;
}

.compose-header button {
  width: 30px;
  height: 30px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.compose-header button:hover {
  color: var(--text);
}

.compose-window form {
  display: grid;
  min-height: 0;
  grid-template-rows: 43px 43px minmax(120px, 1fr) 58px;
}

.compose-window input,
.compose-window textarea {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
}

.compose-window input {
  padding: 0 15px;
}

.compose-window textarea {
  padding: 16px;
  line-height: 1.5;
  resize: none;
}

.compose-window input:focus,
.compose-window textarea:focus {
  border-bottom-color: var(--accent);
}

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 8px 14px;
}

.compose-footer .primary-button {
  min-width: 112px;
}

.modal {
  width: min(500px, calc(100% - 30px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  overflow-y: auto;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-header p {
  margin-bottom: 5px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 23px;
}

.dialog-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.compact-tabs {
  margin: 10px 22px 20px;
}

.modal > .auth-form {
  padding: 0 22px 24px;
}

.profile-summary {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.profile-summary .large-avatar {
  width: 48px;
  height: 48px;
  margin: 0;
  font-size: 19px;
}

.profile-summary > div {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.profile-summary strong,
.profile-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-summary span {
  color: var(--muted);
  font-size: 12px;
}

.settings-form {
  padding: 20px 22px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.settings-form:last-child {
  border-bottom: 0;
}

.settings-form h3 {
  margin: 0 0 2px;
  font-size: 14px;
}

.settings-form .outline-button {
  justify-self: start;
}

.small-modal {
  width: min(460px, calc(100% - 30px));
}

.logout-options {
  display: grid;
  gap: 7px;
  padding: 18px 22px 22px;
}

.logout-options > label {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  cursor: pointer;
}

.logout-options > label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.logout-options input[type="radio"] {
  margin: 4px 0 0;
  accent-color: var(--accent);
}

.logout-options label > span {
  display: grid;
  gap: 4px;
}

.logout-options small {
  color: var(--muted);
}

.logout-options select {
  height: 36px;
  margin-top: 5px;
}

.logout-options .danger-button {
  margin-top: 8px;
}

.sidebar-scrim {
  position: fixed;
  z-index: 44;
  inset: var(--header-height) 0 0;
  background: rgba(0, 0, 0, 0.6);
}

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  max-width: min(430px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 920px) {
  .mail-app {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .mail-header {
    grid-template-columns: 210px minmax(220px, 1fr) auto;
  }

  .mail-search + * {
    justify-self: end;
  }

  .message-open {
    grid-template-columns: minmax(130px, 0.4fr) minmax(160px, 1fr) 58px;
  }

  .row-snippet {
    display: none;
  }
}

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

  .mail-header {
    grid-template-columns: auto minmax(120px, 1fr) auto;
    gap: 10px;
    padding: 0 12px;
  }

  .header-brand-block {
    gap: 3px;
  }

  .mobile-menu {
    display: inline-flex !important;
  }

  .mail-brand span {
    display: none;
  }

  .mail-brand img {
    width: 34px;
    height: 34px;
  }

  .mail-search {
    height: 40px;
  }

  .mail-search > span {
    font-size: 20px;
  }

  .sidebar {
    position: fixed;
    z-index: 45;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mail-content {
    grid-column: 1;
  }

  .list-toolbar,
  .reader-toolbar {
    min-height: 64px;
    padding: 0 15px;
  }

  .message-row {
    min-height: 66px;
  }

  .message-open {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 5px 10px;
    padding: 10px 13px 10px 0;
  }

  .message-open .row-subject {
    grid-column: 1;
    grid-row: 2;
  }

  .message-open time {
    grid-column: 2;
    grid-row: 1;
  }

  .reader-content {
    padding: 26px 20px 50px;
  }

  .reader-content h1 {
    font-size: 21px;
  }

  .reader-sender-row {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .reader-sender-row time {
    grid-column: 2;
  }

  .compose-window {
    right: 10px;
    width: calc(100vw - 20px);
  }
}

@media (max-width: 480px) {
  .auth-shell {
    width: min(100% - 28px, 420px);
    padding-top: 30px;
  }

  .auth-heading {
    margin-top: 42px;
  }

  .auth-heading h1 {
    font-size: 27px;
  }

  .mail-header {
    grid-template-columns: auto minmax(92px, 1fr) 38px;
    padding: 0 8px;
  }

  .mail-brand {
    display: none;
  }

  .mail-search {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
  }

  .mail-search input::placeholder {
    font-size: 12px;
  }

  .account-popover {
    right: 8px;
  }

  .compose-window {
    height: calc(100vh - 82px);
  }

  .modal-header,
  .profile-summary,
  .settings-form,
  .logout-options,
  .modal > .auth-form {
    padding-left: 16px;
    padding-right: 16px;
  }

  .compact-tabs {
    margin-left: 16px;
    margin-right: 16px;
  }
}

/* Account security and settings */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --surface-3: #e2e5ea;
  --line: #cfd3da;
  --line-soft: #e1e4e9;
  --text: #17181b;
  --muted: #666b75;
}

.mail-header {
  grid-template-columns: 244px minmax(260px, 720px) minmax(80px, 1fr);
}

.header-actions {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 8px;
}

.settings-button {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    transform 220ms ease;
}

.settings-button:hover {
  border-color: var(--line);
  background: var(--surface-3);
  color: var(--text);
  transform: rotate(35deg);
}

.avatar-button,
.large-avatar,
.small-avatar,
.sender-avatar,
.avatar-preview {
  overflow: hidden;
}

.avatar-button img,
.large-avatar img,
.small-avatar img,
.sender-avatar img,
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.current-account > span:not(.large-avatar) {
  margin-bottom: 0;
}

.avatar-picker input[type="file"],
.profile-avatar-editor input[type="file"] {
  display: none;
}

.avatar-picker-row {
  display: flex;
  align-items: center;
  gap: 13px;
}

.avatar-preview {
  display: inline-flex;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.avatar-picker-row .outline-button {
  display: inline-flex;
  width: auto;
  min-height: 38px;
  align-items: center;
  color: var(--text) !important;
  cursor: pointer;
}

.compose-window {
  top: 50%;
  right: auto;
  bottom: auto;
  left: 50%;
  width: min(640px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 90px));
  grid-template-rows: 50px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -47%) scale(0.97);
  transition:
    opacity 170ms ease,
    transform 190ms ease;
}

.compose-window.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.compose-header {
  border-radius: var(--radius) var(--radius) 0 0;
}

.compose-header > button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}

.compose-header > button:hover {
  background: var(--surface-2);
}

.compose-window form {
  grid-template-rows: 58px minmax(160px, 1fr) 62px;
}

.compose-window input {
  padding: 0 18px;
  font-size: 13px;
}

.compose-window textarea {
  padding: 20px 18px;
}

.settings-modal {
  width: min(1080px, calc(100% - 34px));
  height: min(760px, calc(100vh - 34px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.62);
  overflow: hidden;
}

.settings-modal::backdrop,
.modal::backdrop {
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(3px);
}

.settings-header {
  display: flex;
  height: 76px;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}

.settings-header p,
.panel-heading p {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
}

.settings-header h2,
.panel-heading h3 {
  margin: 0;
}

.settings-header h2 {
  font-size: 21px;
}

.settings-layout {
  display: grid;
  height: calc(100% - 76px);
  grid-template-columns: 240px minmax(0, 1fr);
}

.settings-nav {
  display: grid;
  align-content: start;
  gap: 5px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.settings-nav-button {
  display: grid;
  min-height: 46px;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-align: left;
  transition:
    color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.settings-nav-button:hover {
  background: var(--surface-3);
  color: var(--text);
  transform: translateX(2px);
}

.settings-nav-button.active {
  background: var(--accent-soft);
  color: var(--text);
}

.settings-nav-button.active span {
  color: var(--accent);
}

.settings-content {
  min-width: 0;
  overflow-y: auto;
}

.settings-panel {
  display: none;
  width: min(720px, calc(100% - 54px));
  margin: 0 auto;
  padding: 34px 0 54px;
}

.settings-panel.active {
  display: block;
  animation: panel-enter 190ms ease both;
}

.panel-heading {
  margin-bottom: 28px;
}

.panel-heading h3 {
  font-size: 24px;
}

.settings-panel .settings-form {
  gap: 18px;
  padding: 0;
  border: 0;
}

.settings-panel .settings-form input {
  background: var(--surface-2);
}

.profile-avatar-editor {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 5px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}

.profile-avatar-editor .large-avatar {
  width: 72px;
  height: 72px;
  margin: 0 8px 0 0;
}

.profile-avatar-editor label {
  display: inline-flex;
  width: auto;
  min-height: 40px;
  align-items: center;
  cursor: pointer;
}

.text-button {
  min-height: 36px;
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.text-button:hover {
  color: var(--accent);
}

.settings-subheading {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding-top: 22px;
  border-top: 1px solid var(--line-soft);
}

.settings-subheading h4,
.security-block h4 {
  margin: 0;
  font-size: 15px;
}

.settings-subheading span,
.security-block span,
.devices-toolbar > span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-submit {
  justify-self: start;
  margin-top: 8px;
}

.security-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line-soft);
}

.security-block > div {
  display: grid;
  gap: 6px;
}

#two-factor-status.enabled {
  color: var(--success);
  font-weight: 800;
}

.security-form {
  margin-top: 10px;
}

.devices-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}

.device-list {
  display: grid;
}

.device-item {
  display: grid;
  min-height: 78px;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}

.device-icon {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
  font-size: 19px;
}

.device-item > div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.device-item span,
.device-item em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.device-item em {
  color: var(--success);
  font-weight: 800;
}

.settings-form fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.settings-form legend {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.segmented-control {
  display: grid;
  width: min(360px, 100%);
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented-control label {
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: var(--muted);
  font-weight: 750;
}

.segmented-control input:checked + span {
  background: var(--accent);
  color: #fff;
}

.color-control {
  display: flex;
  width: min(360px, 100%);
  height: 48px;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.color-control input[type="color"] {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
}

.color-control b {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

.theme-preview {
  display: grid;
  min-height: 74px;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.theme-preview > span {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--preview-accent, var(--accent));
}

.theme-preview > div {
  display: grid;
  gap: 4px;
}

.theme-preview small {
  color: var(--muted);
}

.theme-preview button {
  min-height: 36px;
  padding: 7px 12px;
  border-radius: var(--radius);
  background: var(--preview-accent, var(--accent));
  color: #fff;
  font-weight: 750;
}

.two-factor-setup {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.two-factor-setup > img {
  width: 210px;
  height: 210px;
  padding: 8px;
  border-radius: var(--radius);
  background: #fff;
}

.two-factor-setup > p,
.form-note,
.recovery-codes-content > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.secret-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.secret-row code {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-wrap: anywhere;
}

.two-factor-setup .auth-form {
  width: 100%;
}

.recovery-codes-content {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.recovery-codes-content pre {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font:
    700 14px/1.8 "Cascadia Mono",
    Consolas,
    monospace;
  text-align: center;
}

dialog[open] {
  animation: dialog-enter 180ms ease both;
}

dialog[open]::backdrop {
  animation: backdrop-enter 180ms ease both;
}

.account-popover:not([hidden]) {
  animation: popover-enter 160ms ease both;
}

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dialog-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes backdrop-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popover-enter {
  from {
    opacity: 0;
    transform: translateY(-7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  .mail-header {
    grid-template-columns: 210px minmax(220px, 1fr) auto;
  }

  .settings-layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .mail-header {
    grid-template-columns: auto minmax(120px, 1fr) auto;
  }

  .settings-modal {
    width: calc(100% - 18px);
    height: calc(100vh - 18px);
  }

  .settings-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .settings-nav {
    display: flex;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }

  .settings-nav-button {
    min-width: 180px;
  }

  .settings-panel {
    width: calc(100% - 30px);
    padding-top: 24px;
  }

  .compose-window {
    right: auto;
    width: calc(100vw - 20px);
    height: min(560px, calc(100vh - 32px));
  }
}

@media (max-width: 480px) {
  .mail-header {
    grid-template-columns: auto minmax(80px, 1fr) auto;
  }

  .settings-button,
  .avatar-button {
    width: 36px;
    height: 36px;
  }

  .profile-avatar-editor,
  .devices-toolbar,
  .security-block {
    align-items: flex-start;
    flex-direction: column;
  }

  .device-item {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .device-item .outline-button {
    grid-column: 2;
    justify-self: start;
  }

  .secret-row {
    align-items: stretch;
    flex-direction: column;
  }
}

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