:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-subtle: #f8f9fa;
  --text: #17181a;
  --muted: #696d75;
  --border: #dfe2e7;
  --border-strong: #c8cdd5;
  --accent: #d81f26;
  --accent-hover: #b9181e;
  --success: #137a4d;
  --success-bg: #e8f5ee;
  --danger: #b42318;
  --focus: #2563eb;
  --shadow: 0 12px 30px rgba(22, 26, 34, 0.08);
}

* { box-sizing: border-box; }

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

button, input, a { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 68px;
  padding: 0 clamp(20px, 5vw, 64px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 32px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 30px);
  font-weight: 500;
  line-height: 1.2;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}
.auth-area { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.role-label { padding: 5px 8px; border-radius: 5px; background: #eef0f3; color: var(--muted); font-size: 12px; font-weight: 650; }

.status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #18a563;
  box-shadow: 0 0 0 3px #dff5e9;
}

main {
  width: min(900px, calc(100% - 32px));
  margin: clamp(32px, 8vh, 76px) auto;
}

.workspace {
  padding: clamp(24px, 5vw, 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-heading { margin-bottom: 28px; text-align: center; }
.section-heading p {
  margin: 6px 0 0;
  color: var(--accent);
  font-size: 16px;
}
.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h2, h3 { margin: 0; letter-spacing: 0; }
h2 { font-size: clamp(23px, 4vw, 30px); line-height: 1.25; }
h3 { font-size: 18px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

label {
  display: block;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 650;
}
.field-hint { margin: -3px 0 9px; color: var(--muted); font-size: 13px; }

.query-row { max-width: 660px; margin: 0 auto; }
.query-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: clamp(50px, 12vw, 120px);
}
.query-actions .primary { min-width: 132px; }
input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 140ms, box-shadow 140ms;
}
input::placeholder { color: #9a9ea6; }
input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13); }
input.invalid { border-color: var(--danger); }

button, .open-button {
  height: 42px;
  padding: 0 17px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
  transition: background 140ms, border-color 140ms, transform 80ms;
}
button:active, .open-button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.25); outline-offset: 2px; }

.primary {
  height: 46px;
  background: var(--accent);
  color: #fff;
}
.primary:hover { background: var(--accent-hover); }
.primary:disabled { cursor: wait; opacity: 0.72; }
.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.secondary:hover, .copy-button:hover, .text-button:hover { background: #f1f2f4; }

.deploy-open {
  color: #fff;
  background: #d71920;
  border-color: #d71920;
}

.deploy-open:hover {
  color: #fff;
  background: #b9141a;
  border-color: #b9141a;
}

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  margin: auto;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}
.loading .button-label { display: none; }
.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-error {
  min-height: 20px;
  margin: 7px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.empty-state {
  min-height: 218px;
  margin-top: 22px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--muted);
  text-align: center;
}
.empty-state p { margin: 0; font-size: 14px; }
.empty-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
}

.result {
  margin-top: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.guest-result { margin-top: 22px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.guest-links { padding: 14px 20px 20px; display: grid; gap: 8px; }
.guest-link-row { min-height: 58px; padding: 10px 14px; display: grid; grid-template-columns: 150px minmax(110px, 1fr) auto auto; align-items: center; gap: 14px; border: 1px solid var(--border); border-radius: 5px; }
.guest-link-row span { color: var(--muted); font-size: 12px; }
.guest-link-row .result-time { color: var(--muted); font-size: 13px; display: grid; gap: 4px; }
.validity { font-style: normal; font-size: 13px; font-weight: 700; }
.validity-active { color: var(--success); }
.validity-expired { color: var(--accent); }
.validity-unknown { color: var(--muted); }
.login-code {
  color: var(--accent) !important;
  font: 800 clamp(32px, 5vw, 44px)/1 Consolas, monospace !important;
  letter-spacing: 7px;
  text-shadow: 0 1px 0 rgba(216, 31, 38, 0.12);
}
.guest-link-row a { color: var(--accent); font-size: 13px; font-weight: 650; text-decoration: none; }
.guest-link-row a:hover { text-decoration: underline; }
.verify-action { min-width: 0; display: grid; justify-items: center; gap: 5px; }
.verify-action a { color: var(--accent); font-weight: 700; }
.verify-action .verify-cta {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(216, 31, 38, 0.18);
}
.verify-action .verify-cta:hover { background: var(--accent-hover); text-decoration: none; }
.verify-action small { display: block; color: #17181a; font-size: 12px; white-space: nowrap; }
.result-head {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}
.result-tip { max-width: 620px; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.result-tip strong { display: block; color: var(--accent); font-weight: 500; }
.success-badge {
  padding: 5px 9px;
  border-radius: 5px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}
dl { margin: 0; }
.field-row {
  min-height: 68px;
  padding: 13px 20px;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}
dt { color: var(--muted); font-size: 13px; }
dd { margin: 0; overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: 14px; }
.secret { letter-spacing: 2px; }
.field-actions { display: flex; gap: 5px; }
.copy-button, .text-button {
  height: 32px;
  padding: 0 10px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}
.result-actions { padding: 18px 20px; display: flex; gap: 10px; }
.open-button { display: inline-flex; align-items: center; justify-content: center; }

.mailbox { margin-top: 22px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.mailbox-head { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; background: var(--surface-subtle); border-bottom: 1px solid var(--border); }
.mail-count { color: var(--muted); font-size: 12px; }
.mailbox-controls { padding: 15px 20px 4px; display: flex; align-items: center; gap: 9px; }
.mailbox-controls label { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
select { height: 36px; padding: 0 28px 0 10px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: var(--text); }
.mailbox-controls button { margin-left: auto; height: 36px; }
.mail-list { padding: 14px 20px 20px; display: grid; gap: 10px; }
.mail-empty { margin: 8px 0; color: var(--muted); font-size: 13px; text-align: center; }
.mail-card { padding: 14px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); }
.mail-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.mail-card-head strong { font-size: 14px; }
.mail-card-head time, .mail-meta { color: var(--muted); font-size: 12px; }
.mail-meta { margin-top: 5px; }
.mail-card pre { margin: 12px 0 0; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.6 "Segoe UI", "Microsoft YaHei", Arial, sans-serif; color: #30343b; }
.mail-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mail-links a { color: var(--accent); font-size: 12px; text-decoration: none; }
.mail-links a:hover { text-decoration: underline; }
.mail-links .verify-action { padding: 6px 9px; border-radius: 4px; background: var(--success-bg); }
.mail-links .verify-link { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 6px;
  background: #24262a;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.login-dialog { width: min(400px, calc(100% - 28px)); padding: 0; border: 1px solid var(--border); border-radius: 7px; box-shadow: 0 20px 60px rgba(0,0,0,.22); }
.login-dialog::backdrop { background: rgba(22,24,28,.48); }
.login-dialog form { padding: 22px; }
.dialog-head { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.icon-button { width: 34px; height: 34px; padding: 0; border-color: var(--border); background: var(--surface); color: var(--muted); font-size: 22px; font-weight: 400; line-height: 1; }
.dialog-submit { width: 100%; }

.deploy-section { margin-top: 22px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.deploy-body { padding: 18px 20px; }
.deploy-hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.deploy-hint code { background: var(--surface-subtle); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; color: var(--text); }
.deploy-controls { display: flex; align-items: center; gap: 12px; }
.deploy-controls .primary { min-width: 200px; }
.deploy-msg { margin: 12px 0 0; min-height: 16px; }

[hidden] { display: none !important; }

@media (max-width: 620px) {
  .topbar { padding: 0 16px; }
  .status { font-size: 0; }
  .role-label { display: none; }
  main { width: min(100% - 20px, 900px); margin: 18px auto; }
  .workspace { padding: 22px 16px; }
  .section-heading { margin-bottom: 22px; }
  .query-row { grid-template-columns: 1fr; }
  .query-actions { gap: 12px; }
  .query-actions .primary { min-width: 0; flex: 1; padding-left: 10px; padding-right: 10px; }
  .field-row { grid-template-columns: 1fr auto; gap: 7px; }
  .field-row dt { grid-column: 1 / -1; }
  .field-actions { align-self: start; }
  .result-head, .field-row, .result-actions { padding-left: 14px; padding-right: 14px; }
  .result-actions { flex-direction: column; }
  .result-actions > * { width: 100%; }
  .mailbox-head, .mailbox-controls, .mail-list { padding-left: 14px; padding-right: 14px; }
  .mailbox-controls { flex-wrap: wrap; }
  .mailbox-controls button { margin-left: 0; width: 100%; }
  .deploy-controls { flex-direction: column; }
  .deploy-controls .primary { width: 100%; min-width: 0; }
  .mail-card-head { display: block; }
  .mail-card-head time { display: block; margin-top: 5px; }
  .guest-links { padding-left: 14px; padding-right: 14px; }
  .guest-link-row { grid-template-columns: 1fr auto; }
  .guest-link-row span { grid-column: 1 / -1; }
  .guest-link-row .result-time { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
