/* ================================================================
 * CF-MAIL 控制台样式系统
 * 设计取向：克制、密度高、信息明确、操作快
 * 硬规则：圆角 ≤10px，字号 16/14/12，禁外部资源
 * ================================================================ */

:root {
  /* === 暗色主题（默认） === */
  --bg-base: #0b0d12;
  --bg-panel: #14181f;
  --bg-subtle: #1c2230;
  --bg-hover: #232b3a;
  --border: #2f3a4d;
  --border-strong: #3f4d63;
  --text: #eef2f7;
  --text-secondary: #b9c2cd;
  --text-muted: #8893a1;
  --brand: #5b8cff;
  --brand-hover: #6f9bff;
  --brand-soft: rgba(91, 140, 255, 0.16);
  --success: #34c38f;
  --success-soft: rgba(52, 195, 143, 0.16);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.16);
  --warning: #ffb84d;
  --warning-soft: rgba(255, 184, 77, 0.16);

  /* === 圆角 token（仅以下值，硬规则 ≤10px） === */
  --r-2: 2px;
  --r-4: 4px;
  --r-6: 6px;
  --r-8: 8px;
  --r-10: 10px;

  /* === 字号 token === */
  --fz-12: 12px;
  --fz-14: 14px;
  --fz-16: 16px;
  --fz-20: 20px;

  /* === 间距 token === */
  --sp-4: 4px;
  --sp-6: 6px;
  --sp-8: 8px;
  --sp-10: 10px;
  --sp-12: 12px;
  --sp-16: 16px;
  --sp-20: 20px;
  --sp-24: 24px;

  /* === 兼容旧变量名（contract / inline 字符串引用，必须保留） === */
  --cursor-bg: var(--bg-base);
  --cursor-bg-elevated: var(--bg-panel);
  --cursor-bg-card: var(--bg-panel);
  --cursor-bg-hover: var(--bg-subtle);
  --cursor-border: var(--border);
  --cursor-border-light: var(--border);
  --cursor-text: var(--text);
  --cursor-text-secondary: var(--text-secondary);
  --cursor-text-muted: var(--text-muted);
  --cursor-accent: var(--text);
  --cursor-accent-hover: var(--text);
  --cursor-blue: var(--brand);
  --cursor-blue-hover: var(--brand-hover);
  --cursor-blue-bg: var(--brand-soft);
  --cursor-red: var(--danger);
  --cursor-red-bg: var(--danger-soft);
  --cursor-green: var(--success);
  --cursor-green-bg: var(--success-soft);
  --transition-speed: 0.15s;
}

/* === 亮色主题 === */
[data-theme="light"] {
  --bg-base: #f3f5f9;
  --bg-panel: #ffffff;
  --bg-subtle: #eaeef4;
  --bg-hover: #dde3ec;
  --border: #c2cad6;
  --border-strong: #a6b1c0;
  --text: #0f1620;
  --text-secondary: #3e4a5c;
  --text-muted: #6b7888;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: rgba(37, 99, 235, 0.12);
  --success: #0f9f6e;
  --success-soft: rgba(15, 159, 110, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
}

/* === 全局 reset === */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: var(--fz-14);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button {
  font-family: inherit;
}

/* === 滚动条 === */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* === 焦点 === */
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
}
*:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* === 通用工具类 === */
.text-12 {
  font-size: var(--fz-12);
}
.text-14 {
  font-size: var(--fz-14);
}
.text-16 {
  font-size: var(--fz-16);
}
.text-20 {
  font-size: var(--fz-20);
}
.text-muted {
  color: var(--text-muted);
}
.text-secondary {
  color: var(--text-secondary);
}
.text-brand {
  color: var(--brand);
}
.text-success {
  color: var(--success);
}
.text-danger {
  color: var(--danger);
}
.font-mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* === 面板 === */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-8);
}

/* === 按钮 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--r-6);
  font-size: var(--fz-12);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-speed),
    color var(--transition-speed), border-color var(--transition-speed);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text);
}
.btn-soft {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: transparent;
}
.btn-soft:hover:not(:disabled) {
  background: var(--brand);
  color: #fff;
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}
.btn-sm {
  height: 26px;
  padding: 0 10px;
  font-size: var(--fz-12);
}
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}
.btn-icon.btn-sm {
  width: 26px;
  height: 26px;
}
.btn-block {
  width: 100%;
}

/* === 输入 === */
.input,
.select,
.textarea {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-6);
  color: var(--text);
  font-size: var(--fz-14);
  font-family: inherit;
  transition: border-color var(--transition-speed),
    background var(--transition-speed);
}
.input::placeholder {
  color: var(--text-muted);
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
  background: var(--bg-panel);
}
.textarea {
  height: auto;
  padding: 8px 10px;
  line-height: 1.5;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.input-with-icon {
  position: relative;
}
.input-with-icon .input {
  padding-left: 32px;
}
.input-with-icon > .icon {
  position: absolute;
  top: 50%;
  left: 10px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* === 标签 === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-4);
  font-size: var(--fz-12);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(52, 195, 143, 0.3);
}
.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.3);
}
.badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: rgba(255, 184, 77, 0.3);
}
.badge.brand {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: rgba(91, 140, 255, 0.3);
}
.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: currentColor;
}

/* === 列表项 === */
.row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition-speed);
  position: relative;
}
.row:hover {
  background: var(--bg-subtle);
}
.row.active {
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 0 var(--brand);
}

/* === 应用骨架 === */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: var(--fz-14);
  color: var(--text);
}
.topbar .brand-mark {
  width: 24px;
  height: 24px;
  border-radius: var(--r-6);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar .spacer {
  flex: 1;
}
.topbar .topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fz-12);
  color: var(--text-secondary);
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section {
  padding: 12px 0 8px;
}
.sidebar-section-title {
  padding: 4px 14px;
  font-size: var(--fz-12);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
  flex-shrink: 0;
}

/* === 侧边导航项（Linear/Notion 风：内敛、低饱和） === */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  margin: 1px 8px;
  border-radius: var(--r-6);
  color: var(--text-secondary);
  font-size: var(--fz-14);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-speed),
    color var(--transition-speed);
  width: calc(100% - 16px);
  border: none;
  background: transparent;
  text-align: left;
  position: relative;
}
.nav-item > i {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-speed);
}
.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--text);
}
.nav-item:hover > i {
  color: var(--text-secondary);
}
.nav-item.active {
  background: var(--bg-subtle);
  color: var(--text);
  font-weight: 600;
}
.nav-item.active > i {
  color: var(--brand);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 14px;
  border-radius: 1px;
  background: var(--brand);
}

/* === segmented === */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-subtle);
  border-radius: var(--r-6);
  border: 1px solid var(--border);
}
.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 28px;
  font-size: var(--fz-12);
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--r-4);
  cursor: pointer;
  transition: background var(--transition-speed),
    color var(--transition-speed);
}
.segmented button:hover:not(.active) {
  color: var(--text);
}
.segmented button.active {
  background: var(--brand);
  color: #fff;
}

/* === 中栏 === */
.middle {
  width: 360px;
  flex-shrink: 0;
  background: var(--bg-base);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.middle-toolbar {
  flex-shrink: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.middle-toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.middle-list {
  flex: 1;
  overflow-y: auto;
}

/* === 详情栏 === */
.detail {
  flex: 1;
  background: var(--bg-base);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.detail-header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
}
.detail-body {
  flex: 1;
  overflow-y: auto;
}

/* === 空状态 === */
.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}
.empty .empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--r-10);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.empty .empty-title {
  font-size: var(--fz-14);
  font-weight: 600;
  color: var(--text-secondary);
}
.empty .empty-desc {
  font-size: var(--fz-12);
  max-width: 320px;
  line-height: 1.6;
}

/* === 卡片 === */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-8);
  padding: 16px;
}
.card-title {
  font-size: var(--fz-14);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.card-desc {
  font-size: var(--fz-12);
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* === 步骤条 === */
.steps {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fz-12);
  color: var(--text-muted);
}
.steps .step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.steps .step.active {
  color: var(--brand);
  font-weight: 600;
}
.steps .step.done {
  color: var(--text-secondary);
}
.steps .step-num {
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
}
.steps .step.active .step-num {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.steps .step-sep {
  width: 16px;
  height: 1px;
  background: var(--border);
}

/* === 余额卡片 === */
.balance-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-6);
  padding: 10px 12px;
}
.balance-card .label {
  font-size: var(--fz-12);
  color: var(--text-muted);
}
.balance-card .value {
  font-size: var(--fz-16);
  font-weight: 700;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  margin-top: 2px;
}

/* === ISO 国旗块（替代外部 flagcdn） === */
.iso-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  border-radius: var(--r-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* === Toast === */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--r-8);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  font-size: var(--fz-12);
  font-weight: 500;
  z-index: 9999;
  animation: fadeIn 0.2s ease-out;
}
.toast.success {
  color: var(--success);
  border-color: rgba(52, 195, 143, 0.3);
}
.toast.error {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.3);
}
.toast.info {
  color: var(--brand);
  border-color: rgba(91, 140, 255, 0.3);
}

/* === Modal === */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease-out;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-8);
  padding: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}
.modal-title {
  font-size: var(--fz-14);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.modal-desc {
  font-size: var(--fz-12);
  color: var(--text-secondary);
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* === 动画 === */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.animate-fade-in {
  animation: fadeIn 0.2s ease-out;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.spin {
  animation: spin 0.8s linear infinite;
}

/* === 移动端响应 === */
@media (max-width: 900px) {
  .sidebar {
    width: 200px;
  }
  .middle {
    width: 320px;
  }
}
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
  }
  .sidebar,
  .middle {
    display: none;
  }
  .sidebar.show,
  .middle.show {
    display: flex;
    width: 100%;
    position: fixed;
    inset: 48px 0 0 0;
    z-index: 50;
  }
  .detail.hide-mobile {
    display: none;
  }
}

/* === 邮件 iframe 容器 === */
#d-body {
  background: #fff;
}
#email-frame {
  width: 100%;
  height: 100%;
  border: 0;
}

/* === 隐藏 === */
.hidden {
  display: none !important;
}
