:root {
  --ink: #18213a;
  --muted: #6c7691;
  --line: rgba(141, 157, 191, 0.22);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --sky: #0ea5e9;
  --danger: #ef476f;
  --shadow: 0 20px 45px rgba(42, 50, 100, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 8% 2%, rgba(129, 140, 248, 0.19), transparent 25rem),
    radial-gradient(circle at 92% 14%, rgba(56, 189, 248, 0.16), transparent 27rem),
    linear-gradient(180deg, #f6f7ff 0%, #eef2ff 45%, #f8faff 100%);
}

body::before {
  position: fixed;
  z-index: -1;
  top: 22%;
  right: -8rem;
  width: 24rem;
  height: 24rem;
  border-radius: 50%;
  background: rgba(196, 181, 253, 0.17);
  content: "";
  filter: blur(12px);
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  padding: 13px clamp(18px, 4vw, 54px);
  color: #fff;
  background: rgba(20, 25, 53, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 32px rgba(24, 28, 62, 0.2);
  backdrop-filter: blur(18px);
}

.brand,
.nav,
.nav-user,
.actions,
.section-heading,
.temp-action-row,
.mailbox-options {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.27);
  border-radius: 13px;
  background: linear-gradient(145deg, #38bdf8, #6366f1 60%, #a855f7);
  box-shadow: 0 8px 18px rgba(56, 189, 248, 0.22);
  font-size: 19px;
}

.logo {
  font-size: 16px;
  font-weight: 760;
  letter-spacing: 0.01em;
}

.brand-caption {
  margin-top: 2px;
  color: rgba(224, 231, 255, 0.7);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.nav {
  gap: 7px;
}

.nav > a,
.nav-link {
  padding: 9px 11px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.83);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.nav > a:hover,
.nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.11);
  transform: translateY(-1px);
}

.nav-user {
  gap: 10px;
  margin-left: 4px;
  padding: 4px 5px 4px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.nav-email {
  max-width: 175px;
  overflow: hidden;
  color: #e0e7ff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container {
  width: min(1320px, calc(100% - 36px));
  margin: 30px auto 54px;
}

.card {
  position: relative;
  margin-bottom: 20px;
  padding: clamp(20px, 3vw, 32px);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.card::before {
  position: absolute;
  top: 0;
  right: 8%;
  left: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.55), transparent);
  content: "";
}

h1,
h2 {
  margin: 0;
  color: #18213a;
  font-weight: 780;
  letter-spacing: -0.035em;
}

h2 {
  font-size: clamp(21px, 2.5vw, 27px);
}

.section-heading {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.section-copy,
.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.section-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: 999px;
  color: #4338ca;
  background: #eef2ff;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
  color: #35405c;
  font-size: 13px;
  font-weight: 750;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
  line-height: 1.55;
}

.ai-config-card {
  max-width: 820px;
  margin-right: auto;
  margin-left: auto;
}

.ai-config-form {
  max-width: 680px;
}

.ai-config-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.ai-model-row {
  display: flex;
  align-items: stretch;
  gap: 9px;
}

.ai-model-control {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 8px;
}

.ai-model-control select,
.ai-model-control input {
  min-width: 0;
}

.ai-model-control [hidden] {
  display: none;
}

.ai-inline-button,
.ai-test-button {
  min-height: 46px;
}

.ai-inline-button {
  flex: 0 0 auto;
  padding-right: 16px;
  padding-left: 16px;
}

.ai-inline-button:disabled,
.ai-test-button:disabled {
  opacity: 0.62;
  cursor: wait;
  transform: none;
}

.ai-operation-status {
  padding: 12px 14px;
  border: 1px solid #dfe4f2;
  border-radius: 12px;
  color: #4f5b75;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
}

.ai-operation-status[hidden] {
  display: none;
}

.field-help.is-loading,
.ai-operation-status.is-loading {
  color: #4f46e5;
}

.field-help.is-success,
.field-help.is-error {
  border: 0;
  background: transparent;
}

.field-help.is-success {
  color: #166534;
}

.ai-operation-status.is-success {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.field-help.is-error {
  color: #b42318;
}

.ai-operation-status.is-error {
  color: #b42318;
  border-color: #fecaca;
  background: #fff7f7;
}

.form-grid input:not([type="checkbox"]),
.form-grid select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid #dfe4f2;
  border-radius: 13px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 1px 1px rgba(30, 41, 59, 0.02);
  font: inherit;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.form-grid input:not([type="checkbox"]):hover,
.form-grid select:hover {
  border-color: #bec7e1;
}

.form-grid input:not([type="checkbox"]):focus,
.form-grid select:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.mailbox-form {
  grid-template-columns: minmax(170px, 1fr) minmax(190px, 1.1fr) minmax(120px, 0.55fr) auto;
  align-items: end;
}

.domain-form,
.alias-form {
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, 0.85fr) auto;
  align-items: end;
}

.alias-form {
  grid-template-columns: minmax(145px, 0.65fr) minmax(180px, 0.8fr) minmax(220px, 1.2fr) auto;
}

.domain-form .checkbox {
  min-height: 46px;
}

.mailbox-options {
  grid-column: 1 / -1;
  gap: 20px;
  padding: 5px 2px 0;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #44506b;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.checkbox input[type="checkbox"] {
  width: 19px;
  height: 19px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

button,
input,
select {
  font: inherit;
}

.primary,
.action-btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #4f46e5, #6366f1 55%, #0ea5e9);
  box-shadow: 0 9px 18px rgba(79, 70, 229, 0.2);
}

.primary {
  min-height: 46px;
  padding: 0 19px;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary:hover,
.action-btn.primary:hover {
  color: #fff;
  filter: saturate(1.1) brightness(1.04);
  box-shadow: 0 12px 22px rgba(79, 70, 229, 0.29);
  transform: translateY(-1px);
}

.actions {
  gap: 7px;
  flex-wrap: wrap;
}

.actions form,
.temp-form {
  margin: 0;
}

.action-btn {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 720;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.action-btn.secondary {
  border-color: #e1e6f1;
  color: #4f5b75;
  background: rgba(255, 255, 255, 0.8);
}

.action-btn.secondary:hover {
  border-color: #c9d2e8;
  color: #26324d;
  background: #fff;
  box-shadow: 0 6px 14px rgba(73, 84, 125, 0.1);
  transform: translateY(-1px);
}

.action-btn.danger {
  border-color: #ffd6e0;
  color: #d92d5c;
  background: #fff1f4;
}

.action-btn.danger:hover {
  border-color: #ffb8cb;
  color: #bd1647;
  background: #ffe6ed;
  transform: translateY(-1px);
}

.temporary-card {
  background:
    radial-gradient(circle at 100% 0%, rgba(103, 232, 249, 0.2), transparent 18rem),
    linear-gradient(125deg, rgba(255, 255, 255, 0.94), rgba(243, 244, 255, 0.93));
}

.temp-action-row {
  gap: 18px;
  flex-wrap: wrap;
}

.temp-form {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 13px;
  padding: 5px 6px 5px 13px;
  border: 1px solid rgba(210, 217, 239, 0.86);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.7);
}

.temp-form .action-btn {
  min-height: 34px;
}

.temp-form.danger-form {
  border-color: #ffd9e3;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.58);
}

.table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

.table th {
  padding: 13px 14px;
  color: #6b7691;
  background: rgba(242, 245, 255, 0.83);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 14px;
  border-top: 1px solid rgba(220, 226, 241, 0.72);
  color: #35405a;
  font-size: 14px;
  font-weight: 560;
  vertical-align: middle;
}

.table tbody tr {
  transition: background 0.2s ease;
}

.table tbody tr:hover {
  background: rgba(238, 242, 255, 0.66);
}

.mailbox-address {
  color: #222e49;
  font-weight: 760;
}

.status-chip,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.status-chip.is-active {
  color: #15803d;
  background: #dcfce7;
}

.status-chip.is-inactive {
  color: #b45309;
  background: #fef3c7;
}

.badge {
  margin-top: 6px;
}

.badge.warning {
  color: #b45309;
  background: #fef3c7;
}

.flash {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.flash-item {
  padding: 12px 15px;
  border: 1px solid #bceff5;
  border-radius: 14px;
  color: #0f6173;
  background: rgba(236, 254, 255, 0.88);
  box-shadow: 0 8px 18px rgba(14, 116, 144, 0.06);
  font-size: 14px;
  font-weight: 650;
}

.auth-card {
  max-width: 510px;
  margin: clamp(30px, 8vh, 90px) auto;
}

.auth-card .form-grid {
  gap: 18px;
}

.auth-heading {
  margin-bottom: 24px;
}

.auth-heading .hint {
  margin-bottom: 0;
}

.auth-actions {
  display: flex;
  justify-content: center;
}

.empty-state {
  padding: 34px !important;
  color: var(--muted) !important;
  text-align: center;
}

@media (max-width: 850px) {
  .topbar {
    align-items: flex-start;
    gap: 14px;
  }

  .nav {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .mailbox-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mailbox-form .primary,
  .domain-form .primary,
  .alias-form .primary {
    grid-column: span 2;
  }

  .domain-form,
  .alias-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar {
    position: relative;
    flex-direction: column;
    padding: 15px 18px;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-user {
    margin-left: 0;
  }

  .container {
    width: min(100% - 22px, 1320px);
    margin-top: 16px;
  }

  .card {
    padding: 20px;
    border-radius: 19px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

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

  .mailbox-form .primary,
  .domain-form .primary,
  .alias-form .primary,
  .mailbox-options {
    grid-column: auto;
  }

  .domain-form,
  .alias-form {
    grid-template-columns: 1fr;
  }

  .mailbox-options,
  .temp-action-row,
  .temp-form {
    align-items: flex-start;
    flex-direction: column;
  }

  .temp-form {
    width: 100%;
  }

  .temp-form .action-btn {
    width: 100%;
  }

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

  .ai-inline-button {
    width: 100%;
  }
}
