:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #1c2328;
  --muted: #667077;
  --line: #dce1e4;
  --soft: #eef1f2;
  --sidebar: #202624;
  --sidebar-muted: #9fa9a5;
  --accent: #0f766e;
  --accent-dark: #0a5d57;
  --accent-soft: #dff3f0;
  --amber: #b45309;
  --amber-soft: #fff1dc;
  --danger: #b42318;
  --danger-soft: #feeceb;
  --shadow: 0 16px 44px rgba(24, 31, 35, 0.14);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: white; padding: 22px 14px 18px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.sidebar .brand { padding: 0 8px 24px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--accent); color: white; border-radius: 6px; font: 700 22px/1 Consolas, monospace; flex: 0 0 auto; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: var(--sidebar-muted); margin-top: 2px; font-size: 11px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { width: 100%; min-height: 42px; border: 0; border-radius: 6px; padding: 0 12px; display: flex; align-items: center; gap: 10px; color: #d8dedb; background: transparent; text-align: left; }
.nav-item.active { background: #343c39; color: white; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #39403e; padding: 16px 8px 0; display: flex; align-items: center; gap: 8px; color: var(--sidebar-muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #7d8984; }
.status-dot.online { background: #38b890; box-shadow: 0 0 0 3px rgba(56, 184, 144, .14); }

.workspace { min-width: 0; padding: 28px 32px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.topbar h1, .section-toolbar h2, .dialog h2 { margin: 0; color: var(--ink); }
.topbar h1 { font-size: 25px; line-height: 1.25; }
.topbar p, .section-toolbar p, .dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 10px; }
.btn { min-height: 38px; border: 1px solid transparent; border-radius: 6px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 600; font-size: 13px; text-decoration: none; }
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.btn.secondary:hover { background: var(--soft); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { min-height: 116px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px; display: flex; flex-direction: column; }
.stat > span { color: var(--muted); font-size: 12px; }
.stat strong { margin: 7px 0 3px; font-size: 27px; line-height: 1.15; }
.stat small { margin-top: auto; color: #8a9398; font-size: 11px; }
.stat.accent { border-top: 3px solid var(--amber); padding-top: 16px; }
.stat .time-value { font-size: 16px; margin-top: 14px; overflow-wrap: anywhere; }

.table-section { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.section-toolbar { min-height: 74px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-toolbar h2 { font-size: 16px; }
.search-field { width: min(300px, 100%); height: 38px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; gap: 8px; padding: 0 11px; background: #fafbfb; color: var(--muted); }
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .1); }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 18px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f8f9f9; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 700; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
.address-button { border: 0; padding: 0; background: transparent; color: var(--accent-dark); font-weight: 650; text-align: left; }
.address-button:hover { text-decoration: underline; }
.tag { display: inline-flex; max-width: 170px; padding: 3px 7px; border-radius: 4px; background: var(--soft); color: #4b555b; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions-col { width: 166px; text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-btn { width: 34px; height: 34px; border: 1px solid transparent; border-radius: 5px; display: inline-grid; place-items: center; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.light { color: white; }
.icon-btn.light:hover { background: rgba(255,255,255,.14); color: white; }
.empty-state { min-height: 260px; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 5px; }
.empty-state[hidden] { display: none; }
.empty-state strong { color: var(--ink); }

.dialog { width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 36px); padding: 0; border: 0; border-radius: 7px; color: var(--ink); box-shadow: var(--shadow); overflow: auto; }
.dialog::backdrop { background: rgba(16, 22, 25, .52); }
.dialog form, .dialog > :not(.dialog-head) { margin-left: 22px; margin-right: 22px; }
.dialog form { margin: 0; padding: 22px; }
.dialog form .dialog-head { padding: 0 0 20px; border-bottom: 0; }
.dialog.compact { width: min(420px, calc(100vw - 28px)); }
.dialog.large { width: min(820px, calc(100vw - 28px)); }
.dialog-head { min-height: 70px; padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.dialog h2 { font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 2px 0 6px; }
.field { display: grid; gap: 7px; }
.field > span { color: #3e484e; font-size: 12px; font-weight: 600; }
.field input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 5px; padding: 0 11px; outline: none; color: var(--ink); background: #fff; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .1); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 20px; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 12px; }

.mail-list { margin: 0 !important; }
.mail-row { width: 100%; min-height: 68px; border: 0; border-bottom: 1px solid var(--line); padding: 12px 22px; background: white; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; text-align: left; }
.mail-row:hover { background: #fafcfc; }
.mail-row:last-child { border-bottom: 0; }
.mail-row strong, .mail-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row strong { font-size: 13px; }
.mail-row span { color: var(--muted); font-size: 12px; }
.mail-row time { color: #879097; font-size: 11px; }
.code-chip { align-self: center; grid-row: span 2; padding: 5px 8px; border-radius: 4px; background: var(--amber-soft); color: var(--amber); font: 700 13px/1 Consolas, monospace; }
.code-banner { margin: 18px 22px 0 !important; min-height: 62px; border-radius: 6px; padding: 10px 14px; background: var(--accent); color: white; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; }
.code-banner[hidden] { display: none; }
.code-banner span { font-size: 12px; opacity: .8; }
.code-banner strong { font: 700 26px/1 Consolas, monospace; }
.message-body { margin: 18px 22px !important; min-height: 180px; max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 16px; background: #fafbfb; color: #2f383d; font: 13px/1.65 "Segoe UI", "Microsoft YaHei", sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-links { margin-bottom: 22px !important; display: grid; gap: 7px; }
.message-links a { color: var(--accent-dark); font-size: 12px; overflow-wrap: anywhere; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; max-width: min(420px, calc(100vw - 28px)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #222926; color: white; padding: 10px 15px; border-radius: 5px; box-shadow: var(--shadow); font-size: 13px; transition: opacity .18s ease, transform .18s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.public-page { background: #f3f5f4; }
.public-header { min-height: 68px; padding: 0 max(22px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.public-header .brand small { color: var(--muted); }
.public-main { width: min(1180px, calc(100% - 44px)); margin: 0 auto; padding: 30px 0 50px; }
.public-title { margin-bottom: 20px; }
.public-title > span { color: var(--muted); font-size: 12px; }
.public-title h1 { margin: 6px 0; font-size: 24px; overflow-wrap: anywhere; }
.public-title p { margin: 0; color: var(--muted); font-size: 13px; }
.public-layout { min-height: 590px; display: grid; grid-template-columns: minmax(280px, 36%) minmax(0, 1fr); background: white; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.public-list { border-right: 1px solid var(--line); overflow-y: auto; }
.public-list .mail-row.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.public-message { padding: 24px; min-width: 0; }
.public-message h2 { margin: 0 0 7px; font-size: 20px; overflow-wrap: anywhere; }
.public-message .meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.public-message .message-body { margin: 20px 0 !important; max-height: none; }
.public-message .message-links { margin: 0 !important; }
.empty-message { height: 100%; min-height: 360px; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 5px; }
.empty-message strong { color: var(--ink); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding-left: 10px; padding-right: 10px; }
  .sidebar .brand { padding-left: 9px; }
  .sidebar .brand div, .nav-item:not(.active) span + *, .sidebar-foot span:last-child { display: none; }
  .nav-item { justify-content: center; padding: 0; font-size: 0; }
  .nav-item span { font-size: 18px; }
  .sidebar-foot { justify-content: center; }
  .workspace { padding: 24px 22px 40px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .public-layout { grid-template-columns: 1fr; }
  .public-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 320px; }
}

@media (max-width: 620px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: 62px; padding: 10px 14px; flex-direction: row; align-items: center; }
  .sidebar .brand { padding: 0; }
  .sidebar .brand div { display: block; }
  .sidebar nav { margin-left: auto; }
  .sidebar-foot { display: none; }
  .workspace { padding: 20px 14px 36px; }
  .topbar { align-items: flex-start; }
  .topbar h1 { font-size: 21px; }
  .top-actions { flex-direction: column-reverse; align-items: stretch; }
  .stats-grid { gap: 8px; }
  .stat { min-height: 100px; padding: 14px; }
  .stat strong { font-size: 23px; }
  .stat .time-value { font-size: 13px; }
  .section-toolbar { align-items: stretch; flex-direction: column; }
  .search-field { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .dialog-actions .btn { flex: 1; }
  .public-header { padding: 10px 14px; }
  .public-main { width: calc(100% - 28px); padding-top: 22px; }
  .public-title h1 { font-size: 19px; }
  .public-layout { min-height: 520px; }
  .public-message { padding: 18px; }
}
