:root {
  color-scheme: light;
  --navy: #17477c;
  --navy-dark: #10375f;
  --blue-soft: #eaf2fb;
  --ink: #172332;
  --muted: #687384;
  --line: #dce3eb;
  --paper: #ffffff;
  --canvas: #f3f6f9;
  --green: #157347;
  --green-bg: #e7f6ee;
  --red: #b42318;
  --red-bg: #ffebe9;
  --amber: #9a5b00;
  --amber-bg: #fff3d6;
  --purple: #7130a8;
  --purple-bg: #f4eafe;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
#appView { position: relative; z-index: 0; }
body.modal-open { overscroll-behavior: none; }
body.modal-open #appView { pointer-events: none; }
.user-watermarks {
  position: fixed;
  inset: 0;
  z-index: 11000;
  pointer-events: none;
  user-select: none;
}
.user-watermark {
  position: absolute;
  transform: rotate(-16deg);
  color: rgba(23, 71, 124, .1);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  white-space: nowrap;
}
.watermark-top-left { top: max(78px, calc(env(safe-area-inset-top) + 16px)); left: 18px; }
.watermark-center { top: 58%; left: 50%; transform: translate(-50%, -50%) rotate(-16deg); }
.watermark-bottom-right { right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(155deg, #eef5fc 0%, #f8fafc 55%, #e5eef8 100%);
}
.login-card {
  width: min(100%, 390px);
  padding: 34px 28px;
  border: 1px solid rgba(23, 71, 124, .12);
  border-radius: 22px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 24px 70px rgba(23, 55, 91, .14);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 20px;
  border-radius: 15px;
  background: var(--navy);
  color: white;
  font-size: 24px;
  font-weight: 700;
}
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.login-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.login-card label, .filter-panel label { display: grid; gap: 7px; color: #415064; font-size: 13px; }
.login-card input, .login-card textarea, .filter-panel input, .filter-panel select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: white;
  padding: 0 12px;
  color: var(--ink);
  outline: none;
}
.login-card textarea { min-height: 82px; padding: 10px 12px; resize: vertical; }
.login-card form { display: grid; gap: 10px; }
.login-card input:focus, .login-card textarea:focus, .filter-panel input:focus, .filter-panel select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(23, 71, 124, .12);
}
.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  margin-top: 16px;
  border: 0;
  border-radius: 11px;
  background: var(--navy);
  color: white;
  font-weight: 700;
}
.button-link { text-decoration: none; }
.primary-button:active { background: var(--navy-dark); }
.form-error { min-height: 22px; margin-top: 12px; color: var(--red); font-size: 13px; text-align: center; }
.secondary-button { min-height: 38px; border: 1px solid #b9c8d8; border-radius: 9px; padding: 0 14px; background: white; color: var(--navy); }
.pending-panel { padding: 17px; border-radius: 12px; background: var(--blue-soft); color: var(--navy-dark); }
.pending-panel p { margin: 6px 0 14px; color: #49647f; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 16px max(20px, calc((100vw - 1100px) / 2));
  background: var(--navy);
  color: white;
}
.topbar h1 { margin: 1px 0 0; font-size: 22px; }
.eyebrow { color: #cfe1f4; font-size: 12px; letter-spacing: .18em; }
.text-button { border: 1px solid rgba(255,255,255,.45); border-radius: 9px; padding: 7px 13px; background: transparent; color: white; }

.filter-panel, .results-panel {
  width: min(calc(100% - 32px), 1100px);
  margin: 18px auto 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 4px 18px rgba(24, 43, 66, .04);
}
.filter-panel { padding: 18px; border-color: #17477c; background: linear-gradient(145deg, #10375f, #17477c); box-shadow: 0 8px 24px rgba(16, 55, 95, .18); }
.filter-panel label { min-width: 0; color: #dceafa; }
.filter-panel input, .filter-panel select { min-width: 0; border-color: rgba(255, 255, 255, .35); background: white; }
.filter-panel input::placeholder { color: #8492a4; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: 10px; margin-top: 13px; }
.search-row input { width: 100%; }
.clear-button { min-height: 42px; border: 1px solid rgba(255, 255, 255, .48); border-radius: 10px; background: rgba(255, 255, 255, .08); padding: 0 15px; color: #eef6ff; font-size: 13px; white-space: nowrap; }
.clear-button:hover { border-color: white; background: rgba(255, 255, 255, .14); color: white; }
.results-panel { margin-bottom: 30px; overflow: hidden; }
.results-panel.is-filter-loading .list-header,
.results-panel.is-filter-loading .resident-list,
.results-panel.is-filter-loading .load-more { opacity: .32; pointer-events: none; }
.loading-count { display: inline-flex; align-items: center; gap: 8px; }
.loading-count::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid #c5d1df;
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: filter-spin .7s linear infinite;
}
@keyframes filter-spin { to { transform: rotate(360deg); } }
.result-summary { display: grid; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.result-summary-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; }
.result-summary-main { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.result-summary strong { font-size: 16px; }
.result-summary-main span { color: var(--muted); font-size: 13px; }
.audit-log-button { flex: 0 0 auto; min-height: 30px; border: 1px solid #b9c8d8; border-radius: 8px; padding: 0 10px; background: white; color: var(--navy); font-size: 12px; font-weight: 700; white-space: nowrap; }
.audit-log-button:active { background: var(--blue-soft); }
.status-breakdown { display: flex; flex-wrap: wrap; gap: 6px; }
.status-breakdown .summary-chip { border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.list-header, .resident-row {
  display: grid;
  grid-template-columns: minmax(84px, .8fr) minmax(110px, 1.5fr) minmax(112px, .8fr);
  align-items: center;
  gap: 12px;
}
.list-header { padding: 11px 18px; background: #f7f9fb; color: var(--muted); font-size: 12px; }
.resident-row {
  width: 100%;
  min-height: 62px;
  padding: 11px 18px;
  border: 0;
  border-top: 1px solid #edf1f5;
  background: white;
  color: var(--ink);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.resident-row:first-child { border-top: 0; }
.resident-row:hover, .resident-row:active, .resident-row:focus { background: white; }
.resident-row:focus-visible { outline: 2px solid var(--navy); outline-offset: -2px; }
.room-cell { color: var(--navy-dark); font-weight: 700; }
.name-cell { line-height: 1.45; }
.status-pill { justify-self: start; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-voted { background: var(--green-bg); color: var(--green); }
.status-unvoted { background: var(--red-bg); color: var(--red); }
.status-contacted { background: var(--amber-bg); color: var(--amber); }
.status-opposed { background: var(--purple-bg); color: var(--purple); }
.empty-state { padding: 54px 20px; color: var(--muted); text-align: center; }
.load-more { display: block; width: calc(100% - 36px); margin: 14px 18px 18px; min-height: 42px; border: 1px solid #b9c8d8; border-radius: 10px; background: white; color: var(--navy); }

.modal { position: fixed; inset: 0; z-index: 10000; isolation: isolate; transform: translateZ(0); display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; z-index: 0; width: 100%; border: 0; background: rgba(11, 22, 35, .54); }
.modal-sheet { position: relative; z-index: 1; width: min(100%, 470px); max-height: 90vh; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; border-radius: 20px; background: white; padding: 30px 24px 24px; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal-handle { display: none; }
.close-button { position: absolute; top: 12px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eef2f6; color: #536174; font-size: 25px; line-height: 1; }
.detail-room { margin: 0 0 4px; color: var(--navy); font-size: 14px; font-weight: 700; }
.modal-sheet h2 { margin: 0; padding-right: 38px; font-size: 23px; line-height: 1.35; }
.detail-address { margin: 6px 38px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.detail-section { margin-top: 24px; }
.detail-section h3 { margin: 0 0 10px; color: var(--muted); font-size: 13px; font-weight: 600; }
.phone-list { display: grid; gap: 9px; }
.phone-link { display: flex; align-items: center; justify-content: space-between; min-height: 48px; border-radius: 11px; padding: 0 14px; background: var(--blue-soft); color: var(--navy-dark); font-size: 18px; font-weight: 700; text-decoration: none; }
.phone-link::after { content: "拨打"; font-size: 13px; font-weight: 600; }
.no-phone { color: var(--muted); font-size: 14px; }
.status-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.status-option { min-height: 46px; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); text-align: left; padding: 0 14px; }
.status-option.active { border-color: var(--navy); background: var(--blue-soft); color: var(--navy-dark); font-weight: 700; }
.status-option.active.status-unvoted { border-color: #e2a39d; background: var(--red-bg); color: var(--red); }
.status-option.active.status-voted { border-color: #83c3a2; background: var(--green-bg); color: var(--green); }
.status-option.active.status-contacted { border-color: #dfba72; background: var(--amber-bg); color: var(--amber); }
.status-option.active.status-opposed { border-color: #c7a2e7; background: var(--purple-bg); color: var(--purple); }
.status-option:disabled { opacity: .55; }
.save-message { min-height: 21px; margin-top: 8px; color: var(--green); font-size: 13px; }
.remark-label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13px; font-weight: 600; }
.remark-input { display: block; width: 100%; min-height: 88px; resize: vertical; border: 1px solid #cbd5e1; border-radius: 11px; padding: 11px 12px; background: white; color: var(--ink); line-height: 1.55; outline: none; }
.remark-input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(23, 71, 124, .12); }
.remark-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.remark-actions .save-message { flex: 1; }
.remark-save { min-height: 38px; border: 0; border-radius: 9px; padding: 0 15px; background: var(--navy); color: white; font-weight: 700; }
.remark-save:disabled { opacity: .55; }
.history-section { padding-top: 2px; border-top: 1px solid var(--line); }
.history-list { display: grid; gap: 9px; }
.history-item { padding: 11px 12px; border-radius: 10px; background: #f7f9fb; }
.history-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.history-meta strong { color: var(--navy-dark); font-size: 13px; }
.history-meta time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.history-item p { margin: 6px 0 0; color: #415064; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.history-empty, .history-loading { margin: 0; padding: 8px 0; color: var(--muted); font-size: 13px; }
.audit-sheet { width: min(100%, 560px); }
.audit-count { margin: 6px 0 18px; color: var(--muted); font-size: 12px; }
.audit-list { gap: 10px; }
.audit-load-more { width: 100%; margin: 16px 0 0; }
.history-item .audit-household { margin: 5px 0 0; color: var(--navy-dark); font-size: 12px; font-weight: 700; }

.admin-main { width: min(calc(100% - 32px), 980px); margin: 20px auto 40px; }
.admin-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.admin-summary div { display: grid; gap: 5px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.admin-summary strong { color: var(--navy-dark); font-size: 28px; }
.admin-summary span { color: var(--muted); font-size: 13px; }
.admin-panel { margin-top: 16px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.admin-panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.admin-panel-title h2 { margin: 0; font-size: 19px; }
.user-list { display: grid; gap: 10px; }
.user-card { padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfe; }
.user-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.user-card h3 { margin: 0; font-size: 17px; }
.user-card p { margin: 10px 0 8px; color: #445266; }
.user-meta { color: var(--muted); font-size: 12px; }
.admin-status { border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.admin-status-pending { background: var(--amber-bg); color: var(--amber); }
.admin-status-approved { background: var(--green-bg); color: var(--green); }
.admin-status-rejected { background: #edf0f3; color: #5d6876; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.user-action { min-height: 36px; border: 1px solid #c6d0db; border-radius: 9px; padding: 0 13px; background: white; color: #425167; }
.user-action.approve { border-color: #9acdb1; background: var(--green-bg); color: var(--green); }
.user-action.reject { border-color: #e8b5b1; background: var(--red-bg); color: var(--red); }

@media (max-width: 640px) {
  .topbar { min-height: 72px; padding: 12px 16px; }
  .filter-panel, .results-panel { width: 100%; margin-top: 0; border-width: 0 0 1px; border-radius: 0; box-shadow: none; }
  .filter-panel { padding: 12px 10px 10px; position: sticky; top: 0; z-index: 5; }
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .filter-grid label:last-child { grid-column: auto; }
  .filter-panel label { gap: 5px; font-size: 11px; }
  .filter-panel input { min-height: 40px; font-size: 14px; }
  .filter-panel select { min-height: 38px; padding: 0 6px; font-size: 12px; }
  .search-row { gap: 7px; margin-top: 9px; }
  .clear-button { min-height: 40px; padding: 0 11px; font-size: 12px; }
  .results-panel { margin-bottom: 0; }
  .result-summary { padding: 12px 14px; }
  .status-breakdown { width: 100%; }
  .list-header, .resident-row { grid-template-columns: 76px minmax(90px, 1fr) 104px; gap: 8px; }
  .list-header { padding: 10px 14px; }
  .resident-row { padding: 11px 14px; }
  .modal { place-items: end center; padding: 0; }
  .modal-sheet { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; padding: 28px 20px calc(22px + env(safe-area-inset-bottom)); }
  .modal-handle { display: block; width: 42px; height: 4px; margin: -17px auto 19px; border-radius: 999px; background: #cbd3dc; }
  .admin-main { width: 100%; margin: 0; padding: 14px; }
  .admin-summary { gap: 8px; }
  .admin-summary div { padding: 13px; }
  .admin-summary strong { font-size: 23px; }
  .admin-panel { padding: 14px; border-radius: 14px; }
}
