:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #18202a;
  --muted: #657180;
  --line: #dce1e7;
  --primary: #176b4d;
  --primary-hover: #10573e;
  --accent: #be7a16;
  --danger: #b42318;
  --success-bg: #e8f5ef;
  --queued-bg: #fff4db;
  --running-bg: #e7f0fb;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input { font: inherit; letter-spacing: 0; }
select { min-height: 38px; border: 1px solid #aeb7c2; border-radius: 6px; padding: 0 10px; background: white; color: var(--text); font: inherit; }
button { min-height: 42px; border: 1px solid var(--primary); border-radius: 6px; padding: 0 18px; background: var(--primary); color: white; cursor: pointer; font-weight: 650; white-space: nowrap; }
button:hover { background: var(--primary-hover); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.secondary { background: white; color: var(--text); border-color: #aeb7c2; }
button.secondary:hover { background: #f2f4f6; }
button.text-button { min-height: 32px; padding: 0 8px; background: transparent; color: var(--primary); border: 0; }
input:not([type="file"]) { width: 100%; min-height: 46px; border: 1px solid #aeb7c2; border-radius: 6px; padding: 0 13px; background: white; color: var(--text); }
input:focus { outline: 3px solid rgba(23, 107, 77, .16); border-color: var(--primary); }
label { display: block; margin: 24px 0 8px; font-size: 14px; font-weight: 650; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: 28px; line-height: 1.25; letter-spacing: 0; }
h2 { margin-bottom: 6px; font-size: 18px; letter-spacing: 0; }
.brand { color: var(--primary); font-size: 13px; font-weight: 800; text-transform: uppercase; margin-bottom: 14px; }
.subtle { color: var(--muted); line-height: 1.6; }
.error { min-height: 20px; color: var(--danger); font-size: 14px; }
.hidden { display: none !important; }
.button-row, .inline-actions, .upload-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row { margin-top: 14px; }
.button-row button { flex: 1; }
.user-shell { width: min(680px, calc(100% - 32px)); margin: 0 auto; padding: 9vh 0 48px; }
.tool-panel { padding: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 12px 34px rgba(20, 29, 40, .07); }
.status-panel { margin-top: 20px; padding: 16px; border-left: 4px solid var(--primary); background: #f0f5f3; }
.status-panel strong { display: block; margin-bottom: 5px; }
.history-section { margin-top: 38px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.history-list { border-top: 1px solid var(--line); }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 15px 2px; border-bottom: 1px solid var(--line); }
.history-item strong, .history-item span { overflow-wrap: anywhere; }
.history-item .meta { margin-top: 5px; color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.badge-unused { background: #edf0f3; color: #4d5967; }
.badge-ready { background: var(--success-bg); color: #146c4a; }
.admin-page .badge-ready { background: var(--queued-bg); color: var(--accent); }
.badge-queued { background: var(--queued-bg); color: #805300; }
.badge-running { background: var(--running-bg); color: #185690; }
.badge-success { background: var(--success-bg); color: #146c4a; }
.badge-failed { background: #fdecea; color: var(--danger); }
.badge-token_invalid, .badge-quota_exhausted { background: #fdecea; color: var(--danger); }
dialog { width: min(480px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; box-shadow: 0 24px 80px rgba(13, 20, 28, .26); }
dialog::backdrop { background: rgba(20, 28, 37, .5); }
.dialog-body { padding: 28px; }
.dialog-label { color: var(--muted); font-size: 13px; }
#dialog-email { display: block; margin: 8px 0 16px; font-size: 20px; overflow-wrap: anywhere; }
.import-dialog { width: min(760px, calc(100% - 32px)); }
.result-dialog { width: min(760px, calc(100% - 32px)); }
.mailbox-dialog { width: min(1100px, calc(100% - 24px)); max-height: min(88vh, 900px); }
.import-dialog progress { width: 100%; height: 12px; margin-bottom: 18px; accent-color: var(--primary); }
.import-items { max-height: min(48vh, 420px); overflow: auto; border-top: 1px solid var(--line); }
.import-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 13px 2px; border-bottom: 1px solid var(--line); }
.import-item strong, .import-item span { overflow-wrap: anywhere; }
.import-item .meta { margin-top: 4px; color: var(--muted); font-size: 13px; }
.import-item-valid { color: #146c4a; }
.import-item-temporary { color: var(--accent); }
.import-item-invalid { color: var(--danger); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.admin-shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 60px; }
.admin-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 28px; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(400px, 100%); padding: 30px; background: white; border: 1px solid var(--line); border-radius: 8px; }
.login-panel button { width: 100%; margin-top: 16px; }
.upload-band, .result-band { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 22px 0; border-top: 1px solid var(--line); }
.result-band { display: block; }
.upload-actions { align-items: center; justify-content: flex-end; }
.settings-actions { align-items: center; }
.settings-actions label { margin: 0; }
.settings-actions input { width: min(280px, 100%); min-height: 38px; }
.mailbox-table-wrap { margin-top: 14px; }
#back-to-mailbox { margin-bottom: 14px; }
.mailbox-table-wrap { overflow: hidden; }
.mailbox-table { table-layout: fixed; }
.mailbox-table th, .mailbox-table td { white-space: normal; overflow-wrap: anywhere; }
.mailbox-summary-column { width: 55%; }
.mailbox-date-column { width: 28%; }
.mailbox-action-column { width: 17%; }
.mailbox-summary { display: grid; gap: 4px; }
.mailbox-summary .mailbox-from { color: var(--text); font-weight: 650; }
.mailbox-summary .mailbox-subject { color: var(--muted); font-size: 12px; line-height: 1.45; }
.mailbox-message-content { display: block; width: 100%; min-height: min(58vh, 620px); border: 1px solid var(--line); background: white; }
pre { margin: 0; padding: 16px; max-height: 260px; overflow: auto; border: 1px solid var(--line); background: white; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.records-section { padding-top: 26px; border-top: 1px solid var(--line); }
.search-bar { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.search-actions { display: flex; flex: 1; gap: 10px; }
.search-actions input { flex: 1 1 320px; min-width: 220px; max-width: 640px; }
.search-bar select { min-width: 128px; padding-right: 30px; }
.search-actions button { flex: none; }
.table-wrap { overflow: auto; border: 1px solid var(--line); background: white; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.pagination label { margin: 0; }
.pagination button { min-height: 38px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #eef1f4; color: #4a5664; font-size: 12px; }
.cdk-cell { display: flex; align-items: center; gap: 8px; }
td.error-cell { max-width: 320px; white-space: normal; color: var(--danger); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(480px, calc(100% - 48px)); padding: 14px 18px; border: 1px solid; border-radius: 6px; box-shadow: 0 10px 34px rgba(20, 29, 40, .2); font-size: 14px; font-weight: 700; }
.toast-success { color: #0f5f40; background: #e5f5ed; border-color: #78bea0; }
.toast-error { color: var(--danger); background: #fdecea; border-color: #efaaa3; }

@media (max-width: 720px) {
  .user-shell { padding-top: 28px; }
  .tool-panel { padding: 24px 20px; }
  h1 { font-size: 24px; }
  .admin-shell { width: min(100% - 24px, 1440px); padding-top: 22px; }
  .admin-header, .upload-band { align-items: stretch; flex-direction: column; }
  .upload-actions { justify-content: flex-start; }
  .search-bar, .search-actions { flex-wrap: wrap; }
  .search-actions { flex-basis: 100%; }
  .search-actions input { flex-basis: 100%; }
  .pagination { justify-content: flex-start; }
  .button-row button { flex-basis: 100%; }
}
