:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eef1f2;
  --line: #d8dddf;
  --text: #172024;
  --muted: #657278;
  --accent: #087f5b;
  --accent-hover: #066c4d;
  --accent-soft: #dff4ec;
  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --warning: #9c6500;
  --shadow: 0 12px 36px rgba(25, 36, 40, 0.14);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

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

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

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  background: #172024;
  color: #ffffff;
  border-bottom: 1px solid #0d1316;
}

.brand,
.modal-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #20c997;
  color: #0c2c22;
  font-size: 12px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  margin-top: 2px;
  color: #aeb8bc;
  font-size: 12px;
}

.top-actions,
.row-actions,
.input-action,
.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.service-status {
  color: #b9c2c5;
  font-size: 12px;
}

.service-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #ffd43b;
}

.service-status.online::before {
  background: #20c997;
}

.workspace {
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.domains-panel {
  padding: 22px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.panel-heading,
.column-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1,
h2 {
  font-size: 15px;
  line-height: 1.35;
}

.panel-heading p,
.modal-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.compact-form {
  margin-top: 22px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #cbd2d5;
  border-radius: 5px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.12);
}

.input-action input,
.copy-field input {
  flex: 1 1 auto;
}

.button,
.icon-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.button {
  padding: 0 13px;
  font-weight: 600;
}

.icon-button {
  width: 38px;
  flex: 0 0 38px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 20px;
}

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

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

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

.topbar .button.secondary {
  color: #ffffff;
  background: #273338;
  border-color: #3f4b50;
}

.button.danger {
  background: var(--danger-soft);
  border-color: #ffc9c9;
  color: var(--danger);
}

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

.domain-list {
  margin-top: 16px;
  border-top: 1px solid var(--line);
}

.domain-row {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.domain-name {
  min-width: 0;
}

.domain-name strong,
.domain-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-name strong {
  font-size: 13px;
}

.domain-name span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 34px;
}

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

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: #adb5bd;
  cursor: pointer;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 150ms ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(14px);
}

.main-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.create-strip {
  padding: 16px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.create-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(190px, 1fr) 120px auto;
  align-items: end;
  gap: 12px;
}

.create-button {
  height: 38px;
}

.mail-layout {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
}

.inbox-column,
.message-column {
  min-width: 0;
  background: var(--surface);
}

.inbox-column {
  border-right: 1px solid var(--line);
}

.column-heading {
  min-height: 66px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.column-heading span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.selected-inbox {
  min-width: 0;
}

.selected-inbox h2,
.selected-inbox span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-list,
.message-list {
  overflow-y: auto;
}

.item-list {
  height: calc(100vh - 64px - 71px - 66px);
}

.inbox-item,
.message-item {
  width: 100%;
  display: block;
  padding: 13px 16px;
  text-align: left;
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.inbox-item:hover,
.message-item:hover,
.inbox-item.active,
.message-item.active {
  background: var(--surface-muted);
}

.inbox-item.active,
.message-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.item-title,
.item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-title strong,
.item-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-title strong {
  font-size: 13px;
}

.item-title em {
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 9px;
  color: #065f46;
  background: var(--accent-soft);
  font-size: 10px;
  font-style: normal;
  text-align: center;
}

.item-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.message-workspace {
  height: calc(100vh - 64px - 71px - 66px);
  min-height: 360px;
  display: grid;
  grid-template-columns: minmax(220px, 34%) minmax(0, 1fr);
}

.message-list {
  border-right: 1px solid var(--line);
}

.message-item .subject {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-item .sender,
.message-item .time {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-detail {
  min-width: 0;
  overflow: auto;
  background: #fbfcfc;
}

.message-header {
  padding: 20px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.message-header h3 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.message-header dl {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
  font-size: 12px;
}

.message-header dt {
  color: var(--muted);
}

.message-header dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.message-body {
  padding: 22px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

.attachment-list {
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.attachment-list button {
  margin: 4px 6px 4px 0;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(430px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(11, 18, 21, 0.66);
}

.modal .modal-heading {
  margin-bottom: 22px;
}

.modal h2 {
  font-size: 18px;
}

.modal input {
  margin-bottom: 14px;
}

.form-error {
  min-height: 18px;
  margin: -4px 0 10px;
  color: var(--danger);
  font-size: 12px;
}

.full-width {
  width: 100%;
}

.credential-modal .copy-field {
  margin-bottom: 14px;
}

.credential-modal .copy-field input {
  margin: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: 5px;
  background: #172024;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

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

.hidden {
  display: none !important;
}

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

  .create-form {
    grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) 110px;
  }

  .create-button {
    grid-column: 1 / -1;
  }

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

  .item-list,
  .message-workspace {
    height: calc(100vh - 64px - 121px - 66px);
  }
}

@media (max-width: 740px) {
  .topbar {
    height: auto;
    min-height: 64px;
    padding: 12px 14px;
  }

  .service-status,
  .topbar .button.secondary:first-of-type {
    display: none;
  }

  .workspace,
  .mail-layout,
  .message-workspace {
    display: block;
  }

  .domains-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .domain-list {
    max-height: 180px;
    overflow: auto;
  }

  .create-form {
    grid-template-columns: 1fr 1fr;
  }

  .local-field,
  .create-button {
    grid-column: 1 / -1;
  }

  .inbox-column {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .item-list,
  .message-list,
  .message-workspace {
    height: auto;
    max-height: none;
  }

  .item-list,
  .message-list {
    max-height: 300px;
  }

  .message-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .message-detail {
    min-height: 360px;
  }

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

  .row-actions {
    width: 100%;
  }
}

