/* ============================================================
   Tokens — 明暗双主题
   ============================================================ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --surface-3: #e9eaef;
  --border: #e3e5ea;
  --text: #1b1e27;
  --text-2: #5b6270;
  --text-3: #747c8c;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-ink: #4338ca;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(18, 21, 34, .05), 0 10px 28px rgba(18, 21, 34, .06);
  --shadow-sm: 0 1px 2px rgba(18, 21, 34, .05);
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1e232c;
  --surface-3: #262c37;
  --border: #2a313d;
  --text: #e9ebef;
  --text-2: #9aa2b0;
  --text-3: #7d8594;
  --accent: #818cf8;
  --accent-strong: #a5b0ff;
  --accent-soft: #232a4a;
  --accent-ink: #c7cdff;
  --danger: #f87171;
  --danger-soft: #3a2226;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
}

/* ============================================================
   Base
   ============================================================ */
*,
*::before,
*::after { box-sizing: border-box; }

html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  overflow-x: hidden;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #3730a3; color: #fff; }
.message-body ::selection { background: #3730a3; color: #fff; }

/* 主题化浏览器表面 */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

input, select, button { font-family: inherit; font-size: inherit; color: inherit; max-width: 100%; }

button { cursor: pointer; }

.hidden { display: none !important; }

/* ============================================================
   Layout
   ============================================================ */
.app {
  max-width: min(92%, 1720px);
  overflow-x: hidden;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 4px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, #818cf8, #6366f1 60%, #4f46e5);
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-2);
}

.topbar-actions { display: flex; align-items: center; gap: 14px; }

/* 自动刷新开关 */
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background .18s ease;
  flex: none;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .18s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-2);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar-inbox { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.btn { white-space: nowrap; }

select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 34px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b92a1' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#inboxSelect { min-width: 170px; max-width: 460px; flex: 1 1 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

/* ---- New box ---- */
.new-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.new-box input {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.new-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.new-box input::placeholder { color: var(--text-3); }

/* ---- Main row: 桌面分栏 ---- */
.main-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
  height: calc(100dvh - 220px);
}
.main-row > .panel {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Panel ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 3px 10px;
  border-radius: 999px;
  flex: none;
}

/* ---- Message list / cards ---- */
.message-list {
  padding: 6px;
  flex: 1;
  overflow-y: auto;
}

.message-item {
  position: relative;
  border-radius: var(--radius-sm);
  padding: 2px;
  margin: 3px 6px;
  border-radius: var(--radius-sm);
  transition: background .12s ease;
}
.message-item:hover {
  background: var(--surface-2);
}

/* 折叠态：标题行白色突出，内容灰色弱化 */
.message-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px 2px;
  background: transparent;
  text-align: left;
  cursor: default;
}
.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  font-size: 12px;
  color: var(--text-2);
}
.m-sender {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-sender:hover { color: var(--accent); }
.m-arrow { color: var(--text-3); flex: none; }
.m-to {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-to:hover { color: var(--accent); }
.m-time { color: var(--text-3); flex: none; margin-left: auto; }
.chevron {
  flex: none;
  width: 14px;
  height: 14px;
  color: var(--text-3);
  transition: transform .18s ease;
  opacity: .6;
}
.message-item:hover .chevron { opacity: 1; }
.message-item.open .chevron { transform: rotate(90deg); }

/* 主体区：标题 + 预览 + 内联按钮 */
.message-main { padding: 0 12px 8px; }
.m-subject {
  display: inline;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.5;
}
.m-subject { color: var(--text); }
.message-item:hover .m-subject { color: var(--text); }

/* 链接按钮：紧跟主题末尾，内联高亮 */
.link-actions {
  display: inline-flex;
  gap: 5px;
  margin-left: 6px;
  vertical-align: middle;
}
.copy-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 8px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
  vertical-align: middle;
}
.copy-link:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.copy-link:active { transform: translateY(1px); }

/* 正文预览：折叠态灰色弱化 */
.m-preview {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 验证码药丸：绝对定位右上 */
.message-actions {
  position: absolute;
  top: 7px;
  right: 34px;
  z-index: 1;
}
.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  transition: background .15s ease, transform .08s ease;
}
.code-pill svg { width: 13px; height: 13px; }
.code-pill:hover { background: var(--accent); color: #fff; }
.code-pill:active { transform: translateY(1px); }

/* 展开正文：有内嵌底色+边框，与标题明确区分 */
.message-body {
  display: none;
  padding: 10px 14px;
  margin: 4px 10px 8px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  user-select: text;
  cursor: text;
}
.message-item.open .message-body { display: block; }
.message-item.open {
  background: var(--accent-soft);
}
.message-item.open:hover { background: var(--surface); }

/* ---- Empty states ---- */
.empty-state {
  text-align: center;
  padding: 42px 20px;
  color: var(--text-2);
}
.empty-state .icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-3);
}
.empty-state .icon svg { width: 22px; height: 22px; }
.empty-state .title { font-size: 14px; font-weight: 600; color: var(--text); }
.empty-state .sub { margin-top: 4px; font-size: 12.5px; }

/* ---- Footer ---- */
footer {
  margin-top: 26px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}
footer a { color: var(--text-3); text-decoration: none; }
footer a:hover { color: var(--accent); }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
  transition: opacity .2s ease;
}
.toast.fadeout { opacity: 0; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* 焦点可读性 */
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================
   Responsive — 手机竖排
   ============================================================ */
/* 中等宽度：仅较窄时切竖排 */
@media (max-width: 640px) {
  .main-row { height: auto; min-height: unset; }
  .main-row { flex-direction: column; }
}

/* 窄屏：工具栏整齐堆叠，按钮等宽 */
@media (max-width: 620px) {
  .app { padding: 12px 10px 44px; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .brand-text p { display: none; }
  .switch-label { display: none; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-inbox { flex: 1 1 100%; min-width: 0; overflow: hidden; }
  .toolbar-inbox select { max-width: none; min-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .toolbar-actions .btn { min-width: 0; flex: 1; justify-content: center; padding: 8px 6px; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .toolbar-actions .btn { justify-content: center; }
  .new-box { align-items: stretch; flex-direction: column; }
  .new-box input { min-width: 0; }
  .message-actions { position: static; padding: 0 12px 8px; }
  .message-meta { flex-wrap: wrap; row-gap: 3px; }
  .m-sender, .m-to { white-space: normal; word-break: break-all; }
  .m-time { margin-left: auto; }
}

/* 点击复制地址 */
.m-sender, .m-to, #currentInbox { cursor: pointer; }
.m-sender:hover, .m-to:hover { color: var(--accent); }
#currentInbox { transition: color .15s ease; }
#currentInbox:hover { color: var(--accent); }

/* 刷新加载状态 */
.btn.loading { opacity: .65; pointer-events: none; }
.btn.loading svg { animation: btn-spin .8s linear infinite; }
@keyframes btn-spin { to { transform: rotate(360deg); } }



/* ---- 全部收件：搜索 + 分页 ---- */
.all-search { padding: 8px 12px 0; flex-shrink: 0; }
.all-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.all-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.all-search input::placeholder { color: var(--text-3); }

.all-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
  margin-top: auto;
}
.pg-info { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.pg-btns { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pg-btn {
  min-width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.pg-btn:hover { background: var(--surface-2); color: var(--text); }
.pg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.pg-dots { color: var(--text-3); font-size: 12px; padding: 0 2px; }
.pg-size select {
  padding: 5px 28px 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b92a1' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--text-2);
  font-size: 12px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

/* 正文内链接：高亮可辨，单击复制 / Ctrl+单击打开 */
.body-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  transition: color .12s;
  word-break: break-all;
}
.body-link:hover { color: var(--accent-strong); text-decoration-thickness: 2px; }
