:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #61706a;
  --subtle: #f4f6f4;
  --canvas: #eef2ef;
  --surface: #ffffff;
  --line: #d8dfdb;
  --line-strong: #bcc8c2;
  --brand: #13765a;
  --brand-strong: #0d5d46;
  --brand-soft: #e5f3ed;
  --blue: #27618d;
  --blue-soft: #e9f2f8;
  --amber: #99631b;
  --amber-soft: #fff3d8;
  --red: #a33b39;
  --red-soft: #fbe9e7;
  --shadow: 0 1px 2px rgba(23, 33, 29, 0.06), 0 8px 24px rgba(23, 33, 29, 0.05);
  --radius: 8px;
  --radius-sm: 5px;
  --sidebar-width: 224px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { letter-spacing: 0; }
a { color: var(--brand-strong); }

.app-shell { min-height: 100vh; }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1030;
  width: var(--sidebar-width);
  padding: 22px 14px;
  background: #15221d;
  color: #edf4f1;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 8px;
  color: #fff;
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 7px;
  background: #208467;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #9eb4aa;
  font-size: 10px;
  font-weight: 500;
}

.side-nav { margin-top: 28px; display: grid; gap: 5px; }

.side-nav button,
.side-footer a {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 11px;
  background: transparent;
  color: #b8c9c1;
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  text-align: left;
  font-weight: 600;
}

.side-nav button:hover,
.side-footer a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav button.active { background: #edf7f3; color: #0d5d46; }
.side-nav i, .side-footer i { font-size: 17px; }
.side-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.11); padding-top: 12px; }

.app-main { min-height: 100vh; margin-left: var(--sidebar-width); }

.topbar {
  min-height: 68px;
  padding: 12px 28px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; }
.topbar-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-nav { display: none; }

.app-content { width: min(1500px, 100%); padding: 24px 28px 40px; }
.view { display: none; }
.view.active { display: block; }

.section-heading {
  margin: 0 0 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 { margin: 0; font-size: 18px; font-weight: 700; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric-card {
  min-width: 0;
  min-height: 112px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23,33,29,.04);
}

.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-icon { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; background: var(--subtle); color: var(--brand); }
.metric-value { margin-top: 8px; font-size: 26px; line-height: 1.1; font-weight: 750; }
.metric-note { margin-top: 6px; color: var(--muted); font-size: 11px; }

.panel {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.panel-header h3 { margin: 0; font-size: 14px; font-weight: 700; }
.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar .search-field { flex: 1 1 240px; max-width: 360px; }
.toolbar .filter-field { width: 158px; }
.toolbar-spacer { flex: 1 1 auto; }

.form-control, .form-select, .input-group-text {
  min-height: 38px;
  border-color: var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(19,118,90,.12);
}

.btn {
  min-height: 38px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 650;
}

.btn-icon { width: 38px; padding: 0; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-strong); --bs-btn-hover-border-color: var(--brand-strong); }
.btn-outline-primary { --bs-btn-color: var(--brand-strong); --bs-btn-border-color: #83ae9f; --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.btn-outline-secondary { --bs-btn-color: #47544e; --bs-btn-border-color: var(--line-strong); --bs-btn-hover-bg: var(--subtle); --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: #9cacA4; }

.table-responsive { overflow-x: auto; }
.data-table { width: 100%; margin: 0; min-width: 820px; }
.data-table > :not(caption) > * > * { padding: 12px 14px; border-color: #e8ecea; vertical-align: middle; }
.data-table thead th { background: #f7f9f8; color: #596760; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.data-table tbody tr:hover { background: #fafcfb; }
.data-table .check-col { width: 42px; text-align: center; }
.data-table .action-col { width: 1%; white-space: nowrap; text-align: right; }
.table-primary-text { font-weight: 650; word-break: break-word; }
.table-secondary-text { margin-top: 2px; color: var(--muted); font-size: 11px; }

.status-badge {
  min-height: 23px;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
}

.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pending { background: var(--amber-soft); color: var(--amber); }
.status-active, .status-ready { background: var(--brand-soft); color: var(--brand-strong); }
.status-error { background: var(--red-soft); color: var(--red); }
.status-draining { background: var(--blue-soft); color: var(--blue); }
.status-disabled, .status-expired, .status-deleting { background: #ecefed; color: #68736e; }

.dns-record {
  margin-top: 6px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f7f9f8;
  color: #34413b;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  word-break: break-all;
}

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

.empty-state i { display: block; margin-bottom: 10px; font-size: 30px; color: #91a29a; }
.empty-state strong { display: block; color: var(--ink); }
.empty-state p { margin: 5px 0 0; font-size: 12px; }
.loading-row td { height: 160px; color: var(--muted); text-align: center; }
.spinner-border-sm { --bs-spinner-width: 1rem; --bs-spinner-height: 1rem; }

.pagination-bar {
  min-height: 54px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pagination-meta { color: var(--muted); font-size: 12px; }
.selection-bar {
  display: none;
  min-height: 48px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid #a7cbbf;
  border-radius: var(--radius);
  background: #edf8f4;
  align-items: center;
  gap: 8px;
}
.selection-bar.visible { display: flex; }
.selection-bar strong { margin-right: auto; }

.modal-content { border: 0; border-radius: var(--radius); box-shadow: 0 24px 70px rgba(15,30,23,.2); }
.modal-header, .modal-footer { border-color: var(--line); }
.modal-title { font-size: 16px; font-weight: 750; }
.admin-mail-layout { min-height: 520px; }
.modal-note { margin: 0 0 14px; padding: 10px 12px; border-left: 3px solid #d2a140; background: #fff8e8; color: #624718; font-size: 12px; }
.form-label { margin-bottom: 6px; color: #3d4a44; font-size: 12px; font-weight: 700; }
.form-text { color: var(--muted); font-size: 11px; }

.settings-panel { max-width: 760px; }
.settings-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
.settings-state.is-loading { color: var(--blue); }
.settings-state.is-saved { color: var(--brand-strong); }
.settings-state.is-error { color: var(--red); }
.settings-url-field { max-width: 640px; }
.settings-preview {
  max-width: 640px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f7f9f8;
  display: grid;
  gap: 4px;
}
.settings-preview span { color: var(--muted); font-size: 11px; font-weight: 700; }
.settings-preview code { color: #34413b; overflow-wrap: anywhere; white-space: normal; }
.settings-check {
  max-width: 640px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.settings-check-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.settings-check-head > div { display: grid; gap: 2px; min-width: 0; }
.settings-check-head strong { font-size: 13px; }
.settings-check-head span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.settings-check-duration { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.settings-check-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.settings-check-item {
  min-height: 64px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 7px;
}
.settings-check-item i { grid-row: 1 / 3; color: var(--muted); font-size: 18px; }
.settings-check-item span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.settings-check-item strong { min-width: 0; font-size: 12px; overflow-wrap: anywhere; }
.settings-check-item.is-ok { border-color: #b9dfcf; background: #f0faf6; }
.settings-check-item.is-ok i { color: var(--brand-strong); }
.settings-check-item.is-error { border-color: #edc1bd; background: #fff5f4; }
.settings-check-item.is-error i { color: var(--red); }
.settings-check-details { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); display: grid; gap: 7px; }
.settings-check-details > div { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 8px; }
.settings-check-details dt { color: var(--muted); font-size: 11px; font-weight: 700; }
.settings-check-details dd { margin: 0; font-family: var(--font-mono, monospace); font-size: 11px; overflow-wrap: anywhere; }
#settings-check-error-row dd { color: var(--red); font-family: inherit; }
.settings-note { max-width: 640px; margin-top: 14px; margin-bottom: 0; }
.settings-actions { max-width: 640px; margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }

.toast-container { z-index: 1090; }
.toast { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef2ef; }
.login-shell { width: min(380px, 100%); }
.login-brand { margin-bottom: 18px; justify-content: center; color: var(--ink); }
.login-brand .brand-mark { color: #fff; }
.login-panel { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.login-panel h1 { margin: 0 0 5px; font-size: 19px; font-weight: 750; }
.login-panel > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

/* Public mailbox */
.mailbox-page { min-height: 100vh; background: #edf1ef; }
.mailbox-header {
  min-height: 64px;
  padding: 11px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.mailbox-header .brand { color: var(--ink); padding: 0; }
.mailbox-header-actions { display: flex; align-items: center; gap: 8px; }
.mailbox-address { max-width: min(42vw, 480px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.mailbox-workspace { height: calc(100vh - 64px); display: grid; grid-template-columns: minmax(310px, 400px) minmax(0, 1fr); }
.message-pane { min-width: 0; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.message-toolbar { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.message-toolbar .input-group { min-width: 0; }
.message-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.message-item {
  width: 100%;
  min-height: 92px;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid #e7ebe9;
  background: #fff;
  color: inherit;
  text-align: left;
}
.message-item:hover { background: #f6f9f7; }
.message-item.active { background: #eaf5f0; box-shadow: inset 3px 0 var(--brand); }
.message-item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.message-sender { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.message-time { flex: 0 0 auto; color: var(--muted); font-size: 10px; }
.message-subject { margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.message-preview { margin-top: 4px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-pager { min-height: 50px; padding: 8px 12px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.reader-pane { min-width: 0; min-height: 0; background: #f8faf9; display: flex; flex-direction: column; }
.reader-empty { flex: 1 1 auto; display: grid; place-items: center; color: var(--muted); text-align: center; }
.reader-empty i { display: block; margin-bottom: 10px; font-size: 34px; color: #99aaa2; }
.reader-content { min-height: 0; height: 100%; display: flex; flex-direction: column; }
.reader-content[hidden] { display: none; }
.reader-head { padding: 20px 24px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.reader-subject { margin: 0; font-size: 19px; line-height: 1.35; font-weight: 750; word-break: break-word; }
.reader-meta { margin-top: 12px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; color: var(--muted); font-size: 12px; }
.reader-meta strong { color: var(--ink); }
.reader-actions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 7px; }
.reader-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 22px 24px; background: #fff; }
.reader-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.7 inherit; }
.reader-frame { width: 100%; min-height: 520px; border: 0; background: #fff; }
.attachment-strip { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 7px; }
.attachment-link { min-height: 36px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 7px; }
.attachment-link:hover { border-color: #8eb5a7; background: var(--brand-soft); color: var(--brand-strong); }
.session-gate { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 20px; }
.session-gate-box { width: min(420px, 100%); padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; text-align: center; box-shadow: var(--shadow); }
.session-gate-box i { font-size: 30px; color: var(--brand); }
.session-gate-box h1 { margin: 12px 0 6px; font-size: 18px; }
.session-gate-box p { margin: 0; color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-sidebar { display: none; }
  .app-main { margin-left: 0; padding-bottom: 60px; }
  .topbar { min-height: 60px; padding: 10px 16px; }
  .topbar-actions .btn-label { display: none; }
  .app-content { padding: 16px 12px 28px; }
  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 1040;
    min-height: 58px;
    border-top: 1px solid var(--line);
    background: #fff;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 1px; font-size: 10px; }
  .mobile-nav button i { font-size: 18px; }
  .mobile-nav button.active { color: var(--brand-strong); background: #f1f8f5; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .btn { width: 100%; }
  .toolbar .search-field, .toolbar .filter-field { flex: 1 1 calc(50% - 4px); width: auto; max-width: none; }
  .mailbox-header { padding: 9px 12px; }
  .mailbox-header .brand span:not(.brand-mark) { display: none; }
  .mailbox-address { max-width: 48vw; font-size: 12px; }
  .mailbox-workspace { height: calc(100vh - 60px); display: block; }
  .message-pane, .reader-pane { height: 100%; border: 0; }
  .reader-pane { display: none; }
  .mailbox-workspace.reading .message-pane { display: none; }
  .mailbox-workspace.reading .reader-pane { display: flex; }
  .reader-head { padding: 16px; }
  .reader-body { padding: 16px; }
  .reader-frame { min-height: 440px; }
}

@media (max-width: 520px) {
  .metrics { grid-template-columns: 1fr; gap: 8px; }
  .metric-card { min-height: 94px; }
  .metric-value { font-size: 22px; }
  .toolbar .search-field, .toolbar .filter-field { flex-basis: 100%; }
  .selection-bar { align-items: stretch; flex-wrap: wrap; }
  .selection-bar strong { width: 100%; }
  .pagination-bar { align-items: flex-start; flex-direction: column; }
  .pagination-bar .btn-group { width: 100%; }
  .pagination-bar .btn { flex: 1; }
  .settings-check-grid { grid-template-columns: 1fr; }
  .settings-check-item { min-height: 52px; }
  .settings-actions { flex-direction: column-reverse; }
  .settings-actions .btn { width: 100%; }
}

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