/*
 * app.css —— 配色直接抄自 TREK 的深色主题（client/src/index.css 的 .dark
 * 与 indigo 配色方案），手工复制过来，不引用 TREK 的任何代码。
 */

:root {
  /* 表面 */
  --bg-primary: #121215;
  --bg-secondary: #1a1a1e;
  --bg-tertiary: #1c1c21;
  --bg-card: #131316;
  --bg-input: #1c1c21;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-selected: rgba(255, 255, 255, 0.1);
  --bg-elevated: rgba(19, 19, 22, 0.92);

  /* 文字 */
  --text-primary: #f4f4f5;
  --text-secondary: #d4d4d8;
  --text-muted: #a1a1aa;
  --text-faint: #71717a;

  /* 描边 */
  --border-primary: #27272a;
  --border-secondary: #1c1c21;
  --border-faint: rgba(255, 255, 255, 0.07);

  /* 强调色（TREK indigo 深色方案） */
  --accent: #6366f1;
  --accent-text: #ffffff;
  --accent-on: #a5b4fc;
  --accent-hover: #4f46e5;
  --accent-subtle: rgba(99, 102, 241, 0.18);

  /* 状态色 */
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --info: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.24), 0 1px 2px rgba(0, 0, 0, 0.18);
  --shadow-elevated: 0 4px 16px rgba(0, 0, 0, 0.4);

  --font-system: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  --bottom-bar-h: 64px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-system);
  /* 16px 起步：iOS Safari 在小于 16px 的输入框上会自动放大页面 */
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom, 0px) + 12px);
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

input,
select {
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ── 顶部 ───────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border-faint);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
}

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

.trip-title {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  min-height: 32px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  border: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--text-faint);
  flex: none;
}

.status-pill[data-state='ok'] {
  color: var(--success);
  background: var(--success-soft);
  border-color: transparent;
}
.status-pill[data-state='ok'] .dot {
  background: var(--success);
}
.status-pill[data-state='syncing'],
.status-pill[data-state='connecting'] {
  color: var(--info);
  background: var(--info-soft);
  border-color: transparent;
}
.status-pill[data-state='syncing'] .dot,
.status-pill[data-state='connecting'] .dot {
  background: var(--info);
  animation: pulse 1.1s ease-in-out infinite;
}
.status-pill[data-state='error'],
.status-pill[data-state='retrying'],
.status-pill[data-state='offline'] {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: transparent;
}
.status-pill[data-state='error'] .dot,
.status-pill[data-state='retrying'] .dot,
.status-pill[data-state='offline'] .dot {
  background: var(--warning);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.persona-label {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0 0 6px;
}

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

.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip:active {
  background: var(--bg-hover);
}

.chip[aria-pressed='true'],
.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.chip.chip-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

/* ── 主体 ───────────────────────────────────────────────────────── */

main {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 12px;
  letter-spacing: 0.02em;
}

.empty {
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  padding: 22px 8px;
}

.hint {
  color: var(--text-faint);
  font-size: 13px;
  margin: 8px 0 0;
}

/* 净额大卡 */
.net-card {
  text-align: center;
  padding: 22px 16px;
}

.net-label {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.net-amount {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.net-amount.is-positive {
  color: var(--success);
}
.net-amount.is-negative {
  color: var(--danger);
}
.net-amount.is-zero {
  color: var(--text-secondary);
}

.net-sub {
  font-size: 13px;
  color: var(--text-faint);
  margin: 10px 0 0;
}

/* 结算清单 */
.settle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border-secondary);
}

.settle-row:first-of-type {
  border-top: none;
}

.avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent-subtle);
  color: var(--accent-on);
  border: 1px solid var(--border-faint);
}

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

.settle-name {
  font-size: 16px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settle-note {
  font-size: 12px;
  color: var(--text-faint);
}

.settle-amount {
  flex: none;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.settle-amount.in {
  color: var(--success);
}
.settle-amount.out {
  color: var(--danger);
}

.btn {
  min-height: 44px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  transition: background 0.15s;
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

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

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

.btn-sm {
  min-height: 38px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 550;
  flex: none;
}

.btn-block {
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn-row > * {
  flex: 1;
}

/* 汇总 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-faint);
}

.stat-value {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

details.plan {
  margin-top: 4px;
}

details.plan > summary {
  cursor: pointer;
  list-style: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text-muted);
}

details.plan > summary::-webkit-details-marker {
  display: none;
}

details.plan > summary::after {
  content: '▾';
  margin-left: 6px;
  font-size: 12px;
}

details.plan[open] > summary::after {
  content: '▴';
}

/* 明细列表 */
.day-group {
  margin-bottom: 6px;
}

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-faint);
  padding: 10px 2px 6px;
}

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-secondary);
  background: var(--bg-secondary);
  margin-bottom: 8px;
}

.expense-row:active {
  background: var(--bg-hover);
}

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

.expense-desc {
  font-size: 15px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-meta {
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-amount {
  flex: none;
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info);
  margin-left: 6px;
  vertical-align: 1px;
}

/* ── 底部导航 ───────────────────────────────────────────────────── */

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-elevated);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border-faint);
}

.tab {
  flex: 1;
  min-height: 48px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-faint);
}

.tab[aria-selected='true'] {
  color: var(--text-primary);
  background: var(--bg-selected);
}

.fab {
  flex: 1.4;
  min-height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 650;
}

.fab:active {
  background: var(--accent-hover);
}

/* ── 弹层 ───────────────────────────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-bottom: none;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-elevated);
}

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-primary);
  margin: 8px auto 12px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 650;
  margin: 0 0 14px;
}

.field {
  margin-bottom: 14px;
}

.field > label,
.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 7px;
  font-weight: 550;
}

.amount-input {
  font-size: 30px !important;
  font-weight: 650;
  text-align: center;
  padding: 14px !important;
  font-variant-numeric: tabular-nums;
}

.seg {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 4px;
}

.seg button {
  flex: 1;
  min-height: 38px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 550;
  color: var(--text-muted);
}

.seg button[aria-pressed='true'] {
  background: var(--bg-selected);
  color: var(--text-primary);
}

.split-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
}

.split-row .name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.split-row input {
  flex: none;
  width: 110px;
  padding: 9px 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.reconcile {
  font-size: 13px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.reconcile.ok {
  color: var(--success);
}
.reconcile.bad {
  color: var(--danger);
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0 0 12px;
  min-height: 0;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 50;
  max-width: calc(100vw - 32px);
  background: var(--bg-selected);
  border: 1px solid var(--border-primary);
  color: var(--text-primary);
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-elevated);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* 稍宽的屏幕上让统计块排成一行 */
@media (min-width: 480px) {
  .stat-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
