:root {
  color-scheme: dark;
  --bg: #050505;
  --surface: #0b0b0c;
  --surface-2: #111113;
  --surface-3: #17171a;
  --field: #09090a;
  --line: #242428;
  --line-soft: #1a1a1d;
  --ink: #f6f6f7;
  --muted: #97979d;
  --faint: #626268;
  --blue: #2f6eea;
  --blue-2: #1f56c7;
  --danger: #ff6d61;
  --ok: #8ff0b0;
  --warn: #e2bf65;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.42;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #3a3a42;
  background: var(--surface-3);
}

button:disabled {
  cursor: wait;
  opacity: .5;
}

button.danger {
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 34px;
  padding: 7px 10px;
}

textarea {
  min-height: 120px;
  padding: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #5a5a64;
}

input[readonly] {
  color: var(--muted);
}

::placeholder {
  color: var(--faint);
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* GMX-style mail screen */
.mail-body {
  overflow: hidden;
}

.mail-app {
  display: grid;
  grid-template-rows: 78px minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  padding: 18px 22px 22px;
  background: #030303;
}

.mail-topbar {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #09090a;
  padding: 12px 18px;
}

.gmx-logo {
  font-size: 42px;
  line-height: 1;
  font-weight: 950;
  letter-spacing: -2px;
}

.mail-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  overflow: hidden;
  border: 1px solid #36363c;
  border-radius: 999px;
  background: #050505;
}

.mail-search input {
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 18px;
}

.mail-search button {
  min-height: 42px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-button,
.refresh-button {
  min-height: 44px;
  border-radius: 14px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
}

.refresh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  border-color: #2559c5;
  background: #1d5ee8;
  color: #fff;
  padding: 0 14px;
  font-weight: 760;
}

.refresh-button:hover {
  border-color: #3570ff;
  background: #2d6df0;
}

.refresh-button:disabled svg {
  animation: refresh-spin .8s linear infinite;
}

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

.top-link,
.top-logout button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101012;
  padding: 0 12px;
  color: var(--muted);
}

.top-logout {
  margin: 0;
  justify-self: start;
}

.mail-layout {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 330px minmax(360px, 540px) minmax(420px, 1fr);
  gap: 18px;
  overflow: hidden;
  padding-top: 18px;
}

.mail-sidebar,
.mail-list-pane,
.mail-preview-pane {
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 24px;
  background: #0a0a0b;
  overflow: hidden;
}

.mail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  overflow: auto;
  scrollbar-color: #33333a transparent;
}

.compose-slot {
  display: grid;
}

.compose-button {
  min-height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: #fff;
  font-weight: 760;
}

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

.side-section {
  display: grid;
  gap: 8px;
}

.side-title {
  padding: 0 8px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.mail-account-list {
  display: grid;
  gap: 4px;
}

.side-account {
  display: grid;
  gap: 2px;
  border-radius: 16px;
  padding: 10px 12px;
  color: var(--muted);
}

.side-account:hover,
.side-account.active {
  background: #151519;
  color: #fff;
}

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

.side-account small {
  color: var(--faint);
  font-size: 12px;
}

.share-panel {
  margin-top: auto;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

.mail-address,
.share-created {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.mail-address span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.share-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.mini-share-list {
  display: grid;
  gap: 4px;
}

.mini-share-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.mini-share-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-share-row small.active {
  color: var(--ok);
}

.mini-share-row small.expired {
  color: var(--warn);
}

.mini-share-row small.revoked {
  color: var(--danger);
}

.mini-share-row button {
  width: 28px;
  min-height: 28px;
  padding: 0;
}

.mail-list-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.list-head {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 16px;
}

.list-head div {
  display: grid;
  gap: 2px;
}

.list-head strong {
  font-size: 17px;
}

.list-head span {
  color: var(--muted);
  font-size: 13px;
}

.message-list {
  min-height: 0;
  overflow: auto;
  scrollbar-color: #33333a transparent;
}

.message-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 86px;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px;
}

.message-row::before {
  content: attr(data-avatar);
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #27272d;
  color: #fff;
  font-weight: 760;
}

.message-row:hover,
.message-row.active {
  background: #141417;
}

.message-row.unread .message-main h2,
.message-row.unread .message-meta strong {
  color: #fff;
  font-weight: 820;
}

.message-meta,
.message-main {
  min-width: 0;
}

.message-meta {
  display: none;
}

.message-main {
  display: grid;
  gap: 4px;
}

.message-main h2,
.message-main p,
.message-main .row-from {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-main .row-from {
  font-weight: 720;
}

.message-main h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.message-main p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.message-row time {
  align-self: start;
  color: var(--muted);
  font-size: 12px;
}

.mail-preview-pane {
  overflow: auto;
  padding: 18px;
  scrollbar-color: #33333a transparent;
}

.mail-preview-card {
  min-height: 100%;
  border-radius: 20px;
  background: #0d0d0f;
  padding: 18px;
}

.preview-head {
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.preview-back {
  color: #fff;
  font-weight: 720;
}

.preview-head h1 {
  margin: 14px 0;
  font-size: 24px;
}

.preview-head dl,
.reader dl {
  display: grid;
  gap: 6px;
  margin: 0;
}

.preview-head dl div,
.reader dl div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
}

.preview-head dt,
.reader dt {
  color: var(--muted);
}

.preview-head dd,
.reader dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.preview-empty {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  color: var(--muted);
}

.empty-envelope {
  width: 180px;
  height: 112px;
  border: 2px solid #414148;
  position: relative;
}

.empty-envelope::before,
.empty-envelope::after {
  content: "";
  position: absolute;
  inset: 0;
  border-top: 2px solid #414148;
  transform-origin: top left;
}

.empty-envelope::before {
  transform: skewY(37deg);
}

.empty-envelope::after {
  transform: skewY(-37deg);
}

.mail-empty-accounts {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: calc(100vh - 120px);
  color: var(--muted);
}

.mail-empty-accounts h1 {
  margin: 0;
  color: #fff;
  font-size: 54px;
}

.mail-empty-accounts a {
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
}

/* Shared/direct reader and admin pages */
.app-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: #080809;
  padding: 18px 12px;
  overflow: auto;
}

.brand {
  padding: 0 8px;
  font-size: 15px;
  font-weight: 760;
}

.nav,
.account-list {
  display: grid;
  gap: 3px;
}

.nav a,
.account-link {
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--muted);
}

.nav a:hover,
.account-link:hover,
.nav a.active,
.account-link.active {
  background: #151519;
  color: #fff;
}

.account-link {
  display: grid;
  gap: 2px;
}

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

.account-link small,
.copy-field span,
.stack span,
.shared-expiry,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.logout-form {
  margin-top: auto;
}

.logout-form button {
  width: 100%;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.account-add-grid {
  display: grid;
  grid-template-columns: minmax(250px, 360px) minmax(300px, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.panel,
.account-table,
.share-list,
.reader,
.login-panel,
.notice,
.alert,
.issues,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.panel,
.reader,
.login-panel,
.notice,
.alert,
.issues,
.empty-state {
  padding: 14px;
}

.panel h2,
.list-title {
  margin: 0;
  font-size: 13px;
}

.stack {
  display: grid;
  gap: 12px;
}

.stack label,
.copy-field {
  display: grid;
  gap: 5px;
}

.import-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.import-form input {
  max-width: 360px;
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(200px, 1.2fr) minmax(120px, .8fr) minmax(230px, auto);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}

.table-head,
.list-title {
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.table-row,
.share-row {
  border-bottom: 1px solid var(--line);
}

.table-row:last-child,
.share-row:last-child {
  border-bottom: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto;
  gap: 7px;
}

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

.status,
.badge {
  color: var(--muted);
}

.status.ok,
.badge.active {
  color: var(--ok);
}

.status.error,
.badge.revoked {
  color: var(--danger);
}

.status.syncing,
.status.new,
.status.updated,
.badge.expired {
  color: var(--warn);
}

.badge {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

.share-list {
  margin-bottom: 12px;
  overflow: hidden;
}

.share-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(180px, 1.2fr) 116px 116px 116px 84px 86px;
  gap: 9px;
  align-items: center;
  padding: 9px 12px;
  color: var(--muted);
}

.share-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader h1 {
  margin: 12px 0;
  font-size: 22px;
}

.reader-head {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.reader-head > a {
  font-weight: 720;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.attachments a {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  background: var(--surface-2);
}

.message-body {
  max-width: 980px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.message-body a {
  color: #fff;
  text-decoration: underline;
  text-decoration-color: #555;
}

.message-body table {
  max-width: 100%;
  border-collapse: collapse;
}

.message-body pre {
  white-space: pre-wrap;
}

.alert,
.issues {
  color: var(--danger);
}

.notice {
  color: #dcdcdc;
}

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

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

.login-panel {
  width: min(100%, 360px);
}

.login-panel h1 {
  margin: 0 0 18px;
  font-size: 20px;
}

.shared-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0;
}

.shared-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.shared-head h1 {
  margin: 2px 0 0;
  font-size: 22px;
}

.shared-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.mailbox-toolbar,
.share-result,
.shared-controls {
  display: grid;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.mailbox-toolbar {
  grid-template-columns: minmax(230px, 360px) auto minmax(230px, 320px);
}

.mailbox-toolbar.compact,
.share-result {
  grid-template-columns: minmax(230px, 1fr) auto;
}

@media (max-width: 1180px) {
  .mail-body {
    overflow: auto;
  }

  .mail-app {
    grid-template-rows: auto;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 12px;
  }

  .mail-topbar {
    grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  }

  .mail-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    overflow: visible;
    gap: 12px;
    padding-top: 12px;
  }

  .mail-sidebar,
  .mail-list-pane,
  .mail-preview-pane {
    height: auto;
    min-height: 320px;
  }

  .mail-sidebar {
    min-height: auto;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .main {
    padding: 14px;
  }

  .account-add-grid,
  .table-head,
  .table-row,
  .share-row,
  .mailbox-toolbar,
  .mailbox-toolbar.compact,
  .share-result {
    grid-template-columns: 1fr;
  }

  .import-form,
  .actions {
    align-items: stretch;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 13px;
  }

  .mail-app {
    padding: 10px;
  }

  .mail-topbar {
    grid-template-columns: auto auto;
    grid-template-areas:
      "logo refresh"
      "search search"
      "accounts logout";
    justify-content: stretch;
    gap: 9px;
    border-radius: 16px;
    padding: 10px;
  }

  .gmx-logo {
    grid-area: logo;
    font-size: 34px;
    letter-spacing: -1px;
  }

  .mail-search {
    grid-area: search;
  }

  .refresh-button {
    grid-area: refresh;
    justify-self: end;
  }

  .top-link {
    grid-area: accounts;
  }

  .top-logout {
    grid-area: logout;
    justify-self: stretch;
  }

  .top-link,
  .top-logout button {
    width: 100%;
    min-height: 40px;
  }

  .mail-sidebar,
  .mail-list-pane,
  .mail-preview-pane {
    border-radius: 18px;
  }

  .mail-sidebar {
    padding: 12px;
    gap: 10px;
  }

  .compose-slot {
    display: none;
  }

  .mail-account-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .mail-account-list::-webkit-scrollbar {
    display: none;
  }

  .side-account {
    min-width: 170px;
    padding: 10px;
  }

  .share-panel {
    margin-top: 0;
  }

  .share-form,
  .mail-address,
  .share-created {
    grid-template-columns: 1fr;
  }

  .list-head {
    min-height: 54px;
    padding: 10px 12px;
  }

  .mail-list-pane {
    min-height: 64vh;
  }

  .mail-preview-pane {
    min-height: 52vh;
    padding: 10px;
  }

  .message-row {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    min-height: 80px;
    padding: 10px;
  }

  .message-row::before {
    grid-row: 1 / span 2;
    width: 40px;
    height: 40px;
    font-size: 12px;
  }

  .message-main {
    grid-column: 2;
  }

  .message-main h2 {
    font-size: 13px;
  }

  .message-row time {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    font-size: 11px;
  }

  .mail-preview-card {
    border-radius: 16px;
    padding: 14px;
  }

  .preview-head h1 {
    font-size: 20px;
  }

  .preview-head dl div,
  .reader dl div {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .empty-envelope {
    width: 126px;
    height: 78px;
  }

  .shared-shell {
    width: min(100% - 20px, 1120px);
    padding: 14px 0;
  }

  .shared-head {
    align-items: start;
    flex-direction: column;
  }

  .shared-actions {
    justify-content: stretch;
  }

  .shared-actions .refresh-button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .mail-app {
    padding: 8px;
  }

  .mail-topbar {
    border-radius: 14px;
  }

  .gmx-logo {
    font-size: 30px;
  }

  .refresh-button {
    min-height: 40px;
    padding: 0 12px;
  }

  .mail-search input {
    min-height: 40px;
    padding: 0 12px;
  }

  .mail-search button {
    min-height: 40px;
  }

  .side-account {
    min-width: 150px;
  }

  .message-row {
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 76px;
  }

  .message-row::before {
    width: 34px;
    height: 34px;
  }
}
