:root {
  color-scheme: light;
  --page: #f5f7f7;
  --surface: #ffffff;
  --surface-soft: #f0f3f2;
  --surface-hover: #e9efed;
  --line: #dce3e0;
  --line-strong: #c8d3cf;
  --text: #202624;
  --muted: #68736f;
  --muted-2: #929c98;
  --accent: #16745f;
  --accent-soft: #e0f0eb;
  --accent-strong: #0f5848;
  --danger: #b34343;
  --danger-soft: #f8e9e7;
  --warning: #9a6418;
  --warning-soft: #fff3d9;
  --shadow: 0 14px 34px rgba(32, 52, 45, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #171b1d;
  --surface: #202628;
  --surface-soft: #272e30;
  --surface-hover: #30393a;
  --line: #374143;
  --line-strong: #4a5758;
  --text: #eef2f0;
  --muted: #a3aeaa;
  --muted-2: #76817d;
  --accent: #62c8aa;
  --accent-soft: #1d4439;
  --accent-strong: #8be0c6;
  --danger: #f08b86;
  --danger-soft: #4a2b2b;
  --warning: #efbd67;
  --warning-soft: #493b25;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--page); color: var(--text); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg { display: block; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  grid-template-columns: repeat(3, 4px);
  place-content: center;
  gap: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--text);
}

.brand-mark span { width: 4px; height: 16px; border-radius: 2px; background: var(--surface); }
.brand-mark span:nth-child(2) { height: 22px; }
.brand-mark span:nth-child(3) { height: 11px; }

.btn, .icon-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  color: inherit;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.btn.compact { min-height: 32px; padding: 5px 10px; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { border-color: var(--line); background: var(--surface); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.btn:disabled { cursor: not-allowed; opacity: 0.48; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  text-decoration: none;
  flex: 0 0 auto;
}

.icon-btn:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background-color: var(--page);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 42px 42px;
}

.login-panel {
  width: min(100%, 390px);
  padding: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand, .topbar-brand, .topbar-left, .topbar-actions, .login-status,
.mail-controls, .provider-label, .security-status, .copy-inline, .privacy-chip,
.detail-actions, .privacy-note, .attachment-section h3 {
  display: flex;
  align-items: center;
}

.login-brand { gap: 10px; margin-bottom: 38px; }
.login-brand strong, .topbar-brand strong { display: block; font-size: 14px; }
.login-brand small, .topbar-brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }
.login-copy { margin-bottom: 22px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 750; }
.login-copy h1 { margin: 5px 0 0; font-size: 25px; }
.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.field input { height: 40px; padding: 0 11px; }
.field textarea { min-height: 190px; resize: vertical; padding: 11px; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px var(--accent-soft); }
.login-submit { width: 100%; margin-top: 14px; }
.form-error { margin: 9px 0 0; color: var(--danger); font-size: 12px; }
.login-status { gap: 6px; margin: 18px 0 0; color: var(--muted-2); font-size: 11px; }

.app-shell { height: 100vh; display: grid; grid-template-rows: 54px minmax(0, 1fr); overflow: hidden; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-left, .topbar-actions { gap: 8px; min-width: 0; }
.topbar-brand { gap: 9px; }
.topbar-brand .brand-mark { width: 31px; height: 31px; }
.security-status { gap: 5px; margin-right: 5px; color: var(--accent); font-size: 11px; white-space: nowrap; }
.menu-btn { display: none; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(330px, 390px) minmax(420px, 1fr);
  overflow: hidden;
}

.account-pane, .message-pane, .detail-pane { min-width: 0; min-height: 0; background: var(--surface); }
.account-pane, .message-pane { border-right: 1px solid var(--line); }
.account-pane { display: grid; grid-template-rows: 58px 45px minmax(0, 1fr) auto; }

.account-head, .mail-toolbar, .detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.account-head { padding: 10px 12px; }
.account-head h2 { margin: 0; font-size: 14px; }
.account-head span { color: var(--muted); font-size: 11px; }
.account-search, .search-control, .select-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  background: var(--surface-soft);
}
.account-search { height: 32px; margin: 6px 9px 7px; padding: 0 9px; border: 1px solid transparent; border-radius: 6px; }
.account-search:focus-within { border-color: var(--accent); background: var(--surface); }
.account-search input, .search-control input {
  width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12px;
}
.account-list { min-height: 0; overflow: auto; padding: 3px 7px 10px; }
.account-row {
  width: 100%; min-height: 55px; display: grid; grid-template-columns: 29px minmax(0, 1fr) auto;
  align-items: center; gap: 8px; margin-bottom: 2px; padding: 7px 8px;
  border: 1px solid transparent; border-radius: 6px; background: transparent; color: inherit; text-align: left; cursor: pointer;
}
.account-row:hover { background: var(--surface-soft); }
.account-row.active { border-color: var(--line-strong); background: var(--accent-soft); }
.account-provider { width: 29px; height: 29px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); }
.account-row.active .account-provider { border-color: var(--accent); color: var(--accent); }
.account-copy { min-width: 0; }
.account-copy strong, .account-copy small { display: flex; align-items: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 12px; }
.account-copy small { gap: 5px; margin-top: 4px; color: var(--muted); font-size: 10px; }
.state-dot { width: 6px; height: 6px; flex: 0 0 auto; border-radius: 50%; background: var(--muted-2); }
.state-dot.online { background: #2d9d73; }
.state-dot.error { background: var(--danger); }
.state-dot.paused { background: var(--warning); }
.count-badge { min-width: 19px; height: 19px; display: grid; place-items: center; padding: 0 5px; border-radius: 10px; background: var(--accent); color: white; font-size: 10px; font-weight: 750; }
.account-empty { padding: 24px 10px; color: var(--muted); font-size: 12px; text-align: center; }
.account-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 9px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.account-footer .btn { min-width: 0; padding: 6px 5px; font-size: 11px; }

.message-pane { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.mail-toolbar { min-height: 94px; align-items: flex-start; flex-direction: column; padding: 8px 10px 8px 13px; }
.mailbox-heading { min-width: 0; }
.mailbox-heading h2 { max-width: 260px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.copy-inline { max-width: 260px; gap: 4px; margin-top: 4px; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; }
.copy-inline span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-controls { width: 100%; flex-wrap: wrap; justify-content: flex-start; gap: 6px; }
.provider-label { gap: 5px; color: var(--muted); font-size: 11px; }
.segmented { height: 32px; display: grid; grid-template-columns: 1fr 1fr; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.segmented button { min-width: 54px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(30, 45, 40, 0.12); }
.select-control { height: 32px; padding: 0 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.select-control select { max-width: 105px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 11px; }
.account-error { display: flex; align-items: flex-start; gap: 7px; padding: 8px 12px; border-bottom: 1px solid #f0c8c4; background: var(--danger-soft); color: var(--danger); font-size: 11px; line-height: 1.45; }
.account-error svg { flex: 0 0 auto; margin-top: 1px; }
.message-tools { min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.search-control { min-width: 100px; flex: 1; height: 32px; padding: 0 9px; border: 1px solid transparent; border-radius: 6px; }
.search-control:focus-within { border-color: var(--accent); background: var(--surface); }
.check-control { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.check-control input { width: 14px; height: 14px; accent-color: var(--accent); }
.message-count { color: var(--muted-2); font-size: 10px; white-space: nowrap; }
.message-list { min-height: 0; overflow: auto; padding: 4px 5px 10px; }
.message-row { width: 100%; min-height: 76px; display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 7px; padding: 10px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.message-row:hover { background: var(--surface-soft); }
.message-row.active { border-color: var(--line-strong); background: var(--accent-soft); }
.message-state { width: 6px; height: 6px; margin-top: 5px; border-radius: 50%; background: transparent; }
.message-row.unread .message-state { background: var(--accent); }
.message-copy { min-width: 0; }
.message-topline, .message-bottomline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.message-topline strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.message-topline time, .message-bottomline { color: var(--muted-2); font-size: 9px; }
.message-subject { display: block; margin: 5px 0 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.message-row.unread .message-subject { color: var(--text); font-weight: 600; }
.message-bottomline { justify-content: flex-start; }
.message-bottomline code { padding: 1px 5px; border: 1px solid #9ed1c1; border-radius: 4px; background: var(--surface); color: var(--accent); font-size: 10px; }
.list-empty, .empty-workspace, .detail-empty { display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); text-align: center; }
.list-empty { min-height: 260px; font-size: 12px; }
.empty-workspace { grid-row: span 1; min-height: 0; }

.detail-pane { overflow: auto; }
.detail-toolbar { position: sticky; z-index: 2; top: 0; min-height: 74px; padding: 10px 14px; background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(10px); }
.detail-title { min-width: 0; }
.detail-title h1 { max-width: 760px; margin: 6px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.privacy-chip { width: max-content; gap: 4px; padding: 3px 7px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 9px; font-weight: 700; }
.detail-content { max-width: 920px; margin: 0 auto; padding: 18px 20px 42px; }
.sender-block { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.sender-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: var(--surface-soft); color: var(--accent); font-size: 13px; font-weight: 750; }
.sender-block strong, .sender-block small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-block strong { font-size: 12px; }
.sender-block small, .sender-block time { margin-top: 3px; color: var(--muted); font-size: 10px; }
.code-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 14px 0; padding: 11px 12px; border: 1px solid #a9d4c6; border-radius: 6px; background: var(--accent-soft); }
.code-banner small, .code-banner strong { display: block; }
.code-banner small { color: var(--muted); font-size: 9px; }
.code-banner strong { margin-top: 2px; color: var(--accent); font: 700 20px ui-monospace, SFMono-Regular, Menlo, monospace; }
.detail-tabs { display: flex; align-items: center; gap: 3px; margin: 15px 0 8px; border-bottom: 1px solid var(--line); }
.detail-tabs button { height: 34px; display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.detail-tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.mail-text { min-height: 330px; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); color: var(--text); font: 12px/1.7 inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.mail-frame { width: 100%; min-height: 560px; border: 1px solid var(--line); border-radius: 6px; background: white; }

.privacy-report { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.privacy-summary { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center; gap: 10px; padding: 13px; background: var(--accent-soft); }
.privacy-shield { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: var(--surface); color: var(--accent); }
.privacy-summary strong { font-size: 12px; }
.privacy-summary p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.finding-list, .safe-links { padding: 8px; border-top: 1px solid var(--line); }
.finding-row, .safe-link-row { min-height: 43px; display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 8px; padding: 6px; border-bottom: 1px solid var(--line); }
.finding-row:last-child, .safe-link-row:last-child { border-bottom: 0; }
.safe-link-row { grid-template-columns: 28px minmax(0, 1fr) 30px; }
.finding-kind { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 5px; background: var(--surface-soft); color: var(--muted); }
.finding-kind.tracked { background: var(--danger-soft); color: var(--danger); }
.finding-row strong, .finding-row small, .safe-link-row strong, .safe-link-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finding-row strong, .safe-link-row strong { font-size: 10px; }
.finding-row small, .safe-link-row small { margin-top: 3px; color: var(--muted); font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
.safe-links h3 { margin: 3px 6px 7px; font-size: 11px; }

.attachment-section { margin-top: 16px; }
.attachment-section h3 { gap: 6px; margin: 0 0 7px; font-size: 11px; }
.attachment-list { display: grid; gap: 5px; }
.attachment-row { min-height: 46px; display: grid; grid-template-columns: 24px minmax(0, 1fr) 20px; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; color: inherit; text-decoration: none; }
.attachment-row:hover { border-color: var(--accent); background: var(--accent-soft); }
.attachment-row strong, .attachment-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-row strong { font-size: 10px; }
.attachment-row small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.detail-empty { min-height: 100%; }
.detail-placeholder { min-height: 100%; }
.detail-close { display: none; }

.dialog { width: min(94vw, 610px); padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20, 28, 25, 0.46); backdrop-filter: blur(3px); }
.dialog form { padding: 18px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head { margin-bottom: 17px; }
.dialog-head h2 { margin: 4px 0 0; font-size: 17px; }
.dialog-actions { justify-content: flex-end; margin-top: 17px; }
.privacy-note { gap: 6px; margin: 9px 0 0; color: var(--muted); font-size: 10px; }

.toast-region { position: fixed; z-index: 50; right: 14px; bottom: 14px; display: grid; gap: 7px; }
.toast { width: min(88vw, 340px); min-height: 42px; display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); color: var(--accent); font-size: 11px; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.sidebar-backdrop { display: none; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 235px 340px minmax(380px, 1fr); }
  .security-status { display: none; }
}

@media (max-width: 860px) {
  .workspace { grid-template-columns: 230px minmax(320px, 1fr); }
  .detail-pane { position: fixed; z-index: 12; inset: 54px 0 0; transform: translateX(102%); transition: transform 160ms ease; }
  .detail-pane.open { transform: translateX(0); }
  .detail-close { display: inline-grid; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 8px; }
  .topbar-brand small, .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 36px; padding: 0; }
  .menu-btn { display: inline-grid; }
  .workspace { grid-template-columns: 1fr; }
  .account-pane { position: fixed; z-index: 20; top: 54px; bottom: 0; left: 0; width: min(86vw, 285px); transform: translateX(-102%); transition: transform 160ms ease; box-shadow: var(--shadow); }
  .app-shell.sidebar-open .account-pane { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 19; inset: 54px 0 0; border: 0; background: rgba(18, 25, 22, 0.38); }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  .message-pane { border: 0; }
  .mail-toolbar { min-height: 108px; align-items: flex-start; flex-direction: column; }
  .mail-controls { width: 100%; overflow-x: auto; justify-content: flex-start; padding-bottom: 1px; }
  .select-control { min-width: 110px; }
  .message-tools { grid-template-columns: minmax(0, 1fr); }
  .check-control { display: none; }
  .detail-content { padding: 14px 12px 32px; }
  .sender-block { grid-template-columns: 34px minmax(0, 1fr); }
  .sender-block time { grid-column: 2; }
  .detail-title h1 { max-width: calc(100vw - 120px); }
  .detail-tabs { overflow-x: auto; }
  .detail-tabs button { flex: 0 0 auto; }
  .mail-frame { min-height: 480px; }
}
