:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --text: #18202a;
  --text-soft: #4b5563;
  --text-muted: #6b7280;
  --border: #d7dde5;
  --border-soft: #e7ebf0;
  --brand: #147c74;
  --brand-weak: #e7f3f1;
  --brand-hover: #106961;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --radius: 8px;
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

button {
  border-radius: 6px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel,
.inbox {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  position: sticky;
  top: 16px;
  padding: 20px;
}

.mark,
.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0;
  text-wrap: balance;
}

h1::before,
h2::before {
  content: "";
  width: 4px;
  height: 1.05em;
  border-radius: 4px;
  background: var(--brand);
  flex: 0 0 auto;
}

h1 {
  margin-top: 8px;
  font-size: 23px;
  line-height: 1.25;
}

h2 {
  margin-top: 2px;
  font-size: 18px;
  line-height: 1.35;
}

.lede {
  margin-top: 8px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.45;
}

.redeem-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-size: 13px;
  user-select: none;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand);
}

.login-hint {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-size: 13px;
}

.form-hint {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-size: 12px;
}

.redeem-form label,
.address-card .label,
dt,
th {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

input::placeholder,
textarea::placeholder {
  color: #7b8491;
}

input {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 136px;
  padding: 10px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(20, 124, 116, 0.14);
}

select {
  height: 38px;
  padding: 0 28px 0 10px;
}

.address-card {
  position: relative;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.address-card .label {
  display: block;
}

.address-card strong {
  display: block;
  margin-top: 4px;
  min-height: 30px;
  padding-right: 46px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 600;
}

.copy-hint {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface);
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
}

.copy-hint.error {
  border-color: #fecdca;
  background: #fef3f2;
  color: var(--danger);
}

.copy {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--brand);
  cursor: pointer;
}

.copy:hover,
.actions .secondary:hover,
.small-button:hover {
  border-color: var(--brand);
  background: var(--brand-weak);
}

.copy.is-success {
  border-color: var(--brand);
  background: var(--brand-weak);
  color: var(--brand);
}

.copy.is-error {
  border-color: var(--danger);
  background: #fef3f2;
  color: var(--danger);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.actions button,
.redeem-form button,
.small-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.actions button:hover,
.redeem-form button:hover {
  border-color: var(--brand-hover);
  background: var(--brand-hover);
}

.actions .secondary {
  background: var(--surface);
  color: var(--brand);
}

.secondary-button,
.redeem-form .secondary-button {
  background: var(--surface);
  color: var(--brand);
}

.danger-button {
  border-color: #fecdca;
  background: var(--surface);
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
  background: #fef3f2;
}

button:disabled,
.small-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.meta {
  display: grid;
  gap: 0;
  margin: 14px 0 0;
  border-top: 1px solid var(--border-soft);
}

.meta div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
  color: var(--text-soft);
}

.error {
  color: var(--danger);
}

.local-records {
  margin-top: 14px;
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
}

.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.records-head h2 {
  font-size: 15px;
}

.records-head button,
.record-remove {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 12px;
}

.records-head button:hover,
.record-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.records-empty {
  margin-top: 10px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 13px;
  text-align: center;
}

.records-list {
  display: grid;
  margin-top: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  overflow: hidden;
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}

.record-item:last-child {
  border-bottom: 0;
}

.record-item.active {
  background: var(--brand-weak);
}

.record-select {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.record-main {
  min-width: 0;
}

.record-select:hover {
  background: rgba(20, 124, 116, 0.08);
}

.record-select span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
}

.record-select em {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  color: var(--brand);
  background: var(--brand-weak);
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
}

.record-select small {
  color: var(--text-muted);
  font-size: 12px;
}

.record-meta {
  display: block;
  padding: 0 10px 10px;
  color: var(--text-muted);
  font-size: 11px;
}

.record-remove {
  margin-right: 8px;
}

.inbox {
  min-height: calc(100vh - 48px);
  overflow: hidden;
}

.inbox-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}

.count {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 18px;
  color: var(--text-muted);
  text-align: center;
}

.empty[hidden] {
  display: none;
}

.empty span {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.empty p {
  margin-top: 12px;
  font-size: 13px;
}

.admin-empty {
  min-height: 140px;
}

.mail-list {
  display: grid;
}

.mail {
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}

.mail:last-child {
  border-bottom: 0;
}

.mail-summary {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 120px;
  gap: 14px;
  align-items: center;
  border: 0;
  border-radius: 0;
  padding: 11px 18px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.mail-summary:hover {
  background: var(--surface-muted);
}

.subject {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sender,
time {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

time {
  text-align: right;
  font-size: 13px;
}

.mail-body {
  display: none;
  padding: 0 18px 16px;
}

.mail.open .mail-body {
  display: block;
}

iframe,
pre {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

pre {
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-soft);
}

.admin-shell {
  width: min(1320px, calc(100vw - 32px));
}

.admin-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.admin-table-wrap {
  overflow: hidden;
}

.admin-search {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 120px minmax(120px, 160px) auto auto auto auto;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-muted);
}

.bulk-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
}

.filter-summary {
  padding: 9px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
}

.filter-summary.active {
  color: var(--brand);
  font-weight: 600;
}

.ad-slot {
  padding: 9px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: #f8fbfa;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.45;
}

.ad-slot a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}

.ad-slot a:hover {
  text-decoration: underline;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--border-soft);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

td {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td:last-child {
  max-width: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 190px;
}

.empty-row td,
.empty-row td:last-child {
  display: table-cell;
  max-width: none;
  padding: 28px 18px;
  color: var(--text-muted);
  text-align: center;
  white-space: normal;
}

tbody tr.redeemed {
  background: #f8fbfa;
}

tbody tr.disabled {
  color: var(--text-muted);
}

tbody tr.redeemed td:nth-child(3) {
  color: var(--brand);
  font-weight: 600;
}

th {
  background: var(--surface-muted);
}

.select-column {
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  text-align: center;
}

.select-column input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.code-cell {
  font-family: var(--mono);
  font-size: 13px;
}

.admin-inbox {
  border-top: 1px solid var(--border);
}

.compact {
  padding-top: 14px;
  padding-bottom: 14px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
}

.pagination span {
  color: var(--text-soft);
  font-size: 13px;
}

.ops-panel {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.compact-meta {
  margin-top: 10px;
}

.compact-form {
  margin-top: 10px;
}

.compact-table {
  margin-top: 10px;
  border: 1px solid var(--border-soft);
}

.compact-table th,
.compact-table td {
  padding: 8px 10px;
  font-size: 12px;
}

.compact-table td:last-child {
  display: table-cell;
  min-width: 0;
  max-width: 180px;
}

.full-button {
  width: 100%;
  margin-top: 10px;
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 20px, 680px);
    padding: 10px 0;
  }

  .workspace,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
  }

  h1 {
    font-size: 22px;
  }

  .mail-summary {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  time {
    text-align: left;
  }

  .admin-search {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
