/* ============================================================
   临时邮箱前端 · 侧边栏布局（2026-08-14 全新设计）
   信息架构：左侧地址管理 + 右侧邮件工作区
   ============================================================ */
:root {
  --bg: #eef1f8;
  --bg-grad-1: #f5f7fe;
  --bg-grad-2: #f0effb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef2ff;
  --accent: #7c3aed;
  --accent-soft: #f3e8ff;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);
  --radius: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

/* hidden 属性必须始终生效 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(124, 58, 237, 0.10), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(79, 70, 229, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-1) 0%, var(--bg) 100%);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

/* ================= 登录视图 ================= */
body.auth .topbar,
body.auth .app {
  display: none;
}

.login-view {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.login-view::before,
.login-view::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(70px);
  z-index: 0;
  pointer-events: none;
}

.login-view::before {
  width: 420px;
  height: 420px;
  left: -120px;
  top: -120px;
  background: rgba(99, 102, 241, 0.18);
}

.login-view::after {
  width: 480px;
  height: 480px;
  right: -140px;
  bottom: -140px;
  background: rgba(168, 85, 247, 0.16);
}

body.auth .login-view {
  display: flex;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  padding: 36px 34px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}

.login-brand {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 18px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.3px;
}

.login-sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.login-card label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.password-wrap {
  position: relative;
  margin-bottom: 16px;
}

.password-wrap input {
  width: 100%;
  margin: 0;
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

/* ================= 顶栏 ================= */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3);
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1.5px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #cbd5e1;
}

.status-dot.ok {
  background: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
}

.status-dot.error {
  background: var(--danger);
}

.status-text {
  color: var(--muted);
  font-size: 13px;
}

/* ================= 主体布局：侧边栏 + 主区 ================= */
.app-body {
  flex: 1;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.sidebar {
  width: 310px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.side-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.side-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-history {
  flex: 1;
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.history-list {
  flex: 1;
  overflow: auto;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 11px;
  padding: 0 4px;
}

/* 地址历史项 */
.history-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.history-item:hover {
  background: var(--surface-2);
}

.history-item.active {
  background: var(--primary-soft);
}

.history-main {
  flex: 1;
  min-width: 0;
}

.history-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ================= 主区 ================= */
.main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ================= 通用控件 ================= */
.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label,
.settings-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  height: 42px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  height: auto;
  padding: 10px 14px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

#currentAddress {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13.5px;
  background: var(--surface-2);
}

.address-box {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.inline-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: all 0.15s ease;
}

.btn:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.btn-accent:hover {
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.btn-favorite {
  min-height: 42px;
  width: 52px;
  font-size: 16px;
  padding: 0;
}

.btn-favorite.active {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #fcd34d;
}

.count-badge {
  padding: 3px 9px;
  color: var(--muted);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.panel-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-sm {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

.meta-summary {
  overflow-wrap: anywhere;
}

/* ================= 邮件面板 ================= */
.inbox-panel,
.detail-panel {
  min-height: 600px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-tools {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.mail-list {
  flex: 1;
  overflow: auto;
  max-height: 72vh;
}

.mail-item {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-bottom: 1px solid #edf2f7;
  cursor: pointer;
  transition: background 0.12s ease;
}

.mail-item:hover {
  background: var(--surface-2);
}

.mail-item.active {
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.mail-item-top {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.mail-item h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  word-break: break-word;
}

.mail-item time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.mail-item-from {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-item-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.mail-item-foot > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-code-pill {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  font-family: Consolas, monospace;
}

/* ================= 邮件详情 ================= */
.mail-detail {
  flex: 1;
  overflow: auto;
  padding: 18px;
}

.empty {
  padding: 28px 18px;
  color: var(--muted);
  line-height: 1.7;
}

.detail-subject {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.detail-subject h3 {
  margin: 0;
  font-size: 19px;
  line-height: 1.45;
  word-break: break-word;
  letter-spacing: -0.2px;
}

.detail-subject span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.meta-cell {
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.meta-cell span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.meta-cell div {
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  background: var(--surface-3);
  border-radius: 10px;
  width: fit-content;
}

.tab-btn {
  min-height: 32px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s ease;
}

.tab-btn.active {
  color: var(--primary-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.body-view {
  min-height: 220px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.body-text,
.raw-pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
  font-size: 13px;
}

.raw-pre {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
}

.html-frame {
  display: block;
  width: 100%;
  height: 440px;
  border: 0;
  background: #ffffff;
  border-radius: 8px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ================= 设置对话框 ================= */
dialog {
  width: min(720px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
}

.settings-dialog[open] {
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

dialog:not([open]) {
  display: none;
}

.settings-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.settings-head h2 {
  margin: 0;
  font-size: 17px;
  flex: 1;
  letter-spacing: -0.2px;
}

.role-badge {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 700;
}

#settingsRoleNotice {
  margin: 14px 22px 0;
  padding: 12px 14px;
  background: var(--amber-soft);
  border: 1px solid #fde68a;
  border-radius: 10px;
  color: var(--amber);
}

.settings-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 22px 0;
  border-bottom: 1px solid var(--border);
}

.settings-tab {
  min-height: 38px;
  padding: 0 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: -1px;
  transition: color 0.15s ease;
}

.settings-tab:hover {
  color: var(--text);
}

.settings-tab.active {
  color: var(--primary-strong);
  border-bottom-color: var(--primary);
}

.settings-panel {
  padding: 4px 22px 22px;
  overflow: auto;
}

.settings-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.settings-section:first-child {
  margin-top: 12px;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.settings-section-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.section-hint {
  color: var(--muted);
  font-size: 12px;
}

.settings-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.settings-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
}

.settings-status.ok {
  color: #059669;
  font-weight: 600;
}

.settings-status.error {
  color: var(--danger);
  font-weight: 600;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.settings-actions {
  margin-top: 16px;
  flex-wrap: wrap;
}

.settings-actions .settings-status {
  flex: 1;
  margin: 0;
  overflow-wrap: anywhere;
}

.access-code-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  margin-bottom: 12px;
  overflow: auto;
}

.access-code-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: box-shadow 0.15s ease;
}

.access-code-item:hover {
  box-shadow: var(--shadow-sm);
}

.access-code-item-main {
  min-width: 0;
}

.access-code-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.access-code-expiry {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.access-code-actions {
  display: flex;
  gap: 8px;
}

.access-code-actions .btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.api-key-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  margin-bottom: 12px;
  overflow: auto;
}

.api-key-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: box-shadow 0.15s ease;
}

.api-key-item:hover {
  box-shadow: var(--shadow-sm);
}

.api-key-item-main {
  min-width: 0;
}

.api-key-status {
  font-size: 12px;
  font-weight: 700;
}

.api-key-status.ok {
  color: #059669;
}

.api-key-status.error {
  color: var(--danger);
}

.api-scope-field {
  grid-column: 1 / -1;
}

.scope-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-dialog .scope-option {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.settings-dialog .scope-option:hover {
  border-color: var(--primary);
}

.scope-option input {
  margin: 0;
  width: auto;
  height: auto;
  accent-color: var(--primary);
}

.api-key-bound-fields {
  display: contents;
}

.api-key-bound-fields.hidden {
  display: none;
}

.new-api-key-panel {
  margin-top: 16px;
  padding: 14px;
  background: var(--amber-soft);
  border: 1px solid #fde68a;
  border-radius: 12px;
}

.new-api-key-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.new-api-key-panel textarea {
  min-height: 76px;
  resize: vertical;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  background: #fff;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.access-password-row {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.access-password-row input {
  flex: 1;
}

/* ================= 响应式 ================= */
@media (max-width: 1100px) {
  .app-body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .side-history {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .history-list {
    max-height: 220px;
  }

  .main {
    grid-template-columns: 1fr;
  }

  .inbox-panel,
  .detail-panel {
    min-height: 440px;
  }

  .mail-list {
    max-height: 46vh;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 14px;
  }

  .app-body {
    padding: 12px 10px 30px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .side-history {
    grid-column: auto;
  }

  .address-box,
  .inline-row {
    grid-template-columns: 1fr;
  }

  .address-box {
    display: grid;
  }

  .tabs {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid,
  .access-code-item,
  .api-key-item {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    padding: 4px 14px 14px;
  }

  .settings-head {
    padding: 16px 14px 12px;
  }

  .settings-tabs {
    padding: 12px 14px 0;
  }
}
