/* PairPay - 双人记账样式 */

:root {
  --primary: #e85d75;
  --primary-dark: #c94560;
  --secondary: #1da79a;
  --accent: #f6b84f;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf6;
  --text: #263238;
  --text-secondary: #68727a;
  --muted: #8c969d;
  --border: #e5e1d8;
  --shadow: 0 14px 36px rgba(32, 45, 48, 0.1);
  --shadow-soft: 0 8px 22px rgba(32, 45, 48, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: #e9ece2;
}

body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(232, 93, 117, 0.16), transparent 34rem),
    radial-gradient(circle at top right, rgba(29, 167, 154, 0.16), transparent 30rem),
    linear-gradient(180deg, #fbfaf6 0%, var(--bg) 42%, #eef2ea 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: block;
}

/* 登录页 */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
}

.brand-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #f07f59 52%, var(--accent));
  box-shadow: 0 18px 34px rgba(232, 93, 117, 0.28);
  font-size: 32px;
  font-weight: 900;
}

.logo {
  text-align: center;
  font-size: 40px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
  color: var(--text);
}

.subtitle {
  margin: 12px 0 32px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
}

.login-form {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 22px;
  border: 1px solid rgba(229, 225, 216, 0.78);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.input-group {
  margin-bottom: 18px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.input-group input,
.input-group select,
.filter-bar input,
.filter-bar select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text);
  background: var(--surface);
  font-size: 15px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
}

.input-group input::placeholder {
  color: #a0a7ad;
}

.input-group input:focus,
.input-group select:focus,
.filter-bar input:focus,
.filter-bar select:focus {
  border-color: rgba(232, 93, 117, 0.72);
  box-shadow: 0 0 0 4px rgba(232, 93, 117, 0.12);
  background: #fff;
}

.input-group select,
.filter-bar select {
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath fill='%2368727a' d='M7 10.2 2.3 5.5l1-1L7 8.1l3.7-3.6 1 1z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.hint {
  margin-top: 15px;
  color: var(--text-secondary);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}

/* 按钮 */
.btn-primary {
  width: 100%;
  min-height: 50px;
  padding: 13px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #f47a57);
  box-shadow: 0 12px 22px rgba(232, 93, 117, 0.24);
  font-size: 16px;
  font-weight: 800;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  -webkit-appearance: none;
}

.btn-primary:hover {
  filter: brightness(1.02);
}

.btn-primary:active,
.btn-add:active,
.btn-icon:active,
.payer-btn:active,
.split-btn:active,
.btn-secondary:active {
  transform: translateY(1px) scale(0.99);
}

.btn-secondary {
  min-height: 48px;
  padding: 12px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface-soft);
  font-size: 15px;
  font-weight: 700;
}

.btn-icon,
.btn-close {
  display: grid;
  place-items: center;
  border: 1px solid rgba(229, 225, 216, 0.8);
  color: var(--text);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-size: 18px;
}

.btn-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
}

.btn-row {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 12px;
}

/* 顶部栏 */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  border-bottom: 1px solid rgba(229, 225, 216, 0.72);
  background: rgba(251, 250, 246, 0.88);
  backdrop-filter: blur(18px);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-info > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
}

#current-user {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 800;
}

.avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 24px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* 欠款卡片 */
.balance-card {
  position: relative;
  margin: 16px;
  padding: 22px 18px 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 22px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(232, 93, 117, 0.98), rgba(244, 122, 87, 0.95) 54%, rgba(246, 184, 79, 0.95)),
    #e85d75;
  box-shadow: 0 22px 38px rgba(232, 93, 117, 0.28);
}

.balance-card::before,
.balance-card::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.balance-card::before {
  width: 170px;
  height: 170px;
  right: -70px;
  top: -80px;
}

.balance-card::after {
  width: 120px;
  height: 120px;
  left: -56px;
  bottom: -70px;
}

.balance-content,
.balance-summary {
  position: relative;
  z-index: 1;
}

.balance-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.balance-person {
  min-width: 0;
  text-align: center;
}

.balance-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 7px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 27px;
}

.balance-name {
  display: block;
  margin-bottom: 5px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-amount {
  display: block;
  font-size: 25px;
  font-weight: 900;
  line-height: 1.1;
}

.balance-label {
  display: inline-block;
  margin-top: 7px;
  padding: 4px 8px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
  font-weight: 700;
}

.balance-divider {
  text-align: center;
}

.balance-status {
  min-width: 54px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.17);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.balance-summary {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.15);
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
}

/* 快捷操作 */
.quick-actions {
  padding: 0 16px;
  margin-bottom: 14px;
}

.btn-add {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(232, 93, 117, 0.2);
  border-radius: 16px;
  color: var(--primary-dark);
  background: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 16px;
  font-weight: 900;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-add span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: var(--primary);
  line-height: 1;
}

/* 标签页 */
.tabs {
  position: sticky;
  top: calc(65px + env(safe-area-inset-top, 0px));
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 16px;
  padding: 6px;
  border: 1px solid rgba(229, 225, 216, 0.76);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  color: var(--text-secondary);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.tab.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 8px 16px rgba(32, 45, 48, 0.08);
}

.tab-content {
  display: none;
  padding: 16px;
  padding-bottom: calc(88px + var(--safe-bottom));
}

.tab-content.active {
  display: block;
}

/* 筛选栏 */
.filter-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.filter-bar input,
.filter-bar select {
  min-height: 44px;
  font-size: 14px;
}

/* 记录列表 */
.records-list,
.history-list,
.category-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.record-item,
.stat-card,
.cat-stat-item,
.history-item {
  border: 1px solid rgba(229, 225, 216, 0.74);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 15px;
  border-left: 5px solid var(--secondary);
}

.record-item.paid-by-me {
  border-left-color: var(--primary);
}

.record-item.paid-by-partner {
  border-left-color: var(--secondary);
}

.record-left,
.record-right {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.record-category {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 900;
}

.record-note {
  min-height: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.record-right {
  align-items: flex-end;
  text-align: right;
}

.record-amount {
  color: var(--primary-dark);
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
}

.record-payer {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.record-date {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.record-receipt {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 6px 10px;
  border-radius: 999px;
  color: #0b7f75;
  background: rgba(29, 167, 154, 0.1);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

/* 统计 */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 18px 14px;
  text-align: center;
}

.stat-value {
  color: var(--primary-dark);
  font-size: 27px;
  line-height: 1.1;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.stat-label {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 800;
}

.cat-stat-item {
  padding: 14px;
}

.cat-stat-header,
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.cat-stat-header {
  margin-bottom: 10px;
}

.cat-stat-name {
  min-width: 0;
  font-size: 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.cat-stat-amount {
  flex-shrink: 0;
  color: var(--primary-dark);
  font-weight: 900;
}

.cat-stat-bar {
  height: 8px;
  margin-bottom: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece8df;
}

.cat-stat-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.45s ease;
}

.cat-stat-pct {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* 历史 */
.history-item {
  padding: 16px;
}

.history-header {
  margin-bottom: 9px;
}

.history-date {
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
}

.history-total {
  flex-shrink: 0;
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 900;
}

.history-summary,
.history-note {
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.45;
}

.history-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* 空状态 */
.empty-state {
  padding: 42px 20px;
  border: 1px dashed rgba(140, 150, 157, 0.34);
  border-radius: var(--radius);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.56);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
}

/* 模态框 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(23, 32, 35, 0.42);
  backdrop-filter: blur(8px);
}

.modal.active {
  display: flex;
}

.modal-content {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 42px rgba(23, 32, 35, 0.18);
  animation: slideUp 0.28s ease;
}

.modal-content.image-modal {
  margin: 16px;
  border-radius: 22px;
  max-height: 82vh;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 900;
}

.modal-body {
  padding: 18px;
}

.modal-body img {
  width: 100%;
  border-radius: var(--radius-sm);
}

/* 付款人与分摊切换 */
.payer-toggle,
.split-toggle {
  display: grid;
  gap: 10px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-soft);
}

.payer-toggle {
  grid-template-columns: 1fr 1fr;
}

.split-toggle {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.payer-btn,
.split-btn {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  color: var(--text-secondary);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  transition: transform 0.15s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.payer-btn.active,
.split-btn.active {
  color: var(--primary-dark);
  background: #fff;
  box-shadow: 0 8px 16px rgba(32, 45, 48, 0.08);
}

.custom-split {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.custom-split.active {
  display: grid;
}

.custom-split label {
  color: var(--text-secondary);
  font-size: 12px;
}

.custom-split input {
  min-height: 42px;
  margin-top: 5px;
}

.record-split {
  width: fit-content;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 999px;
  color: #8a5c09;
  background: rgba(246, 184, 79, 0.14);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

/* 小票上传 */
.receipt-upload {
  margin-top: 4px;
}

.receipt-upload input[type="file"] {
  display: none;
}

.receipt-label {
  display: block;
  padding: 16px;
  border: 1px dashed rgba(29, 167, 154, 0.42);
  border-radius: var(--radius-sm);
  color: #0b7f75;
  background: rgba(29, 167, 154, 0.07);
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.receipt-label:active {
  border-color: var(--secondary);
  background: rgba(29, 167, 154, 0.12);
}

.receipt-preview {
  margin-top: 10px;
}

.receipt-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

/* 结算弹窗 */
#settle-text {
  margin-bottom: 14px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
}

.settle-summary {
  margin-bottom: 16px;
  padding: 13px 14px;
  border: 1px solid rgba(246, 184, 79, 0.34);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(246, 184, 79, 0.1);
  font-size: 14px;
  line-height: 1.7;
}

.settle-result {
  margin-top: 5px;
  color: var(--primary-dark);
  font-weight: 900;
}

/* Toast */
.toast {
  position: fixed;
  top: calc(58px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 200;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -6px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
}

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

.toast-success {
  background: #1da779;
}

.toast-error {
  background: #d94f50;
}

.toast-info {
  background: #2878bd;
}

@media (max-width: 380px) {
  .balance-card {
    margin-inline: 12px;
    padding-inline: 14px;
  }

  .balance-content {
    gap: 7px;
  }

  .balance-amount {
    font-size: 20px;
  }

  .balance-avatar {
    width: 42px;
    height: 42px;
    font-size: 24px;
  }

  .tabs {
    margin-inline: 12px;
  }

  .tab-content,
  .quick-actions {
    padding-inline: 12px;
  }
}

@media (min-width: 700px) {
  body {
    padding: 18px 0;
  }

  #app {
    min-height: calc(100vh - 36px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(32, 45, 48, 0.16);
  }

  .login-container,
  .page {
    min-height: calc(100vh - 36px);
  }
}
