:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --card: #1c2030;
  --card-hover: #23283a;
  --border: #2a2f3d;
  --border-strong: #3a4156;
  --text: #e8eaed;
  --muted: #8a8f9a;
  --primary: #09ba07;
  --primary-hover: #0ad30a;
  --primary-soft: rgba(9, 186, 7, 0.12);
  --danger: #e0533d;
  --danger-soft: rgba(224, 83, 61, 0.12);
  --warn: #f0a020;
  --warn-soft: rgba(240, 160, 32, 0.14);
  --info: #4aa3ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* 页面背景加一点渐变条纹 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(9, 186, 7, 0.08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(74, 163, 255, 0.06), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.view {
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.hidden {
  display: none !important;
}

/* ─── 登录页 ─── */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: cardIn 0.35s ease-out;
}

.login-logo {
  font-size: 42px;
  margin-bottom: 6px;
  filter: drop-shadow(0 2px 8px rgba(9, 186, 7, 0.3));
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

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

.login-input-wrap {
  position: relative;
  margin-bottom: 14px;
}

.login-input-wrap input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-input-wrap input:focus {
  border-color: var(--primary);
}

.login-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.login-toggle:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.btn-block {
  width: 100%;
}

.error-msg {
  color: var(--danger);
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
}

.login-foot {
  color: var(--muted);
  margin: 14px 0 0;
  font-size: 12px;
  opacity: 0.75;
}

/* ─── 主页面 ─── */
.main-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 25, 34, 0.9);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.5px;
}

.logo-emoji {
  font-size: 20px;
  filter: drop-shadow(0 1px 4px rgba(9, 186, 7, 0.35));
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.storage-tag {
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
}

.storage-tag.muted {
  color: var(--muted);
  border-style: dashed;
}

/* ─── 统计卡片 ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 20px 24px 8px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(9, 186, 7, 0.06));
  pointer-events: none;
}

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

.stat-card.stat-amount {
  background:
    linear-gradient(135deg, rgba(9, 186, 7, 0.08), transparent 70%),
    var(--card);
}

.stat-card.stat-amount .stat-value {
  background: linear-gradient(135deg, #0ad30a, #a6ff4d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
  position: relative;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
  position: relative;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
  position: relative;
}

/* ─── 工具栏 ─── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 24px 14px;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input,
.sort-select {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.search-input {
  width: 220px;
}

.search-input:focus,
.sort-select:focus {
  border-color: var(--primary);
}

.search-input::placeholder {
  color: var(--muted);
}

.sort-select {
  cursor: pointer;
}

/* ─── 预览区 ─── */
.preview-section {
  padding: 0 24px 8px;
}

.preview-card {
  background: var(--card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-2);
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px dashed var(--border);
}

.preview-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.preview-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.preview-row .p-amount {
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  min-width: 58px;
}

.preview-row .p-names {
  color: var(--text);
  flex: 1;
  word-break: break-all;
}

.preview-empty {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 10px;
}

/* ─── 分组列表 ─── */
.donor-list {
  flex: 1;
  padding: 8px 24px 110px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.donor-list-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
}

.donor-list-empty .big-emoji {
  font-size: 44px;
  display: block;
  margin-bottom: 8px;
  opacity: 0.6;
}

.donor-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 160px 1fr 40px;
  gap: 12px;
  align-items: start;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.donor-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.donor-card.is-invalid {
  border-color: var(--danger);
  background: linear-gradient(180deg, var(--danger-soft), transparent 40%), var(--card);
}

.donor-card.is-hidden {
  border-style: dashed;
  opacity: 0.75;
}

.donor-card .amount-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.donor-card .amount-wrap label {
  font-size: 12px;
  color: var(--muted);
}

.donor-card .amount-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.donor-card .amount-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.donor-card .amount-input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.donor-card .names-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.donor-card .names-wrap label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.donor-card .names-wrap .name-count {
  color: var(--primary);
  font-weight: 600;
  padding: 1px 8px;
  background: var(--primary-soft);
  border-radius: 999px;
  font-size: 11px;
}

.donor-card .names-input {
  width: 100%;
  min-height: 62px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.donor-card .names-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.donor-card .del-btn {
  align-self: stretch;
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.donor-card .del-btn:hover {
  background: var(--danger-soft);
  border-color: rgba(224, 83, 61, 0.4);
}

.donor-subtotal {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.donor-subtotal .chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.donor-subtotal .chip.total {
  background: var(--primary-soft);
  color: var(--primary);
}

.donor-subtotal .chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

/* ─── 底部操作栏 ─── */
.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(22, 25, 34, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--border);
  z-index: 10;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}

.dirty-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.dirty-tip.is-dirty {
  color: var(--warn);
  border-color: rgba(240, 160, 32, 0.5);
  background: var(--warn-soft);
}

.dirty-tip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.divider {
  color: var(--border-strong);
}

.footer-right {
  display: flex;
  gap: 10px;
}

/* ─── 按钮 ─── */
.btn-primary,
.btn-ghost,
.btn-link {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, transform 0.1s;
  border-radius: var(--radius);
}

.btn-primary {
  padding: 10px 18px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(9, 186, 7, 0.3);
}

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

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

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

.btn-ghost {
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-link {
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--text);
}

/* ─── 模态框 ─── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease-out;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease-out;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.modal-body .modal-note {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}

.modal-body textarea {
  width: 100%;
  min-height: 180px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  outline: none;
  resize: vertical;
}

.modal-body textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.modal-body .parse-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--danger-soft);
  border-radius: var(--radius);
  border: 1px solid rgba(224, 83, 61, 0.3);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ─── 快速添加模态框表单样式 ───────────────────── */
.modal-body .form-row {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
}

.modal-body .form-row label {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.modal-body .form-row .amount-input {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 500;
  outline: none;
  width: 100%;
}

.modal-body .form-row .amount-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.modal-body .form-row .names-input {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  width: 100%;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 86%;
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: var(--primary);
  background: linear-gradient(180deg, var(--primary-soft), transparent), var(--card);
}

.toast.error {
  border-color: var(--danger);
  background: linear-gradient(180deg, var(--danger-soft), transparent), var(--card);
  color: var(--danger);
}

.toast.warn {
  border-color: var(--warn);
  background: linear-gradient(180deg, var(--warn-soft), transparent), var(--card);
  color: var(--warn);
}

/* ─── 动画 ─── */
@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

/* ─── 响应式 ─── */
@media (max-width: 820px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  html,
  body {
    font-size: 15px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .topbar {
    padding: 10px 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar h1 {
    font-size: 15px;
  }
  .topbar-right {
    gap: 6px;
    font-size: 11px;
  }
  .storage-tag {
    padding: 3px 8px;
    font-size: 11px;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    padding: 12px 14px 6px;
    gap: 8px;
  }
  .stat-card {
    padding: 10px 12px;
  }
  .stat-label {
    font-size: 11px;
  }
  .stat-value {
    font-size: 19px;
  }

  .toolbar {
    padding: 4px 14px 12px;
    gap: 8px;
  }
  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }
  .toolbar-left .search-input {
    flex: 1;
    width: auto;
  }
  .toolbar-left .sort-select {
    flex: 0 0 auto;
  }
  .toolbar-right button {
    flex: 1;
    min-width: 0;
    padding: 9px 10px;
    font-size: 13px;
  }

  .preview-section {
    padding: 0 14px 6px;
  }

  .donor-list {
    padding: 4px 14px 140px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .donor-card {
    grid-template-columns: 1fr 36px;
    gap: 10px;
    padding: 12px 12px;
  }
  .donor-card .amount-wrap,
  .donor-card .names-wrap {
    grid-column: 1 / -1;
  }
  .donor-card .amount-input,
  .donor-card .names-input {
    font-size: 16px;
  }
  .donor-card .del-btn {
    align-self: end;
    height: 36px;
    font-size: 16px;
  }

  .footer {
    padding: 10px 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    gap: 8px;
  }
  .footer-left {
    width: 100%;
    justify-content: space-between;
  }
  .footer-right {
    width: 100%;
  }
  .footer-right button {
    flex: 1;
  }
  .footer-right .btn-primary {
    flex: 2;
  }

  .toast {
    bottom: calc(120px + env(safe-area-inset-bottom));
    font-size: 13px;
  }

  .login-card {
    padding: 26px 22px;
  }
}

@media (max-width: 380px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }
  .stat-value {
    font-size: 17px;
  }
}
