/* ─────────────────────────────────────────────────────────────
   发信台 · 样式
   质感方向：暖纸底 + 墨色字 + 朱红点缀；衬线标题，等宽字段。
   不依赖任何外部字体或 CDN，离线/内网也能正常显示。
   ───────────────────────────────────────────────────────────── */

:root {
  --paper: #f4f0e8;
  --paper-2: #ebe5d9;
  --sheet: #fffdf9;
  --ink: #1a1612;
  --ink-2: #57504a;
  --ink-3: #8a8178;
  --line: #e0d7c9;
  --line-2: #cdc1ae;
  --accent: #c8402b;
  --accent-hover: #ad331f;
  --accent-soft: #f8e5df;
  --ok: #1d6b46;
  --ok-soft: #e2f0e8;
  --warn: #96620f;
  --warn-soft: #f8eedb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(26, 22, 18, .04), 0 18px 40px -18px rgba(26, 22, 18, .22);
  --shadow-sm: 0 1px 0 rgba(26, 22, 18, .04), 0 6px 16px -10px rgba(26, 22, 18, .25);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
             "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong",
                "SimSun", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
               Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15120f;
    --paper-2: #1c1815;
    --sheet: #1f1b17;
    --ink: #f2ece2;
    --ink-2: #b9afa2;
    --ink-3: #877d72;
    --line: #302a25;
    --line-2: #3d352f;
    --accent: #e2634c;
    --accent-hover: #ec7761;
    --accent-soft: #38201b;
    --ok: #62c391;
    --ok-soft: #172a21;
    --warn: #d8a54a;
    --warn-soft: #2b2416;
    --shadow: 0 1px 0 rgba(0, 0, 0, .35), 0 20px 44px -20px rgba(0, 0, 0, .7);
    --shadow-sm: 0 1px 0 rgba(0, 0, 0, .35), 0 8px 18px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  /* 极淡的纸纹点阵 */
  background-image:
    radial-gradient(rgba(26, 22, 18, .045) 1px, transparent 1px),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
  background-size: 22px 22px, 100% 100%;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  body {
    background-image:
      radial-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
      linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
  }
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; }

code, kbd, .mono { font-family: var(--font-mono); }

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-2);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* ── 视图切换 ───────────────────────────────────────────── */

.view { min-height: 100vh; }

/* ── 登录 ───────────────────────────────────────────────── */

.view--login {
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login {
  width: 100%;
  max-width: 380px;
  padding: 40px 36px 32px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: left;
  animation: rise .45s cubic-bezier(.2, .7, .2, 1) both;
}

.login__mark { color: var(--accent); display: inline-flex; }

.login__title {
  margin-top: 18px;
  font-family: var(--font-serif);
  font-size: 34px;
  letter-spacing: .04em;
}

.login__sub {
  margin: 6px 0 26px;
  color: var(--ink-2);
}

.login__form { display: grid; gap: 14px; }

.login__foot {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  color: var(--ink-3);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ── 顶栏 ───────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand__mark { color: var(--accent); display: inline-flex; }
.brand__text { display: grid; line-height: 1.25; min-width: 0; }
.brand__name { font-family: var(--font-serif); font-size: 18px; letter-spacing: .06em; }
.brand__sub { font-size: 11.5px; color: var(--ink-3); letter-spacing: .04em; }

.topbar__actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── 主体布局 ───────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 26px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 40px) 72px;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* ── 信笺（写信区）─────────────────────────────────────── */

.sheet {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise .4s cubic-bezier(.2, .7, .2, 1) both;
}

.sheet form { padding: 26px clamp(18px, 3vw, 32px) 22px; }

.sheet__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sheet__head h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  letter-spacing: .05em;
}

.sheet__hint { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

/* 字段行：标签在左、输入在右，用发丝线分隔，像信笺的横线 */
.lines { border-top: 1px solid var(--line); }

.line {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
}

.line__label {
  font-size: 12.5px;
  letter-spacing: .1em;
  color: var(--ink-3);
  transition: color .15s;
}

.line:focus-within .line__label { color: var(--accent); }

.line input,
.line__subject {
  width: 100%;
  min-width: 0;
  padding: 8px 0;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
}

.line input::placeholder { color: var(--ink-3); opacity: .75; }

.line__subject {
  font-family: var(--font-serif);
  font-size: 19px;
  letter-spacing: .02em;
}

/* 收件人 chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  min-width: 0;
}

.chips input {
  flex: 1 1 180px;
  min-width: 120px;
  padding: 6px 0;
}

.chip-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  animation: pop .18s ease-out both;
}

.chip-item__x {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  color: var(--ink-3);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.chip-item__x:hover { color: var(--accent); background: var(--accent-soft); }

@keyframes pop {
  from { opacity: 0; transform: scale(.92); }
  to { opacity: 1; transform: none; }
}

/* 正文 */
.body { margin-top: 18px; }

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

.tabs {
  display: inline-flex;
  padding: 3px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.tab {
  padding: 5px 16px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  background: var(--sheet);
  box-shadow: var(--shadow-sm);
}

.body__count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.body__area {
  display: block;
  width: 100%;
  min-height: 260px;
  padding: 16px 18px;
  font: inherit;
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink);
  background: color-mix(in srgb, var(--paper) 55%, var(--sheet));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  resize: vertical;
  transition: border-color .15s, background .15s;
}

.body__area:focus {
  border-color: var(--accent);
  background: var(--sheet);
}

.body__area--code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  tab-size: 2;
}

.sheet__foot {
  /* 吸在视口底部：正文再长，发送按钮也始终够得着 */
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 14px 0 2px;
  background: var(--sheet);
  box-shadow: 0 -12px 14px -12px rgba(26, 22, 18, .22);
}

.quota { margin: 0; font-size: 12.5px; color: var(--ink-3); }

/* ── 侧栏面板 ───────────────────────────────────────────── */

.side { display: grid; gap: 18px; }

.panel {
  padding: 18px 18px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.panel__title {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .14em;
  color: var(--ink-3);
  margin-bottom: 12px;
}

.panel__head .panel__title { margin-bottom: 12px; }

.kv { margin: 0 0 14px; display: grid; gap: 10px; }

.kv__row { display: grid; gap: 2px; }
.kv dt { font-size: 12px; color: var(--ink-3); }
.kv dd {
  margin: 0;
  font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.kv dd.mono { font-size: 12.5px; }
.kv dd.is-empty { color: var(--ink-3); }

.domain-list { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  padding: 2px 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ok);
  background: var(--ok-soft);
  border-radius: 999px;
}

/* 最近发送 */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.history__item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-top: 1px solid var(--line);
}

.history__item:first-child { border-top: 0; }

.history__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.history__item.is-failed .history__dot { background: var(--accent); }

.history__main { min-width: 0; }

.history__subject {
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history__to {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history__time {
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history__empty {
  padding: 6px 2px;
  font-size: 13px;
  color: var(--ink-3);
}

/* ── 附件 ───────────────────────────────────────────────── */

.attach {
  position: relative;
  margin-top: 12px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  background: transparent;
  background: color-mix(in srgb, var(--paper-2) 45%, transparent);
  transition: border-color .15s, background .15s;
}

.attach.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* 原生文件输入框永远不露面，只由按钮点击或拖拽触发 */
.attach__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.attach__add {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 16px 12px;
  font: inherit;
  color: var(--ink-2);
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.attach__add:hover {
  color: var(--ink);
  background: var(--paper-2);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}

.attach__icon {
  color: var(--accent);
  opacity: .9;
}

.attach__title {
  font-size: 13px;
}

.attach__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0 12px 12px;
  list-style: none;
  min-width: 0;
}

.attach__list:empty { display: none; }

.attach__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 4px 4px 10px;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 999px;
  animation: pop .18s ease-out both;
}

.attach__name {
  max-width: 220px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.attach__size {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
}

.attach__hint {
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.attach__hint.is-over { color: var(--accent); }

/* ── 按钮 ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .08s, opacity .15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn:focus-visible,
.tab:focus-visible,
.chip:focus-visible,
.link:focus-visible,
.icon-btn:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  color: #fffdf9;
  background: var(--accent);
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover { background: var(--accent-hover); }

.btn--ghost { color: var(--ink-2); border-color: var(--line-2); }
.btn--ghost:hover { color: var(--ink); background: var(--paper-2); }

.btn--quiet {
  padding: 7px 12px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--paper-2);
  border-color: var(--line);
}
.btn--quiet:hover { color: var(--ink); border-color: var(--line-2); }

.btn--block { width: 100%; }

.btn--send { padding: 12px 30px; font-size: 15px; }

.btn[disabled] { opacity: .55; cursor: progress; }

.link {
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--ink-3);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--accent); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--paper-2); }

/* 顶栏状态胶囊 */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: var(--line-2); }

.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}
.chip.is-ready .chip__dot { background: var(--ok); }

/* ── 表单通用 ───────────────────────────────────────────── */

.field { display: grid; gap: 6px; }

.field__label {
  font-size: 12.5px;
  letter-spacing: .1em;
  color: var(--ink-3);
}

.field input,
.group input {
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  color: var(--ink);
  background: color-mix(in srgb, var(--paper) 55%, var(--sheet));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  transition: border-color .15s, background .15s;
}

.field input:focus,
.group input:focus {
  border-color: var(--accent);
  background: var(--sheet);
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}

.login .form-error { margin: 0; }

/* ── 设置抽屉 ───────────────────────────────────────────── */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}

.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 22, 18, .42);
  backdrop-filter: blur(2px);
  animation: fade .2s ease-out both;
}

.drawer__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(460px, 100vw);
  max-height: 100vh;
  background: var(--sheet);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: slide .28s cubic-bezier(.2, .7, .2, 1) both;
}

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.drawer__head h2 { font-family: var(--font-serif); font-size: 21px; letter-spacing: .05em; }

.drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 22px;
  display: grid;
  gap: 24px;
  align-content: start;
}

.group { display: grid; gap: 10px; }

.group__title { font-size: 14px; }

.group__hint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-3);
}

.group__hint code {
  padding: 1px 5px;
  font-size: 12px;
  background: var(--paper-2);
  border-radius: 4px;
}

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

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

.verify {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  color: var(--ok);
  background: var(--ok-soft);
}
.verify.is-bad { color: var(--accent); background: var(--accent-soft); }

.drawer__foot {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
  padding: 14px 0 2px;
  background: var(--sheet);
  box-shadow: 0 -12px 14px -12px rgba(26, 22, 18, .22);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ── 提示条 ─────────────────────────────────────────────── */

.toasts {
  position: fixed;
  z-index: 80;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 28px);
  display: grid;
  gap: 10px;
  max-width: min(380px, calc(100vw - 24px));
}

.toast {
  padding: 12px 16px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: rise .25s ease-out both;
}

.toast.is-bad { border-left-color: var(--accent); }
.toast__title { font-weight: 600; }
.toast__meta {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }

/* ── 小屏微调 ───────────────────────────────────────────── */

@media (max-width: 620px) {
  .brand__sub { display: none; }
  .topbar__actions .btn--ghost { padding: 8px 11px; font-size: 13px; }
  .sheet__head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .line { grid-template-columns: 62px minmax(0, 1fr); }
  .sheet__foot { flex-direction: column-reverse; align-items: stretch; }
  .btn--send { width: 100%; }
  .quota { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
