/* ============================================================
   style.css —— 楼房共有出租结算系统（移动端优先）
   主色 #1e3a5f · 强调 #3498db · 成功 #27ae60 · 警告红 #e74c3c
   ============================================================ */

:root {
  --primary: #1e3a5f;
  --accent: #3498db;
  --success: #27ae60;
  --danger: #e74c3c;
  --warn: #e67e22;
  --bg: #f2f5f9;
  --card: #ffffff;
  --border: #e3e8ef;
  --text: #22303f;
  --text-sub: #6b7a8c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(30, 58, 95, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

/* ---------- 布局 ---------- */
#view {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 14px 14px 96px; /* 底部给移动端导航留空间 */
}
@media (min-width: 769px) {
  #view { padding: 22px 22px 48px; }
}

/* hidden 状态兜底（防止被布局规则覆盖） */
.topbar[hidden], .nav[hidden] { display: none !important; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  height: 52px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; color: #fff; }
.brand-short { display: none; }
.month-picker { display: flex; align-items: center; gap: 6px; margin-left: 4px; }
.month-picker label { font-size: 12px; color: rgba(255, 255, 255, 0.8); white-space: nowrap; }
.month-select {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  max-width: 130px;
}
.month-select option { color: var(--text); }
.user-area { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-logout:active { background: rgba(255, 255, 255, 0.28); }
@media (max-width: 768px) {
  .brand-full { display: none; }
  .brand-short { display: inline; }
  .month-picker label { display: none; }
}

/* ---------- 导航 ---------- */
.nav { background: var(--card); }

/* 桌面端：顶部横向导航 */
.nav-desktop {
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px 8px;
}
.nav-desktop .nav-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--text-sub);
  text-decoration: none;
  font-size: 14px;
}
.nav-desktop .nav-item.active {
  background: rgba(52, 152, 219, 0.12);
  color: var(--accent);
  font-weight: 600;
}

/* 移动端：底部固定导航 */
.nav-mobile {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--card);
  box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.07);
}
.nav-mobile .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0 6px;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 11px;
}
.nav-mobile .nav-item .nav-icon { font-size: 19px; line-height: 1.2; }
.nav-mobile .nav-item.active { color: var(--primary); font-weight: 600; }

@media (min-width: 769px) { .nav-mobile { display: none; } }
@media (max-width: 768px) { .nav-desktop { display: none; } }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  background: #e8edf3;
  color: var(--text);
  transition: filter 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { filter: brightness(0.93); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--primary); }
.btn-outline-danger { background: #fff; border: 1px solid #f0c4c9; color: var(--danger); }
.btn-muted { background: #e8edf3; color: var(--text-sub); }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: 16px; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.busy { pointer-events: none; }

/* ---------- 输入与表单 ---------- */
.input, select.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  min-height: 36px;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}
@media (max-width: 768px) {
  .input, select.input { font-size: 16px; } /* 防止 iOS 聚焦缩放 */
}
.field { display: block; }
.field-label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .field-wide { grid-column: 1 / -1; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }
.form-tip { font-size: 13px; color: var(--text-sub); margin-bottom: 12px; }
.open-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* ---------- 页面标题 ---------- */
.page-head { margin-bottom: 14px; }
.page-title { font-size: 20px; color: var(--primary); }
.page-sub { font-size: 13px; color: var(--text-sub); margin-top: 2px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; color: var(--primary); }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-success { background: rgba(39, 174, 96, 0.13); color: var(--success); }
.badge-warn { background: rgba(230, 126, 34, 0.13); color: var(--warn); }
.badge-danger { background: rgba(231, 76, 60, 0.13); color: var(--danger); }
.badge-info { background: rgba(52, 152, 219, 0.13); color: var(--accent); }
.badge-muted { background: #eef1f5; color: var(--text-sub); }

/* ---------- 表格 ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  margin-bottom: 12px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 620px;
}
.table th {
  background: #f6f8fb;
  color: var(--text-sub);
  font-weight: 600;
  text-align: left;
  padding: 9px 10px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid #f0f3f7;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafcfe; }
.table .input { min-width: 88px; padding: 6px 8px; }
.td-money { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.td-actions { white-space: nowrap; }
.td-actions .btn + .btn { margin-left: 6px; }
.td-note { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-main { font-weight: 600; color: var(--primary); }
.td-sub { font-size: 12px; color: var(--text-sub); }
.row-unpaid { background: #fdf1f1; }
.row-unpaid:hover { background: #fbeaea !important; }
.row-credit { background: #f0faf3; }
.row-debit { background: #fdf1f1; }

/* ---------- 工具栏与汇总条 ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.summary-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 4px;
  font-size: 14px;
}
.summary-bar .sum-warn { color: #ffd2c7; font-weight: 700; }
.summary-bar .sum-item { white-space: nowrap; }

/* ---------- 每月流程提示条 ---------- */
.flow-tip {
  background: #eef4fb;
  border-left: 4px solid var(--primary);
  color: #35506e;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0 12px;
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- 收费页分区块标题 ---------- */
.block-title {
  font-size: 15px;
  margin: 18px 0 6px;
  color: var(--primary);
}

/* ---------- 欠缴挂账卡片 ---------- */
.unpaid-card { border: 1px solid var(--danger); background: #fff8f6; }
.unpaid-head { font-size: 13px; font-weight: 700; color: var(--danger); margin: 6px 0 4px; }
.unpaid-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  background: #fff;
  margin: 3px 0;
  font-size: 14px;
}
.unpaid-name { color: #333; }
.unpaid-amount { font-weight: 700; color: var(--danger); }

/* ---------- 仪表盘 ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 768px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}
.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow: var(--shadow);
}
.metric-card.warn { border-color: #f2b8bd; background: #fdf6f6; }
.metric-icon { font-size: 22px; line-height: 1.3; }
.metric-label { font-size: 12px; color: var(--text-sub); }
.metric-value { font-size: 16px; font-weight: 700; color: var(--primary); margin-top: 2px; word-break: break-all; }
.metric-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.reminder-bar { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.reminder-item {
  background: #fef7e8;
  border: 1px solid #f3d9a4;
  color: #8a6116;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
}
.reminder-item:active { background: #fdf0d2; }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.shortcut-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 480px) { .shortcut-grid { grid-template-columns: repeat(2, 1fr); } }
.shortcut-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  background: #fff;
}
.shortcut-item:active { background: #f0f4f9; }
.shortcut-icon { font-size: 24px; }
.shortcut-label { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

/* ---------- 选项卡 ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: #e8edf3;
  padding: 4px;
  border-radius: 10px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-sub);
  font-family: inherit;
}
.tab-btn.active {
  background: #fff;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.seg { display: inline-flex; background: #e8edf3; border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-sub);
  font-family: inherit;
}
.seg-btn.active {
  background: #fff;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ---------- 提示与空状态 ---------- */
.note {
  background: #eef6fd;
  border-left: 3px solid var(--accent);
  color: #35506e;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 0 8px 8px 0;
  margin-bottom: 12px;
}
.empty { text-align: center; color: var(--text-sub); padding: 30px 10px; font-size: 14px; }
.center { text-align: center; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1e3a5f 0%, #2c5282 60%, #3498db 140%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
.login-brand { text-align: center; padding: 28px 20px 18px; background: var(--primary); color: #fff; }
.login-logo { font-size: 40px; line-height: 1; }
.login-title { font-size: 19px; margin-top: 10px; font-weight: 700; }
.login-sub { font-size: 12px; color: rgba(255, 255, 255, 0.75); margin-top: 6px; }
.login-body { padding: 22px; }
.login-body .field + .field { margin-top: 12px; }
.login-body .btn-block { margin-top: 18px; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(20, 30, 45, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 400px;
  padding: 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  max-height: 85vh;
  overflow-y: auto;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.modal-msg { font-size: 14px; color: var(--text); line-height: 1.65; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-form .field + .field { margin-top: 12px; }

/* ---------- Toast ---------- */
.toast-box {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: 92vw;
  pointer-events: none;
}
.toast {
  background: #22303f;
  color: #fff;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: #2c5282; }

/* ---------- 加载状态 ---------- */
.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 0;
  color: var(--text-sub);
  font-size: 14px;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(52, 152, 219, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 结算单 ---------- */
.settle-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
@media (max-width: 768px) {
  .settle-summary-grid { grid-template-columns: repeat(2, 1fr); }
}
.net-cell { font-weight: 700; }
.net-credit { color: var(--success); }
.net-debit { color: var(--danger); }
.transfer-card {
  background: linear-gradient(135deg, #fffdf4, #fff);
  border-color: #f0d9a0;
}
.transfer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: #fffdf5;
  border: 1px solid #f0dfb5;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 15px;
}
.transfer-item:last-child { margin-bottom: 0; }
.transfer-main { display: flex; align-items: center; flex-wrap: wrap; }
.transfer-name { font-weight: 700; color: var(--primary); font-size: 16px; }
.transfer-tag { color: var(--text-sub); margin: 0 2px; }
.transfer-amount { font-size: 18px; font-weight: 700; color: var(--warn); white-space: nowrap; }
.settle-action-card { text-align: center; padding: 26px 14px; }
.settle-action-card .note { text-align: left; }

/* ---------- 历史 ---------- */
.history-item { cursor: default; }
.history-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.history-ym { font-size: 18px; font-weight: 700; color: var(--primary); }
.history-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 10px;
}
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history-detail { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }

/* ---------- 开关 ---------- */
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #cbd5e1;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  vertical-align: middle;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch:checked { background: var(--success); }
.switch:checked::after { left: 22px; }

/* ---------- 打印（仅结算单区域） ---------- */
@media print {
  body.print-mode * { visibility: hidden !important; }
  body.print-mode .print-area,
  body.print-mode .print-area * { visibility: visible !important; }
  body.print-mode .print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  body.print-mode .print-btn,
  body.print-mode .topbar,
  body.print-mode .nav,
  body.print-mode .toast-box,
  body.print-mode .modal-overlay { display: none !important; }
  body.print-mode .table-wrap { overflow: visible; }
  body.print-mode .table { min-width: 0; font-size: 12px; }
}
