/*
 * 域名邮箱 Dashboard —— 沿用 .api 调度中心的 achromatic-ledger 风格:
 * 界面本身不带颜色,唯一色相 --accent-hue 只用于品牌点与未读标记,状态用语义色。
 */
:root {
  color-scheme: light dark;
  --ground: #f2f4f7; --surface: #ffffff; --raised: #eceef2; --active: #e4e7ec;
  --border: #e1e4e9; --rule: #eceef1; --control: #c9cdd4;
  --text: #0e1116; --muted: #5a6068; --faint: #666c75;
  --primary: #14171c; --primary-hover: #2b3038; --on-primary: #ffffff;
  --accent-hue: #1d5fbf;
  --negative: #c4242a;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-warning-bg: #fff3d6;  --pill-warning-ink: #7a3a08;
  --pill-negative-bg: #ffe9e7; --pill-negative-ink: #831c1e;
  --pill-neutral-bg: #eceef2;  --pill-neutral-ink: #3d424a;
  --radius-card: 8px; --radius-control: 6px;
  --gap: 12px; --pad: 28px; --control-height: 36px; --row-height: 52px; --sidebar-width: 224px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0c0c0d; --surface: #151516; --raised: #1f1f21; --active: #262629;
    --border: #27272a; --rule: #1e1e20; --control: #3c3c41;
    --text: #f3f3f4; --muted: #a6a6ad; --faint: #94949b;
    --primary: #f3f3f4; --primary-hover: #d9d9dc; --on-primary: #0c0c0d;
    --accent-hue: #6ea3f2; --negative: #f2737c;
    --pill-positive-bg: #14291c; --pill-positive-ink: #66d393;
    --pill-warning-bg: #2f2410;  --pill-warning-ink: #f0be6b;
    --pill-negative-bg: #2e181c; --pill-negative-ink: #f58a92;
    --pill-neutral-bg: #232326;  --pill-neutral-ink: #c4c4ca;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--text); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; line-height: 32px; } h2 { font-size: 16px; line-height: 24px; }
p { margin: 0; }
.muted { color: var(--muted); } .center { text-align: center; padding: 40px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono, code { font-family: var(--font-mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.shell:has(#tabs[hidden]) { grid-template-columns: minmax(0, 1fr); }
.shell:has(#tabs[hidden]) .side { display: none; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 12px 16px; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.mark { flex: none; color: var(--text); } .mark-dot { fill: var(--accent-hue); }
.brand-name { font-weight: 600; line-height: 18px; } .brand-scope { font-size: 12px; color: var(--muted); line-height: 16px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; margin-top: 24px; }
nav button { width: 100%; height: 34px; justify-content: flex-start; padding: 0 10px; border: 0; background: transparent; color: var(--muted); font-weight: 400; }
nav button:hover { background: var(--raised); color: var(--text); }
nav button.active { background: var(--active); color: var(--text); }
nav svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
nav .nav-quiet { margin-top: auto; }

main { min-width: 0; padding: 36px var(--pad) 64px; max-width: 1320px; width: 100%; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.title-actions { display: flex; gap: 8px; }
.sub { color: var(--muted); margin-top: 2px; min-height: 21px; }

button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-height); padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius-control); font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer; transition: background-color .15s, border-color .15s, color .15s, transform .06s; }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary { background: var(--primary); color: var(--on-primary); }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button.ghost { background: transparent; color: var(--text); border-color: var(--control); }
button.ghost:hover:not(:disabled) { background: var(--raised); }
button.danger { background: transparent; color: var(--negative); border-color: var(--control); }
button.danger:hover:not(:disabled) { border-color: var(--negative); background: var(--pill-negative-bg); }
button.small { height: 30px; padding: 0 10px; font-size: 13px; }
button.block { width: 100%; }
button:disabled, button[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
button[aria-busy="true"]::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

label { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; min-height: 32px; font-weight: 400; }
input, select, textarea { width: 100%; height: var(--control-height); padding: 0 10px; background: var(--surface); color: var(--text); border: 1px solid var(--control); border-radius: var(--radius-control); font: 400 14px/1.4 var(--font); transition: border-color .15s; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
select { width: auto; padding-right: 28px; }
dialog select { width: 100%; }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:user-invalid { border-color: var(--negative); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); }
input[type="file"] { height: auto; padding: 6px 8px; }
.field-hint { font-size: 12px; font-weight: 400; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.checks { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.error { min-height: 1.4em; margin-top: 8px; font-size: 13px; color: var(--negative); }
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); }

#login-form { max-width: 380px; margin: 14vh auto 0; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
#login-form button { margin-top: 16px; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 8px 12px; text-align: left; white-space: nowrap; font-size: 12px; font-weight: 400; color: var(--muted); border-bottom: 1px solid var(--control); }
td { height: var(--row-height); padding: 6px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr { transition: background-color .12s; }
tbody tr:hover { background: color-mix(in srgb, var(--text) 3.5%, transparent); }
td.muted { color: var(--muted); }
td.actions-cell { text-align: right; white-space: nowrap; }
td.actions-cell button + button { margin-left: 6px; }
td strong { font-weight: 500; }
.dash { color: var(--muted); }
.stack { min-width: 760px; }

.badge { display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }
.badge.ok, .badge.warn, .badge.bad { padding-left: 7px; }
.badge.ok::before, .badge.warn::before, .badge.bad::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.badge.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.badge.bad { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }

td.state { height: auto; padding: 20px 0; border-bottom: 0; }
.state-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--control); border-radius: var(--radius-card); }
.state-box.is-error { color: var(--text); }
.skel { display: block; height: 12px; border-radius: 4px; background: var(--raised); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* 邮件:左列表 + 右详情 */
.mail { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.mail-list, .mail-detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.mail-list { padding: 4px 0 0; overflow: hidden; }
.msgs { list-style: none; margin: 0; padding: 0; }
.msgs li button { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 12px 16px 12px 22px; cursor: pointer; border-bottom: 1px solid var(--rule); position: relative; }
.msgs li button:hover { background: var(--raised); }
.msgs li button:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.msgs li.sel button { background: var(--active); }
.msgs li.unread button::before { content: ""; position: absolute; left: 9px; top: 20px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-hue); }
.m-top { display: flex; justify-content: space-between; gap: 8px; }
.m-from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .m-from, .unread .m-subj { font-weight: 600; }
.m-time { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-subj, .m-snip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-snip, .m-box { color: var(--muted); font-size: 13px; }
.mail-list > button { margin: 12px; width: calc(100% - 24px); }
.mail-detail { padding: 20px 24px; min-height: 320px; }
.d-head { border-bottom: 1px solid var(--rule); padding-bottom: 14px; margin-bottom: 14px; }
.d-head h2 { font-size: 18px; line-height: 26px; margin-bottom: 8px; word-break: break-word; }
.d-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; color: var(--muted); font-size: 13px; }
.d-meta dd { margin: 0; color: var(--text); word-break: break-all; } .d-meta dt { text-align: right; }
.d-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.d-body { white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.d-frame { width: 100%; height: 480px; border: 1px solid var(--border); border-radius: var(--radius-control); background: #fff; }
.atts { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.att { padding: 4px 10px; border: 1px solid var(--control); border-radius: var(--radius-control); font-size: 13px; }

/* 接入指引 */
.guide h2 { margin-bottom: 4px; }
.steps { margin: 12px 0; padding-left: 20px; } .steps li { margin: 6px 0; }
.rec { width: 100%; margin: 8px 0; min-width: 0; }
.rec td, .rec th { padding: 6px 8px; height: auto; vertical-align: top; }
.rec td:nth-child(-n+2) { white-space: nowrap; }
.rec td:last-child { overflow-wrap: anywhere; }
.checkline { display: flex; align-items: center; gap: 8px; margin: 4px 0; }

dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: 0 12px 40px rgba(0,0,0,.22); }
dialog.wide { width: min(680px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(8,10,14,.5); }
dialog h2 { font-size: 18px; margin-bottom: 2px; }
dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#token-secret { margin-top: 12px; } #token-secret p { margin-bottom: 8px; }
#token-secret code { display: block; padding: 12px; word-break: break-all; user-select: all; background: var(--ground); border: 1px solid var(--control); border-radius: var(--radius-control); }

#toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--radius-control); background: var(--text); color: var(--ground); box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transform: translate(-50%, 8px); pointer-events: none; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) { :root { --sidebar-width: 190px; --pad: 20px; } .mail { grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); } }
@media (max-width: 860px) {
  .shell, .shell:has(#tabs[hidden]) { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .side { position: sticky; top: 0; z-index: 5; height: 48px; flex-direction: row; align-items: center; padding: 0 8px 0 16px; background: var(--ground); border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; } .brand-scope { display: none; }
  nav { flex-direction: row; justify-content: flex-end; margin: 0; gap: 0; }
  nav button { width: auto; height: 44px; padding: 0 10px; } nav svg { display: none; } nav .nav-quiet { margin: 0; }
  main { padding: 20px 16px 48px; } h1 { font-size: 22px; }
  .brand-name { display: none; }
  .mail { grid-template-columns: minmax(0, 1fr); }
  .row2 { grid-template-columns: 1fr; }
  button.small { height: 40px; padding: 0 14px; } input, select { height: 44px; }
  .table-wrap { overflow: visible; } .stack { min-width: 0; }
  .stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stack, .stack tbody { display: block; }
  .stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; padding: 14px 4px; border-bottom: 1px solid var(--rule); }
  .stack tbody tr:hover { background: none; }
  .stack td { display: block; min-width: 0; height: auto; padding: 0; border: 0; text-align: left; }
  .stack td::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }
  .stack td:not([data-label])::before { display: none; }
  .stack td:first-child, .stack td.wide, .stack td.actions-cell, .stack td.state { grid-column: 1 / -1; }
  .stack td.actions-cell { display: flex; flex-wrap: wrap; gap: 8px; } .stack td.actions-cell button + button { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* 模板 */
textarea.mono { font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }
#template-preview-frame { width: 100%; height: 280px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
#tpl-vars { display: grid; gap: 8px; }
