:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --text: #10203a;
  --muted: #66748a;
  --line: #d7e0eb;
  --soft: #f7f9fc;
  --blue: #2f63e8;
  --blue-dark: #214ec4;
  --red: #c92218;
  --red-dark: #9f1c14;
  --green: #178c55;
  --warn: #b7791f;
  --shadow: 0 14px 34px rgba(16, 32, 58, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--blue-dark);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  outline: none;
}

textarea {
  min-height: 260px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 15px;
}

.hidden {
  display: none !important;
}

.notice-popup {
  position: fixed;
  z-index: 1000;
  top: 50%;
  left: 50%;
  width: min(430px, calc(100vw - 32px));
  min-height: 132px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 22px 22px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.notice-popup.ok {
  border-left-color: var(--green);
}

.notice-popup.warn {
  border-left-color: var(--warn);
}

.notice-popup.error {
  border-left-color: var(--red);
}

.notice-popup strong {
  display: block;
  margin-bottom: 9px;
  font-size: 18px;
}

.notice-popup p {
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.notice-popup button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text);
  background: #edf3f8;
}

.notice-popup button:hover {
  background: #dde8f2;
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth {
  align-content: center;
  gap: 14px;
}

.auth-panel,
.panel,
header,
.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel {
  width: min(620px, 100%);
  padding: 28px;
  display: grid;
  gap: 18px;
  position: relative;
}

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

.cat-logo {
  display: inline-block;
  background-image: url("/cats.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.login-logo,
.brand img,
.login-brand img,
aside .brand img {
  width: 52px;
  height: 52px;
  max-width: 52px;
  max-height: 52px;
  flex: 0 0 52px;
  object-fit: contain;
}

.side-logo,
.brand.compact img,
aside .brand.compact img {
  width: 38px;
  height: 38px;
  max-width: 38px;
  max-height: 38px;
  flex-basis: 38px;
}

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

.brand small,
p,
.message,
.hint,
.login-hint {
  color: var(--muted);
  font-size: 13px;
}

.auth-form,
.form-stack {
  display: grid;
  gap: 13px;
}

.auth-form button {
  min-height: 40px;
  font-size: 16px;
}

.login-hint {
  margin-top: 4px;
}

.side-language {
  display: grid;
  gap: 6px;
}

.login-language {
  position: absolute;
  top: 30px;
  right: 28px;
}

.login-language select {
  width: auto;
  min-width: 88px;
  min-height: 38px;
  padding: 8px 10px;
  background: #fff;
}

.side-language {
  color: #b7c2d4;
}

.side-language select {
  min-height: 34px;
  padding: 7px 9px;
}

.admin-profile {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.admin-profile h3 {
  font-size: 22px;
}

.admin-panel {
  align-content: start;
}

.admin-profile button {
  justify-self: end;
  min-height: 34px;
  padding: 0 18px;
}

.admin-password-section {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.compact-kv {
  display: grid;
  gap: 7px;
}

.compact-kv div {
  display: grid;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.compact-kv div:last-child {
  border-bottom: 0;
}

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

.compact-kv strong {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.powered-by {
  color: var(--text);
  font-size: 13px;
  text-align: center;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

aside {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: #10203a;
  color: #fff;
}

aside .brand small {
  color: #b7c2d4;
}

nav {
  display: grid;
  gap: 8px;
}

nav button,
#logout {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

nav button.active {
  background: #fff;
  color: var(--text);
}

#logout {
  margin-top: auto;
}

main {
  min-width: 0;
  padding: 28px;
}

header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 18px 20px;
  margin-bottom: 20px;
}

#status {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: #fff;
}

#status.ok,
.message.ok {
  color: var(--green);
}

#status.warn {
  color: var(--warn);
}

#status.error,
.message.error {
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.grid {
  display: grid;
  gap: 20px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.mail-workspace {
  align-items: stretch;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}

.server-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(360px, 1.5fr);
  gap: 20px;
  align-items: stretch;
}

.service-control-panel {
  min-width: 0;
}

.status-grid {
  align-items: stretch;
}

.metric-card {
  min-height: 300px;
}

.disk-gauge {
  --gauge-color: var(--green);
  width: 190px;
  height: 190px;
  margin: 4px auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--gauge-color) calc(var(--value, 0) * 1%), #e6edf5 0);
  position: relative;
}

.disk-gauge::before {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  background: #fff;
}

.disk-gauge strong {
  position: relative;
  z-index: 1;
  font-size: 38px;
}

.compact-disk {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-top: 8px;
}

.compact-disk h2 {
  width: 100%;
  text-align: left;
}

#serverTimeText {
  text-align: center;
  line-height: 1.45;
}

.compact-disk .disk-gauge {
  width: 142px;
  height: 142px;
}

.compact-disk .disk-gauge::before {
  inset: 17px;
}

.compact-disk .disk-gauge strong {
  font-size: 30px;
}

.traffic-chart {
  min-height: 205px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(#f8fbff, #fff);
  overflow: hidden;
}

.traffic-chart svg {
  display: block;
  width: 100%;
  height: 205px;
}

.chart-empty {
  min-height: 205px;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

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

.chart-empty span {
  max-width: 320px;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.spam-pie {
  --reject: 0%;
  --junk: 0%;
  width: 190px;
  height: 190px;
  margin: 4px auto;
  border-radius: 50%;
  background: conic-gradient(var(--red) 0 var(--reject), #d9a427 var(--reject) var(--junk), var(--green) var(--junk) 100%);
}

.spam-pie.empty {
  background: #e6edf5;
  border: 1px dashed var(--line);
}

.spam-pie.loading {
  display: grid;
  place-items: center;
  background: #eef4fb;
  border: 1px dashed var(--line);
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #d7e0eb;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 999px;
}

.ham-dot {
  background: var(--green);
}

.spam-dot {
  background: #d9a427;
}

.reject-dot {
  background: var(--red);
}

.config-actions-panel {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
}

.blacklist-grid {
  align-items: start;
}

.blacklist-record-panel {
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr);
}

#blacklistList {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.panel {
  padding: 20px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.inbox-panel {
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-content: stretch;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.panel-head button,
.panel-actions button,
.row-actions button,
.domain-row button,
.item button {
  min-height: 32px;
  padding: 0 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 12px;
  align-items: end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-grid button {
  align-self: end;
}

.provision-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  grid-template-areas:
    "domains mailbox"
    "alias alias";
  gap: 20px;
  align-items: start;
}

.domain-panel {
  grid-area: domains;
}

.mailbox-panel {
  grid-area: mailbox;
}

.alias-panel {
  grid-area: alias;
}

#aliasList {
  max-height: 300px;
  overflow: auto;
  padding-right: 4px;
}

.domain-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.domain-table-head,
.domain-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 150px;
  gap: 12px;
  align-items: center;
}

.domain-table-head {
  padding: 10px 12px;
  color: var(--muted);
  background: var(--soft);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.domain-list {
  display: grid;
  max-height: 320px;
  overflow: auto;
}

.domain-row {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.domain-row:last-child {
  border-bottom: 0;
}

.domain-row span {
  color: var(--green);
  font-size: 13px;
}

.list,
.kv,
.directory-list,
.mailbox-list {
  display: grid;
  gap: 10px;
}

.kv div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  font-size: 13px;
}

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

.kv strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  box-shadow: none;
}

.domain-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.domain-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  color: var(--text);
  background: var(--soft);
  text-align: left;
}

.domain-toggle:hover {
  color: var(--blue-dark);
  background: #eef4ff;
}

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

.mailbox-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

button.edit {
  background: var(--blue);
}

button.edit:hover {
  background: var(--blue-dark);
}

button.delete,
button.danger-soft {
  background: var(--red);
}

button.delete:hover,
button.danger-soft:hover {
  background: var(--red-dark);
}

.empty {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

pre {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  font: 13px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

#messageDialog {
  width: min(760px, calc(100vw - 32px));
}

#configDialog {
  width: min(980px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(16, 32, 58, 0.35);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

#cancelMailboxPassword,
#closeMessage,
#closeConfigDialog,
#cancelConfigDialog {
  color: var(--text);
  background: #edf3f8;
}

.config-dialog-form textarea {
  min-height: 55vh;
}

.message-link {
  min-height: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  overflow-wrap: anywhere;
}

.message-link:hover {
  color: var(--blue-dark);
  background: transparent;
  text-decoration: underline;
}

.mail-list {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background: #fff;
}

.mail-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.48fr) 132px;
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.mail-row:last-child {
  border-bottom: 0;
}

.mail-row span,
.mail-row time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  min-width: 0;
}

.mail-row time {
  white-space: nowrap;
  text-align: right;
}

.message-dialog iframe {
  width: 100%;
  max-height: 60vh;
  min-height: 360px;
  background: #f8fafc;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .shell,
  .grid.two,
  .grid.three,
  .server-top-grid,
  .provision-grid,
  .config-actions-panel {
    grid-template-columns: 1fr;
  }

  .provision-grid {
    grid-template-areas:
      "domains"
      "mailbox"
      "alias";
  }
}

@media (max-width: 720px) {
  main {
    padding: 18px;
  }

  header,
  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form,
  .form-grid,
  .domain-table-head,
  .domain-row,
  .mailbox-row,
  .item,
  .mail-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }
}
