:root {
  color-scheme: light;
  --paper: #f6f8fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e8ed;
  --line-strong: #d0d7de;
  --accent: #d52b1e;
  --accent-hover: #b92217;
  --accent-ring: rgba(213, 43, 30, 0.12);
  --error: #b91c1c;
  --success: #0f766e;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --font: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font: 14.5px/1.55 var(--font);
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 320px; margin: 0; }

button, input, select { font: inherit; }
a { color: var(--text); text-decoration: none; transition: color 0.12s ease; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1120px;
  min-height: 54px;
  margin: auto;
  padding: 8px 24px;
  gap: 16px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  text-decoration: none;
}

.wordmark img { display: block; max-width: 100%; height: auto; }
.wordmark span {
  padding-left: 10px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
}

.topbar nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13.5px;
}

.topbar nav a {
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--muted);
  font-weight: 500;
}

.topbar nav a:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

body[data-admin-embedded] .topbar-inner {
  justify-content: flex-end;
  min-height: unset;
}

body[data-admin-embedded] .topbar:not(:has(#sign-out:not([hidden]))) { display: none; }

.mail-admin .workspace {
  width: min(calc(100% - 40px), 1056px);
  margin-block: 22px 40px;
}

.mail-admin .page-heading {
  align-items: center;
  margin-bottom: 16px;
}

.mail-admin .section,
.mail-admin .access { border-radius: 10px; }

.mail-admin .account-actions { background: var(--surface-subtle); }

.mail-admin .section details + details { border-top-color: var(--line-strong); }

.mail-admin #all-mail { scroll-margin-top: 64px; }

.access {
  width: min(calc(100% - 32px), 400px);
  margin: clamp(32px, 10vh, 96px) auto 40px;
  padding: clamp(24px, 5vw, 34px);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

h1, h2, p { margin: 0; }
h1 {
  font-size: 1.45rem;
  font-weight: 650;
  line-height: 1.28;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  margin-bottom: 14px;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.access h1 { margin-bottom: 6px; }
.access > .field-note { margin-bottom: 4px; }
.access .form-stack { margin-top: 20px; }

.form-stack { display: grid; gap: 14px; width: min(100%, 380px); }
.form-stack label, .mail-filter label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 550;
  color: #334155;
}

.form-stack input, .form-stack select, .mail-filter select {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 400;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.form-stack input[readonly] {
  color: var(--muted);
  background: var(--surface-subtle);
  border-color: var(--line);
}

.form-stack input:focus, .form-stack select:focus, .mail-filter select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  outline: none;
}

.form-stack input::placeholder { color: #94a3b8; }
.field-note { color: var(--muted); font-size: 12.5px; line-height: 1.45; }

button[type="submit"], .button-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 16px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.access button[type="submit"] { width: 100%; margin-top: 4px; }
.button-link { margin-top: 16px; }
button[type="submit"]:hover:not(:disabled), .button-link:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

button:disabled { opacity: 0.52; cursor: not-allowed; }
[aria-busy="true"] button:disabled { cursor: wait; }

.text-button {
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: #334155;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.text-button:hover {
  background: var(--surface-subtle);
  border-color: var(--line-strong);
  color: var(--text);
}

.topbar .text-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
}

.topbar .text-button:hover {
  background: var(--surface-subtle);
  color: var(--accent);
}

.workspace {
  width: min(calc(100% - 48px), 1072px);
  margin: 28px auto 56px;
}

.page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 20px;
  margin-bottom: 20px;
}

.page-heading span {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.section {
  margin: 0 0 16px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.section:has(details) { padding-top: 2px; padding-bottom: 2px; }
.section details + details { border-top: 1px solid var(--line); }
.section details summary {
  padding: 13px 0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.section details summary:hover { color: var(--accent); }
.section details form { margin: 4px 0 18px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: start; }
th, td {
  padding: 10px 14px 10px 0;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: middle;
}

th {
  padding-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

td {
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

tbody tr:hover td { background: var(--surface-subtle); }
td:first-child { padding-left: 4px; overflow-wrap: anywhere; font-weight: 500; }
th:first-child { padding-left: 4px; }
td:last-child { padding-right: 4px; }
td:nth-child(n+2) { white-space: nowrap; color: #475569; }
tr:last-child td { border-bottom: 0; }

.status { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.status:empty { display: none; }
.status[data-kind="error"] { color: var(--error); }
.status[data-kind="success"] { color: var(--success); }
.page-status { width: min(calc(100% - 48px), 1072px); margin: 16px auto 0; }
.access .status { margin-top: 14px; }

.invite-result {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-subtle);
  font-size: 13px;
}

.invite-result code {
  display: block;
  margin: 6px 0 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
  user-select: all;
}

.mail-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.mail-filter label { min-width: min(210px, 100%); }
.mail-table { margin-top: 8px; }
.mail-table th:first-child { min-width: 140px; }
.mail-table td:nth-child(2) { max-width: 30ch; overflow: hidden; text-overflow: ellipsis; }

.mail-table .text-button {
  max-width: min(52vw, 52ch);
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  overflow-wrap: anywhere;
  text-align: start;
}

.mail-table .text-button:hover {
  background: transparent;
  color: var(--accent);
}

.mail-pages {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.mail-message {
  margin-top: 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-subtle);
}

.mail-message h3 {
  margin: 0 0 12px;
  font-size: 1.08rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.mail-meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}

.mail-meta dt { color: var(--muted); }
.mail-meta dd { margin: 0; overflow-wrap: anywhere; color: var(--text); }

.mail-message pre {
  margin: 14px 0 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mail-message .field-note { margin-top: 10px; }
.mail-message h4 { margin: 16px 0 8px; font-size: 12.5px; color: var(--muted); }
.mail-message ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mail-message ul li {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font-size: 12.5px;
}

.mail-message ul li a { color: var(--accent); font-weight: 500; }
.mail-message ul li a:hover { text-decoration: underline; }

@media (max-width: 560px) {
  .topbar-inner { padding-inline: 14px; }
  .topbar nav { gap: 4px 8px; }
  .workspace, .page-status { width: calc(100% - 28px); }
  .workspace { margin-top: 20px; }
  .section { padding: 15px 14px; }
  .mail-admin .workspace { width: calc(100% - 24px); margin-top: 12px; }
  .mail-admin .page-heading { gap: 8px; }
  .mail-admin .page-heading span { overflow-wrap: anywhere; }
  th, td { padding-right: 8px; }
  td { font-size: 13px; }
}
