/* ============================================================
   收租台账 · 公共样式
   浅色主题，暖橙色主色。移动端优先（房东要在手机上抄表）。
   ============================================================ */

:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-2: #FCFBF9;
  --border: #E7E4DE;
  --border-2: #D6D2C9;

  --text: #2C2C2A;
  --text-2: #6B6862;
  --text-3: #9C988F;

  --primary: #E1701A;
  --primary-600: #C55F12;
  --primary-50: #FDF2E7;

  --danger: #C0392B;
  --danger-50: #FDECEA;
  --success: #2E7D46;
  --success-50: #E9F5EC;
  --warn: #A97400;
  --warn-50: #FDF6E3;
  --info: #2F6FA8;
  --info-50: #EAF2FA;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .05);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --nav-h: 58px;
}

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

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

a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ── 布局骨架 ─────────────────────────────────────────── */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.topbar .brand::before {
  content: ''; width: 8px; height: 8px; border-radius: 2px;
  background: var(--primary); display: block;
}
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-3); font-size: 12px; }

.body { flex: 1; display: flex; min-height: 0; }

.sidenav {
  width: 168px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidenav button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 11px;
  background: none; border: 0; border-radius: 8px;
  font: inherit; font-size: 13.5px; color: var(--text-2);
  text-align: left; cursor: pointer;
}
.sidenav button:hover { background: var(--bg); color: var(--text); }
.sidenav button.on { background: var(--primary-50); color: var(--primary-600); font-weight: 600; }
.sidenav .ico { width: 16px; text-align: center; opacity: .85; font-size: 13px; }

.main { flex: 1; min-width: 0; padding: 18px 20px 40px; }
.view { display: none; }
.view.on { display: block; }

/* ── 卡片 ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.card > h2 { margin-bottom: 4px; }
.card .sub { color: var(--text-3); font-size: 12.5px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { flex: none; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }

/* ── 统计块 ──────────────────────────────────────────── */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px;
}
.stat .k { color: var(--text-3); font-size: 12.5px; margin-bottom: 4px; }
.stat .v { font-size: 21px; font-weight: 600; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.stat .n { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.stat.danger .v { color: var(--danger); }
.stat.success .v { color: var(--success); }
.stat.warn .v { color: var(--warn); }

/* ── 表单 ────────────────────────────────────────────── */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
label.f .hint { color: var(--text-3); font-size: 11.5px; font-weight: 400; }

input, select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border-2); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
input:disabled { background: var(--bg); color: var(--text-3); }
textarea { resize: vertical; min-height: 68px; }
input.num { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-600); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #A33024; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.link { background: none; color: var(--primary); padding: 4px 6px; font-weight: 400; }
.btn.link:hover { background: var(--primary-50); }

/* ── 表格 ────────────────────────────────────────────── */
.tw { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-3); font-weight: 500; font-size: 12.5px; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--text-3); padding: 34px 10px; font-size: 13px; }

/* ── 徽标 ────────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.tag.paid { background: var(--success-50); color: var(--success); }
.tag.partial { background: var(--warn-50); color: var(--warn); }
.tag.unpaid { background: var(--danger-50); color: var(--danger); }
.tag.void { background: var(--bg); color: var(--text-3); }
.tag.gray { background: var(--bg); color: var(--text-2); }
.tag.info { background: var(--info-50); color: var(--info); }

/* ── 提示条 ──────────────────────────────────────────── */
.note {
  padding: 10px 13px; border-radius: 9px; font-size: 13px;
  border: 1px solid; margin-bottom: 12px;
}
.note.warn { background: var(--warn-50); border-color: #EBD9A8; color: #7A5400; }
.note.danger { background: var(--danger-50); border-color: #F0C4BE; color: #8E2B1F; }
.note.info { background: var(--info-50); border-color: #C6DCF0; color: #24557F; }
.note.success { background: var(--success-50); border-color: #BFDFC9; color: #245C36; }
.note b { font-weight: 600; }

/* ── 弹窗 ────────────────────────────────────────────── */
.mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(40, 38, 34, .38);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.mask[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-head h2 { flex: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.x {
  background: none; border: 0; font-size: 19px; line-height: 1;
  color: var(--text-3); cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.x:hover { background: var(--bg); color: var(--text); }

/* ── 吐司 ────────────────────────────────────────────── */
#toasts {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.toast {
  background: #2C2C2A; color: #fff;
  padding: 9px 16px; border-radius: 22px; font-size: 13.5px;
  box-shadow: var(--shadow); max-width: 88vw;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

/* ── 登录页 ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 372px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px 26px 24px; box-shadow: var(--shadow);
}
.login-card .logo {
  width: 42px; height: 42px; border-radius: 12px; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; font-weight: 600; margin-bottom: 15px;
}
.login-card h1 { margin-bottom: 4px; }
.login-card .sub { color: var(--text-3); font-size: 13px; margin-bottom: 22px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 15px; }

/* ── 抄表模式（移动端优先）────────────────────────────── */
.meter-head {
  position: sticky; top: 54px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 15px; margin-bottom: 12px;
}
.meter-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.meter-progress .bar { flex: 1; height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.meter-progress .bar i { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width .2s; }
.meter-progress .txt { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.meter-list { display: flex; flex-direction: column; gap: 9px; }
.meter-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 11px 13px;
}
.meter-row.done { border-color: #BFDFC9; background: var(--success-50); }
.meter-row .r1 { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.meter-row .room {
  font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums;
  min-width: 52px;
}
.meter-row .nm { color: var(--text-2); font-size: 13px; flex: 1; }
.meter-row .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.mf { }
.mf .lb {
  display: flex; align-items: baseline; gap: 5px;
  font-size: 12px; color: var(--text-3); margin-bottom: 3px;
}
.mf .lb b { color: var(--text-2); font-weight: 500; }
.mf input {
  padding: 10px 11px; font-size: 16px;
  font-variant-numeric: tabular-nums; font-weight: 500;
}
.mf .calc { font-size: 11.5px; color: var(--text-3); margin-top: 3px; min-height: 17px; }
.mf .calc b { color: var(--primary-600); font-weight: 600; }

/* ── 抽屉 ────────────────────────────────────────────── */
.drawer-mask { position: fixed; inset: 0; z-index: 60; background: rgba(40,38,34,.38); }
.drawer-mask[hidden] { display: none; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: 100%; max-width: 480px; background: var(--surface);
  box-shadow: -8px 0 30px rgba(0,0,0,.1);
  display: flex; flex-direction: column;
}
.drawer[hidden] { display: none; }
.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-3); font-size: 12.5px; }
.kv dd { margin: 0; }

.sec-title {
  font-size: 12.5px; color: var(--text-3); font-weight: 500;
  margin: 20px 0 9px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.sec-title:first-child { margin-top: 0; }

/* ── 时间线 ──────────────────────────────────────────── */
.tl { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 11px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.tl-item:last-child { border-bottom: 0; }
.tl-item .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary);
  margin-top: 7px; flex: none;
}
.tl-item .c { flex: 1; font-size: 13.5px; }
.tl-item .m { color: var(--text-3); font-size: 11.5px; }

/* ── 缩略图 ──────────────────────────────────────────── */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb {
  position: relative; width: 78px; height: 78px;
  border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
  background: var(--bg); cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .del {
  position: absolute; top: 2px; right: 2px;
  width: 19px; height: 19px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; border: 0;
  font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
}
.thumb.add {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); font-size: 22px; cursor: pointer;
}

.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.nowrap { white-space: nowrap; }
.big { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* 只在手机卡片布局里显示 / 只在电脑表格里显示 */
.rt-only { display: none; }

/* ── 移动端专用：底部导航「更多」弹层 ───────────────── */
.sheet-mask {
  position: fixed; inset: 0; z-index: 70; background: rgba(40, 38, 34, .38);
}
.sheet-mask[hidden] { display: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 8px 10px calc(12px + env(safe-area-inset-bottom));
}
.sheet .sh-title { text-align: center; color: var(--text-3); font-size: 12.5px; padding: 8px 0 12px; }
.sheet .sh-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.sheet .sh-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: none; border: 0; font: inherit; font-size: 12px;
  color: var(--text-2); padding: 12px 4px; border-radius: 12px; cursor: pointer;
}
.sheet .sh-grid button .ico {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}
.sheet .sh-grid button.on { color: var(--primary); font-weight: 600; }
.sheet .sh-grid button.on .ico { background: var(--primary-50); }
.sheet .sh-cancel { margin-top: 8px; }

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

@media (max-width: 760px) {
  .sidenav { display: none; }
  .main { padding: 13px 13px 92px; }
  .bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: var(--nav-h); background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav button {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: 0; font: inherit; font-size: 10.5px;
    color: var(--text-3); cursor: pointer; padding: 6px 2px;
  }
  .bottomnav button .ico { font-size: 17px; line-height: 1; }
  .bottomnav button.on { color: var(--primary); font-weight: 600; }
  .card { padding: 14px 14px; border-radius: 12px; }
  h1 { font-size: 17px; }
  .kv { grid-template-columns: 76px 1fr; }
  .meter-head { top: 54px; }

  /* 概览页这类「两栏卡片」在手机上必须竖排，否则文字挤成一团。
     统计块例外——两个一行反而更好读。 */
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, 1fr); }

  /* 搜索框占满整行，别跟按钮抢位置 */
  .search-in { width: 100% !important; flex: 1 1 100%; }

  /* ── 卡片化表格：手机上不再横着拖 ──
     每一行变成一张卡片，每个数字前面标出它是什么。
     最关键的数字和操作按钮不会再被推出屏幕外。 */
  .tw { overflow: visible; margin: 0; padding: 0; }
  .rt-only { display: inline; }
  .rt-hide { display: none !important; }
  table.rt thead { display: none; }
  table.rt, table.rt tbody { display: block; }
  table.rt tr {
    display: block; border: 1px solid var(--border); border-radius: 12px;
    padding: 11px 13px; margin-bottom: 9px; background: var(--surface);
  }
  table.rt tr:hover { background: var(--surface); }
  table.rt td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    border: 0; padding: 3px 0; white-space: normal; text-align: right;
  }
  table.rt td::before {
    content: attr(data-l); color: var(--text-3); font-size: 12.5px;
    flex: none; text-align: left; padding-top: 1px;
  }
  table.rt td.rt-h {
    justify-content: flex-start; text-align: left;
    font-size: 15.5px; font-weight: 600; padding-bottom: 8px;
    border-bottom: 1px dashed var(--border); margin-bottom: 7px;
  }
  table.rt td.rt-h::before { display: none; }
  table.rt td.act {
    justify-content: flex-end; gap: 8px;
    padding-top: 9px; margin-top: 8px; border-top: 1px dashed var(--border);
  }
  table.rt td.act::before { display: none; }
  table.rt td.act .btn { flex: 1 1 auto; }

  /* 弹窗在手机上全屏，否则小屏里表单被压得没法填 */
  .mask { padding: 0; align-items: stretch; }
  .modal {
    max-width: 100%; width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; display: flex; flex-direction: column;
  }
  .modal-body { flex: 1; overflow-y: auto; }
  .modal-head, .modal-foot { border-radius: 0; }
  .modal-foot .btn { flex: 1 1 auto; }

  .drawer { max-width: 100%; }

  /* 备忘录入这一行在手机上竖排，别把输入框挤没了 */
  .memo-add { flex-direction: column; align-items: stretch; }
  .memo-add > * { width: 100% !important; }
  /* 抽屉里的按钮拉宽一点，手指好点 */
  .drawer .row .btn { flex: 1 1 auto; }
}

@media (min-width: 761px) {
  .bottomnav, .sheet, .sheet-mask { display: none !important; }
}

/* 超窄屏（小屏安卓 / 老款 iPhone）再收一轮 */
@media (max-width: 380px) {
  .main { padding: 11px 10px 92px; }
  .card { padding: 12px 12px; }
  .stat .v { font-size: 19px; }
  .meter-row .fields { gap: 7px; }
  .sheet .sh-grid { grid-template-columns: repeat(3, 1fr); }
}
