:root {
  color-scheme: light;
  --ink: #22242b;
  --muted: #585d6a;
  --read: #6b7280;
  --accent: #007957;
  --soft: #eaf5ef;
  --highlight: #e0f1e9;
  --bg: #f5f7f9;
  --line: #e4e6ea;
  --deep: #eceef1;
  --danger: #a12a2a;
  font: 14px/1.5 "Microsoft YaHei UI", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; min-height: 510px; display: grid; grid-template-rows: auto auto minmax(300px, 1fr) auto; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: #fff; border: 1px solid #d7dade; border-radius: 9px; padding: 7px 12px; white-space: nowrap; }
button:hover { background: var(--highlight); }
button:disabled { cursor: default; opacity: .5; background: var(--deep); }
:focus-visible { outline: 2px solid #228d73; outline-offset: 2px; }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.primary:hover { background: #006d4e; }
.primary:disabled { color: var(--ink); border-color: var(--line); }
.danger { background: var(--danger); color: white; border-color: var(--danger); }
.danger:hover { background: #8a2020; }
.hero { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 28px; background: linear-gradient(110deg, #eaf4ef, #f3f8f6 65%, #e1efeb); }
.brand { display: flex; align-items: center; gap: 13px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(23px, 3vw, 30px); line-height: 1.2; }
.hero p, .totals, .toolbar p, .list-footer, .status { color: var(--muted); }
.hero p { margin-top: 4px; font-size: 12px; }
.totals { white-space: nowrap; font-size: 13px; }
.session-bar { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.session-bar .totals { margin-right: 8px; }
.session-bar button { font-size: 12px; }
.profile { position: relative; }
.profile-button { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 5px; background: #ffffffbf; }
.avatar { display: grid; place-items: center; width: 29px; height: 29px; flex: none; border-radius: 50%; background: var(--highlight); color: var(--accent); font-size: 14px; font-weight: 700; }
.account-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.profile-menu { position: absolute; right: 0; top: calc(100% + 7px); z-index: 3; width: 176px; background: white; border: 1px solid var(--line); border-radius: 11px; padding: 5px; box-shadow: 0 4px 14px #263b3326; }
.profile-menu button, .profile-menu a { display: block; text-align: left; width: 100%; border: 0; }
.profile-menu a { color: inherit; text-decoration: none; font-size: 12px; border-radius: 9px; padding: 7px 12px; }
.profile-menu a:hover { background: var(--highlight); }
.profile-menu button:last-child { border-top: 1px solid var(--line); color: var(--danger); }
.login-panel { display: none; }
.signed-out { grid-template-rows: auto minmax(350px, 1fr); }
.signed-out > :is(.tabbar, .workspace, .status), .signed-out .session-bar { display: none; }
.signed-out .login-panel { display: grid; place-items: start center; padding: clamp(20px, 10dvh, 100px) 16px 24px; }
.login-card { width: min(390px, 100%); padding: 26px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 30px #24393212; }
.login-card h2 { font-size: 22px; }
.login-card > p { margin-top: 6px; color: var(--muted); }
.login-card label, .settings label { display: block; margin: 13px 0 4px; color: var(--muted); }
.login-card input, .settings input { width: 100%; padding: 8px 11px; border: 1px solid #d7dade; border-radius: 8px; background: #fff; }
.login-card button { width: 100%; margin-top: 17px; }
.login-guide { display: block; margin-top: 13px; text-align: center; color: var(--accent); font-size: 13px; }
.settings { width: min(420px, calc(100vw - 32px)); }
.login-card .form-error, .form-error { color: var(--danger); margin-top: 9px; }
.api-keys { width: min(830px, calc(100vw - 32px)); max-height: 90dvh; }
.key-help { color: var(--muted); margin: 8px 0 14px; overflow-wrap: anywhere; }
#apiKeyForm { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
#apiKeyName, #issuedKeyValue { min-width: 0; padding: 7px 10px; background: white; border: 1px solid #d7dade; border-radius: 8px; }
#apiKeyName { flex: 1 1 135px; }
#apiKeyForm fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 7px; padding: 3px 8px 6px; margin: 0; }
#apiKeyForm legend { color: var(--muted); font-size: 11px; }
#apiKeyForm input[type="checkbox"] { accent-color: var(--accent); }
.issued-key { margin-top: 12px; padding: 10px; background: var(--soft); border-radius: 9px; }
.issued-key div { display: flex; gap: 7px; align-items: center; margin: 6px 0; }
#issuedKeyValue { flex: 1; font-family: ui-monospace, Consolas, monospace; }
.key-scroll { margin-top: 13px; max-height: 40dvh; overflow: auto; background: white; border-radius: 8px; }
.key-scroll table { min-width: 640px; }
.key-scroll td { overflow-wrap: anywhere; }
.key-scroll td:first-child, .key-scroll td:nth-child(3) { width: 20%; }
.tabbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 7px; padding: 9px 20px 12px; }
.primary-tabs, .mailbox-tabs, .tab-nav { display: flex; align-items: center; gap: 7px; }
.mailbox-tabs { overflow: auto hidden; scrollbar-width: none; }
.mailbox-tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; height: 39px; border-radius: 11px; background: var(--deep); }
.primary-tabs .tab { width: 142px; }
.mailbox-tabs .tab { display: flex; align-items: center; flex: 0 0 302px; width: 302px; min-width: 0; }
.tab-button { flex: 1; text-align: left; min-width: 0; height: 100%; overflow: hidden; text-overflow: ellipsis; padding: 0 15px; border: 0; border-radius: 11px; background: transparent; }
.primary-tabs .tab-button { width: 100%; }
.tab.active { background: white; color: var(--accent); }
.tab.active::after { content: ""; position: absolute; height: 3px; inset: auto 16px 1px; background: var(--accent); pointer-events: none; }
.tab-close { padding: 0; width: 29px; height: 28px; margin-right: 6px; border: 0; background: transparent; color: var(--muted); }
.tab-nav { background: var(--bg); }
.icon-button { width: 28px; height: 28px; display: inline-grid; place-items: center; vertical-align: middle; border: 0; padding: 0; color: var(--accent); background: var(--soft); border-radius: 7px; }
.icon-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.45; stroke-linejoin: round; stroke-linecap: round; }
.workspace { display: grid; grid-template-rows: auto minmax(230px, 1fr) auto; margin: 0 20px 13px; background: white; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 19px; min-height: 88px; }
.heading { min-width: 0; }
.heading-line { display: flex; align-items: center; gap: 12px; }
.heading-line h2 { font-size: 19px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heading-line h2.mailbox { font-size: 16px; }
#headingCopy { flex: none; }
.toolbar p { font-size: 12px; margin-top: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar p.failure { color: var(--danger); }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }
input[type="search"] { width: min(25vw, 236px); min-width: 112px; background: white; border: 1px solid #d7dade; border-radius: 9px; padding: 8px 12px; }
input::placeholder { color: var(--muted); opacity: 1; }
.table-scroll { overflow: auto; scrollbar-color: #b8cac2 transparent; min-height: 0; }
table { border-spacing: 0; width: 100%; table-layout: fixed; min-width: 740px; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; text-align: left; background: #eff1f4; color: var(--muted); font-weight: 500; height: 43px; padding: 0 16px; }
td { border-bottom: 1px solid var(--line); height: 48px; padding: 0 16px; }
tbody tr:nth-child(even) { background: #f9fbfa; }
tbody tr:hover { background: #f0f8f4; }
tbody tr.selected { background: var(--highlight); }
tbody tr.selected td:first-child { box-shadow: inset 3px 0 var(--accent); }
tbody tr.read { color: var(--read); font-weight: 400; }
tbody tr.unread { color: #202127; font-weight: 550; }
.cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell .value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell .icon-button { margin-left: auto; flex: none; }
.keyword { background: var(--soft); border-radius: 6px; padding: 3px 6px; }
.center { text-align: center; }
.good { color: var(--accent); }
.failure { color: var(--danger); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 16px; font-size: 12px; }
.pager { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pager span { margin: 0 8px; }
.status { background: var(--deep); padding: 10px 20px; font-size: 12px; min-height: 38px; }
.context-menu { position: fixed; z-index: 2; min-width: 186px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 4px 14px #263b3326; }
.context-menu button { display: block; width: 100%; text-align: left; border: 0; }
.context-menu hr { border: 0; border-top: 1px solid var(--line); }
.context-menu .delete-menu { color: var(--danger); }
dialog { color: var(--ink); border: 1px solid #d6ddda; border-radius: 12px; padding: 20px; background: var(--bg); box-shadow: 0 4px 16px #1d2d3540; }
dialog::backdrop { background: #22332b40; }
dialog h2 { font-size: 19px; overflow-wrap: anywhere; }
dialog header, dialog footer { display: flex; align-items: center; gap: 10px; }
dialog header { justify-content: space-between; }
dialog footer { justify-content: flex-end; padding-top: 13px; }
.detail { width: min(960px, calc(100vw - 32px)); max-height: 90dvh; }
dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 5px 12px; }
dt { color: var(--muted); }
dd { margin: 0; padding: 5px 9px; border: 1px solid var(--line); background: white; border-radius: 7px; overflow-wrap: anywhere; user-select: text; }
.detail-tabs { display: flex; gap: 7px; margin-bottom: 8px; }
.detail-tabs .active { background: var(--highlight); color: var(--accent); }
#mailBody { display: block; width: 100%; height: clamp(120px, 39dvh, 460px); resize: none; border-radius: 8px; border: 1px solid var(--line); padding: 11px; background: #fff; white-space: pre-wrap; }
#mailBody.source { font-family: ui-monospace, Consolas, monospace; white-space: pre; }
.confirm { max-width: min(400px, calc(100vw - 32px)); }
.confirm p { margin-top: 10px; }
@media (max-width: 760px) {
  .hero { padding: 14px; }
  .tabbar { padding-inline: 10px; }
  .primary-tabs .tab { width: 91px; }
  .tab-button { padding-inline: 9px; }
  .workspace { margin-inline: 10px; }
  .toolbar { flex-wrap: wrap; padding: 12px; }
  .heading, .actions { flex: 1 1 100%; }
  .actions input { flex: 1; min-width: 70px; }
  .list-footer { flex-wrap: wrap; }
  .pager { flex-wrap: wrap; }
}
