:root {
  color-scheme: light;
  --ink: #14202b;
  --ink-soft: #344550;
  --paper: #edf1f2;
  --surface: #f8faf9;
  --surface-strong: #ffffff;
  --line: #c7d0d3;
  --line-dark: #8e9ca2;
  --signal: #e96538;
  --signal-dark: #b94621;
  --teal: #1f5c68;
  --teal-soft: #d8e6e6;
  --good: #19724e;
  --warn: #966014;
  --bad: #a33a34;
  --shadow: 0 18px 45px rgba(20, 32, 43, 0.11);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(20, 32, 43, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 28px;
}

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

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.masthead {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 46px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--signal);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font: 800 17px/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  transform: rotate(-2deg);
}

.brand h1 {
  margin: 0;
  font-size: clamp(19px, 2.2vw, 27px);
  letter-spacing: -0.04em;
}

.brand p, .muted { color: var(--ink-soft); }
.brand p { margin: 3px 0 0; font-size: 12px; letter-spacing: .08em; }

.login-layout {
  min-height: calc(100vh - 78px);
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  align-items: center;
  gap: clamp(40px, 8vw, 110px);
  padding: 56px 0 80px;
}

.login-copy { max-width: 580px; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  color: var(--teal);
  font: 700 12px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 28px; height: 3px; background: var(--signal); }

.login-copy h2 {
  max-width: 11ch;
  margin: 0;
  font-size: clamp(44px, 7.5vw, 88px);
  line-height: .98;
  letter-spacing: -.075em;
}

.login-copy > p {
  max-width: 42ch;
  margin: 28px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.8;
}

.login-card, .panel {
  background: var(--surface);
  border: 1px solid var(--line-dark);
  box-shadow: var(--shadow);
}

.login-card { padding: clamp(25px, 5vw, 42px); position: relative; }
.login-card::before {
  content: "MAIL DELIVERY";
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 7px 9px;
  color: var(--signal-dark);
  border: 2px solid var(--signal);
  border-radius: 50%;
  font: 800 8px/1 ui-monospace, monospace;
  letter-spacing: .08em;
  transform: rotate(9deg);
}

.login-card h3 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.04em; }
.login-card > p { margin: 0 0 28px; color: var(--ink-soft); font-size: 13px; }

.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field span { font-size: 12px; font-weight: 700; letter-spacing: .04em; }

input, select, textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line-dark);
  border-radius: 2px;
  outline: none;
}

input, select { min-height: 44px; padding: 0 13px; }
textarea { min-height: 140px; padding: 12px 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(31, 92, 104, .15); }

.btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  color: var(--ink);
  background: white;
  font-weight: 750;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 3px 3px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid rgba(233, 101, 56, .35); outline-offset: 2px; }
.btn-primary { color: white; background: var(--ink); }
.btn-signal { color: white; background: var(--signal); border-color: var(--signal-dark); }
.btn-danger { color: var(--bad); border-color: #d7aaa7; }
.btn-small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn[disabled] { cursor: wait; opacity: .6; transform: none; box-shadow: none; }

.error-box, .notice {
  margin-top: 16px;
  padding: 11px 12px;
  border-left: 4px solid var(--bad);
  background: #f9e9e7;
  color: #702d29;
  font-size: 13px;
}
.notice { border-color: var(--teal); background: var(--teal-soft); color: var(--ink); }
[hidden] { display: none !important; }

.admin-main { padding: 28px 0 70px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.toolbar-group { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px rgba(150,96,20,.12); }
.status-dot.connected { background: var(--good); box-shadow: 0 0 0 4px rgba(25,114,78,.12); }
.status-dot.error { background: var(--bad); box-shadow: 0 0 0 4px rgba(163,58,52,.12); }

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line-dark);
  background: var(--surface);
  margin-bottom: 20px;
}
.stat { padding: 18px 20px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font: 800 30px/1 ui-monospace, monospace; }
.stat span { display: block; margin-top: 7px; color: var(--ink-soft); font-size: 12px; }

.panel { padding: 20px; margin-bottom: 20px; box-shadow: 0 8px 24px rgba(20,32,43,.07); }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 18px; letter-spacing: -.03em; }
.panel-head p { margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }

.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.compact-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.compact-form .field { margin: 0; }

.table-wrap { overflow: auto; border: 1px solid var(--line); background: white; }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
th, td { padding: 12px 13px; text-align: left; border-bottom: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #e4eaeb; color: var(--ink-soft); font-size: 11px; letter-spacing: .06em; }
tbody tr:hover { background: #f2f6f5; }
.email-text { font: 700 12px/1.4 ui-monospace, Consolas, monospace; }
.code-text { font: 850 18px/1 ui-monospace, Consolas, monospace; letter-spacing: .08em; }
.tag { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border: 1px solid var(--line-dark); border-radius: 999px; background: white; font-size: 10px; }
.tag.used { color: var(--teal); border-color: #79a4ab; background: #e7f1f1; }
.tag.disabled { color: var(--bad); border-color: #d9aaa7; background: #fae9e7; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.empty { padding: 42px 18px; text-align: center; color: var(--ink-soft); }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(20,32,43,.62); }
.modal { width: min(540px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border: 2px solid var(--ink); box-shadow: 9px 9px 0 var(--signal); padding: 24px; }
.modal h2 { margin: 0 0 8px; }
.modal .secret { margin: 18px 0; padding: 16px; border: 1px dashed var(--ink); background: white; font: 800 15px/1.5 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }

.mailbox-main { width: min(760px, calc(100% - 32px)); margin: 0 auto; padding: 38px 0 80px; }
.mailbox-heading { margin-bottom: 28px; }
.mailbox-heading h2 { margin: 0; font-size: clamp(30px, 5vw, 50px); letter-spacing: -.06em; }
.mailbox-address { margin-top: 10px; color: var(--teal); font: 700 14px/1.4 ui-monospace, Consolas, monospace; }
.mailbox-heading .mailbox-address-title {
  color: var(--teal);
  font: 750 clamp(20px, 4vw, 32px)/1.35 ui-monospace, Consolas, monospace;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}
.code-list { display: grid; gap: 14px; }
.code-card { position: relative; padding: 22px; background: var(--surface); border: 1px solid var(--line-dark); box-shadow: 5px 5px 0 #a9b6ba; }
.code-card::after { content: "ARRIVED"; position: absolute; top: 13px; right: 14px; color: var(--signal); font: 800 9px/1 ui-monospace, monospace; letter-spacing: .1em; transform: rotate(5deg); }
.code-card strong { display: block; margin: 6px 0 14px; font: 900 clamp(30px, 8vw, 48px)/1 ui-monospace, Consolas, monospace; letter-spacing: .14em; }
.code-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--ink-soft); font-size: 12px; }

@media (max-width: 800px) {
  .login-layout { grid-template-columns: 1fr; gap: 38px; align-content: center; }
  .login-copy h2 { max-width: 9ch; }
  .stats-strip { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .import-grid, .compact-form { grid-template-columns: 1fr; }
}

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