/* style.css — 公寓房租水电记账工具 */
* { box-sizing: border-box; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #475569;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 10px;
}
html, body { margin: 0; padding: 0; }
/* 始终保留纵向滚动条位置，避免切换页签时页面左右跳动 */
html { overflow-y: scroll; scrollbar-gutter: stable; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
.topbar {
  background: #0f172a;
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; color: #cbd5e1;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.tab.active { background: var(--primary); color: #fff; }
.main { max-width: 1180px; margin: 18px auto; padding: 0 16px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card h3 { margin: 14px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; min-width: 100px; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }

button.btn {
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  padding: 8px 16px; border-radius: 8px; font-size: 14px;
  white-space: nowrap;
}
button.btn:hover { background: var(--primary-dark); }
button.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.btn.ghost:hover { background: #f8fafc; }
button.btn.danger { background: #fff; color: var(--err); border: 1px solid #fecaca; }
button.btn.danger:hover { background: #fef2f2; }
button.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 7px 9px; text-align: center; }
table.grid th { background: #f8fafc; font-weight: 600; }
table.grid tr:hover td { background: #f8fafc; }
table.grid tr.vacant td { background: #fffbeb; }

/* 入住情况看板 */
.occ-legend { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.occ-legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.occ-legend .dot.ok { background: #dcfce7; border: 1px solid #86efac; }
.occ-legend .dot.warn { background: #fef3c7; border: 1px solid #fcd34d; }
.occ-group { margin-bottom: 16px; }
.occ-group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.occ-group-head b { font-size: 15px; }
.occ-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.occ-tile {
  border-radius: 10px; padding: 10px 12px; border: 1px solid var(--border);
  min-height: 62px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  background: #fff;
}
.occ-tile.occupied { background: #f0fdf4; border-color: #bbf7d0; }
.occ-tile.vacant { background: #fffbeb; border-color: #fde68a; }
.occ-tile .occ-no { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.occ-tile.occupied .occ-no { color: #15803d; }
.occ-tile.vacant .occ-no { color: #92400e; }
.occ-tile .occ-who { font-size: 12px; color: var(--muted); margin-top: 2px; }
.occ-tile.vacant .occ-who { color: #b45309; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; }
.pill.ok { background: #dcfce7; color: #15803d; }
.pill.warn { background: #fef3c7; color: #92400e; }
.pill.err { background: #fee2e2; color: #b91c1c; }
.pill.info { background: #e0f2fe; color: #0369a1; }

.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-card { flex: 1; min-width: 160px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.stat-card .label { font-size: 13px; color: var(--muted); }
.cell-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.floor-card { border-left: 4px solid var(--primary); }

/* 公寓选项卡导航 */
.apt-tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.apt-tab {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 16px; cursor: pointer; font-size: 14px; color: var(--text);
}
.apt-tab:hover { background: #f8fafc; }
.apt-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.reading-sm {
  width: 110px; padding: 7px 8px; font-size: 16px; font-weight: 700; text-align: center;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.reading-sm:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }
.reading-sm.warn { border-color: #f59e0b; background: #fffbeb; }
.reading-sm.err { border-color: #dc2626; background: #fef2f2; }
.meter-warn { font-size: 12px; margin-top: 2px; min-height: 16px; }
.est-fill { cursor: pointer; }
.est-fill:hover { color: var(--primary); text-decoration: underline; }
.meter-warn.warn { color: #92400e; }
.meter-warn.err { color: #b91c1c; }
.small { font-size: 13px; }

/* ---------- 文本识别 ---------- */
textarea#textInput {
  width: 100%; min-height: 150px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: Consolas, Menlo, monospace; line-height: 1.7;
  background: #fff; color: var(--text); box-sizing: border-box;
}
textarea#textInput:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }

/* ---------- 走势图 ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100%; height: 300px; display: block; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend-btn { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 3px 12px; font-size: 13px; cursor: pointer; line-height: 1.4; }
.legend-btn:hover { background: #f8fafc; }
.legend-btn.off { opacity: .35; text-decoration: line-through; }

/* ---------- 收据卡片 ---------- */
.receipt-card { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.rc-preview { cursor: zoom-in; line-height: 0; }
.rc-preview:hover canvas { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.receipt-preview { width: 220px; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.rc-info { flex: 1; min-width: 220px; }
.rc-title { font-size: 15px; }
.rc-btns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- 收据预览弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal.hidden { display: none; }
body.modal-open { overflow: hidden; }
.modal-box {
  background: #fff; border-radius: 12px; max-width: 900px; width: 100%;
  max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { overflow: auto; padding: 14px; text-align: center; background: #f8fafc; }
.modal-body canvas { max-width: 100%; height: auto; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(80px);
  background: #0f172a; color: #fff; padding: 10px 20px; border-radius: 999px;
  opacity: 0; transition: all .25s; z-index: 99; font-size: 14px; pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 80vw;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.spacer { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

@media (max-width: 720px) {
  .cell-list { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .field input, .field select { min-width: 0; }
}

/* ---------- 登录 ---------- */
.app-shell.hidden { display: none; }

.login-screen {
  position: fixed; inset: 0; background: #f1f5f9;
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.login-screen.hidden { display: none; }
.login-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 30px 28px; width: 320px; max-width: 100%;
  box-shadow: 0 12px 40px rgba(15,23,42,.1); text-align: center;
}
.login-card .login-logo { font-size: 42px; }
.login-card h1 { font-size: 22px; margin: 6px 0 2px; }
.login-card .field { text-align: left; margin-top: 12px; }
.login-card input { width: 100%; }
.login-card .btn { margin-top: 14px; width: 100%; }
.login-err { color: var(--err); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---------- 顶栏用户区 ---------- */
.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.topbar-user.hidden { display: none; }
.login-info { font-size: 13px; color: #cbd5e1; white-space: nowrap; }

/* ---------- 页签隐藏（按角色） ---------- */
.tab.hidden { display: none; }

/* ---------- 焦点可见性（键盘可达） ---------- */
.tab:focus-visible, .apt-tab:focus-visible, button.btn:focus-visible,
.legend-btn:focus-visible, a:focus-visible, select:focus-visible,
input:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .65);
  outline-offset: 2px;
}

/* ---------- 尺寸 / 间距工具类 ---------- */
.w-36 { width: 36px; } .w-60 { width: 60px; } .w-64 { width: 64px; }
.w-70 { width: 70px; } .w-80 { width: 80px; } .w-90 { width: 90px; }
.w-100 { width: 100px; } .w-110 { width: 110px; } .w-130 { width: 130px; }
.w-140 { width: 140px; } .w-150 { width: 150px; }
.mt-6 { margin-top: 6px; } .mt-8 { margin-top: 8px; } .mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; } .mt-14 { margin-top: 14px; }
.mb-4 { margin-bottom: 4px; } .mb-8 { margin-bottom: 8px; }
.ml-6 { margin-left: 6px; }
.my-4 { margin: 4px 0; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; }
.self-end { align-self: flex-end; }
.val-ok { color: var(--ok); } .val-err { color: var(--err); }

/* ---------- 内联 SVG 图标 ---------- */
.ic { display: inline-block; vertical-align: -2px; margin-right: 4px; flex: none; }
button .ic { vertical-align: -3px; }
.empty .big svg { display: block; margin: 0 auto 8px; }

/* ---------- 移动端：页签横向滑动，避免挤成多行 ---------- */
@media (max-width: 720px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: thin; }
  .tabs::-webkit-scrollbar { height: 4px; }
  .tab { flex: 0 0 auto; }
}
