:root {
  --ink: #1a2332;
  --ink-soft: #2c3a4e;
  --paper: #f4efe6;
  --paper-2: #ebe4d6;
  --card: #fffdf8;
  --copper: #c4784a;
  --copper-deep: #9a5a34;
  --line: rgba(26, 35, 50, 0.1);
  --muted: #6b6258;
  --ok: #2d6a4f;
  --danger: #9b2335;
  --shadow: 0 18px 40px rgba(26, 35, 50, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Noto Sans SC", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(196, 120, 74, 0.08), transparent 50%),
    var(--paper);
  color: var(--ink);
}
button, input, select { font-family: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.serif { font-family: "Noto Serif SC", serif; }
.num { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  position: relative;
}
.login-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 6px;
  background: var(--copper);
}
.stamp {
  position: absolute;
  right: 22px;
  top: 22px;
  border: 2px solid var(--danger);
  color: var(--danger);
  padding: 4px 8px;
  font-size: 12px;
  transform: rotate(12deg);
  opacity: 0.7;
  letter-spacing: 0.2em;
}
.brand-mark {
  width: 42px; height: 42px;
  border: 1.5px solid var(--copper);
  display: grid; place-items: center;
  color: var(--copper);
  margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: 28px; }
.sub { color: var(--muted); margin: 0 0 28px; font-size: 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 16px; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
input:focus, select:focus { border-color: var(--copper); }
.btn {
  border: 0;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  font-size: 15px;
}
.btn:hover { background: var(--ink-soft); }
.btn.copper { background: var(--copper); }
.btn.copper:hover { background: var(--copper-deep); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.danger { background: var(--danger); }
.btn.full { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; }
.error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 8px 0; }
.drop {
  border: 1.5px dashed var(--line);
  padding: 28px 20px;
  text-align: center;
  background: #fff;
}
.drop label.btn { display: inline-block; position: relative; overflow: hidden; }
.drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
}
.import-summary { margin-top: 16px; text-align: left; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--ink);
  color: #e8e2d6;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
}
.side .logo {
  padding: 0 10px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 18px;
}
.side .logo strong { display: block; font-size: 18px; }
.side .logo span { color: #9aa3b2; font-size: 12px; }
.nav-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #c9c3b8;
  border: 0;
  padding: 12px 12px;
  margin-bottom: 4px;
}
.nav-btn.active, .nav-btn:hover {
  background: rgba(196, 120, 74, 0.16);
  color: #fff;
}
.side-foot {
  margin-top: auto;
  padding: 16px 10px 0;
  font-size: 12px;
  color: #9aa3b2;
}
.side-foot b { color: #fff; display: block; font-size: 14px; margin-bottom: 4px; }

.main { padding: 28px 32px 48px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
  gap: 12px;
}
.topbar h2 { margin: 0; font-size: 26px; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.result-phone {
  font-size: 28px;
  letter-spacing: 0.12em;
  margin: 8px 0 0;
}
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.admin { color: var(--copper-deep); border-color: var(--copper); }
.badge.mp { color: #355c7d; }
.badge.web { color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.empty { color: var(--muted); padding: 28px 8px; text-align: center; }

.modal-mask {
  position: fixed; inset: 0;
  background: rgba(26, 35, 50, 0.45);
  display: grid; place-items: center;
  padding: 16px;
  z-index: 20;
}
.modal {
  width: min(480px, 100%);
  background: var(--card);
  padding: 24px;
  border: 1px solid var(--line);
}
.qr {
  width: 220px; height: 220px;
  display: block;
  margin: 12px auto;
  background: #fff;
}
.code-box {
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.18em;
  margin: 8px 0 12px;
}
.ok { color: var(--ok); }

/* ═══ SHEET CARD ═══ */
.sheet-card { overflow: hidden; }

/* 小区分表页签 */
.sheet-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  padding: 0 0 8px; border-bottom: 2px solid var(--line);
}
.sheet-tab {
  border: 1px solid var(--line); border-bottom: none;
  background: #f3eee4; color: var(--muted);
  padding: 7px 16px; font-size: 13px;
  border-radius: 6px 6px 0 0; margin-bottom: -2px;
}
.sheet-tab:hover { background: #ece4d6; color: var(--ink); }
.sheet-tab.on {
  background: #fff; color: var(--copper-deep); font-weight: 600;
  border-color: var(--line); border-bottom: 2px solid #fff;
}

/* toolbar (stb = sheet toolbar) */
.stb {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.stb:last-of-type { border-bottom: none; margin-bottom: 8px; }
.stb select, .stb-search { width: auto; min-width: 100px; padding: 5px 8px; font-size: 12px; border: 1px solid var(--line); border-radius: 4px; }
.stb-search { min-width: 160px; }
.stb-sel { width: auto; min-width: 60px; padding: 4px 6px; font-size: 12px; }
.stb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }
.stb-color { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 600; cursor: pointer; }
.stb-color input[type="color"] { width: 24px; height: 22px; padding: 0; border: 1px solid var(--line); cursor: pointer; }
.swatch { width: 16px; height: 16px; border: 1px solid var(--line); padding: 0; cursor: pointer; font-size: 9px; line-height: 16px; text-align: center; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn.copper { background: var(--copper); color: #fff; }
.btn.copper:hover { opacity: .85; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--body); padding: 3px 8px; font-size: 12px; }
.btn.ghost:hover { background: #f3eee4; }

/* table */
.sheet-wrap {
  overflow: auto;
  max-height: calc(100vh - 360px);
  position: relative;
  border: 1px solid var(--line);
  background: #fff;
}
.sheet-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 248, 0.82);
  color: var(--muted);
  font-size: 14px;
}
.sheet-table tr.v-spacer td { border: none !important; padding: 0 !important; }
.sheet-table {
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  table-layout: fixed;
}
.sheet-table th, .sheet-table td { border: 1px solid #eadfce; padding: 0; font-size: 13px; overflow: hidden; box-sizing: border-box; }
.sheet-table th {
  background: #f3eee4;
  padding: 0 8px;
  height: 34px;
  line-height: 34px;
  user-select: none;
  white-space: nowrap;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 #eadfce;
}
.sheet-table th .th-label { display: inline-block; vertical-align: middle; line-height: normal; }
.sheet-table tbody tr:not(.v-spacer) {
  height: 34px;
  max-height: 34px;
}
.sheet-table tbody tr:not(.v-spacer) td {
  height: 34px;
  max-height: 34px;
  vertical-align: middle;
  overflow: hidden;
}
.sheet-table td.gutter, .sheet-table th.gutter {
  width: 36px; min-width: 36px; max-width: 36px;
  text-align: center; background: #f7f2e9; color: var(--muted);
  cursor: pointer; user-select: none; font-size: 11px;
  position: sticky;
  left: 0;
  z-index: 2;
  box-shadow: 1px 0 0 #eadfce;
}
.sheet-table th.gutter {
  z-index: 4;
  background: #f3eee4;
}
.sheet-table th.col-sticky-left,
.sheet-table td.col-sticky-left {
  position: sticky;
  left: 36px;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 #eadfce;
}
.sheet-table th.col-sticky-left {
  z-index: 5;
  background: #f3eee4;
}
.sheet-table td.cell-dirty { background: #fff9db !important; }
.sheet-table td.cell-dirty input,
.sheet-table td.cell-dirty select { background: #fff9db; }
.sheet-pending-hint { color: var(--copper); font-weight: 600; }
.sheet-table tr.row-on td.col-sticky-left { background: #fff4ea; }
.sheet-table tbody tr:hover td.col-sticky-left { background: #faf5ee !important; }
.sheet-table tr.row-on:hover td.col-sticky-left { background: #ffe8d0 !important; }

/* row hover highlight */
.sheet-table tbody tr:hover td { background: #faf5ee !important; }
.sheet-table tbody tr:hover td.gutter { background: #f0e8d8 !important; }
.sheet-table tr.row-on td { background: #fff4ea; }
.sheet-table tr.row-on:hover td { background: #ffe8d0 !important; }

.sheet-table tr.row-fresh td { background: #fffdf3; }
.sheet-table tr.row-fresh td.gutter { background: #f4ead6; }
.sheet-table tr.row-fresh td.col-sticky-left { background: #fffdf3; }
.sheet-table tr.row-fresh:hover td.col-sticky-left { background: #faf5ee !important; }
.sheet-table tr.row-on.row-fresh td,
.sheet-table tr.row-on.row-fresh td.col-sticky-left { background: #fff4ea; }

.sheet-table td.ro.update-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  font-size: 12px;
  color: #8a7b6c;
  white-space: nowrap;
}
.sheet-table td.ro.update-hint.is-fresh { color: #9b6b2d; }
.uh-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--copper);
  flex-shrink: 0;
}
.uh-text {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.uh-undo {
  flex-shrink: 0;
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--copper);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 2px;
  line-height: 34px;
}
.uh-undo:hover { text-decoration: underline; }

.sheet-trash {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #faf8f4;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.sheet-trash-head { margin-bottom: 8px; color: #8a6b3d; }
.sheet-trash-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet-trash-table th, .sheet-trash-table td {
  border-bottom: 1px solid #eadfce;
  padding: 8px 10px;
  text-align: left;
}
.sheet-trash-table th { color: var(--muted); font-weight: 600; }

/* cells */
.sheet-table td.ro { padding: 6px 8px; color: var(--muted); }
.sheet-table td.cell { padding: 0; }
/* 不用 position:relative，否则会破坏 sticky 列导致滚动错位 */
.sheet-table td.cell-on {
  box-shadow: inset 0 0 0 2px var(--copper);
  z-index: 3;
}
.sheet-table td.col-sticky-left.cell-on { z-index: 6; }
.sheet-table td.cell input,
.sheet-table td.cell input[type="date"],
.sheet-table td.cell select.cell-select {
  display: block;
  box-sizing: border-box;
  height: 34px;
  min-height: 34px;
  max-height: 34px;
  line-height: 22px;
}
.sheet-table td.cell input, .sheet-table td.cell input[type="date"] {
  border: 0; width: 100%; padding: 6px 8px; background: transparent; color: inherit; font: inherit;
}
.sheet-table td.cell-date,
.sheet-table td.cell input[type="date"] { cursor: pointer; }
.sheet-table td.cell input[type="date"] {
  position: relative;
}
.sheet-table td.cell input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.sheet-table td.cell select.cell-select {
  border: 0; width: 100%; padding: 5px 18px 5px 8px;
  color: inherit; font: inherit; cursor: pointer;
  appearance: none;
  /* 自绘下拉箭头，明确提示这是可选列表 */
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 11px) calc(50% + 1px), calc(100% - 7px) calc(50% + 1px);
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.sheet-table td.cell select.cell-select:hover { background-color: #f7f2e9; }

/* column resize handle */
.col-resize {
  position: absolute; right: -2px; top: 0; bottom: 0; width: 5px;
  cursor: col-resize; z-index: 3;
}
.col-resize:hover { background: rgba(180,130,60,.3); }

/* per-column filter icon */
.th-filter { font-size: 9px; color: var(--muted); cursor: pointer; margin-left: 4px; opacity: .5; }
.th-filter:hover, .th-filter-on { opacity: 1; color: var(--copper); }

/* column filter popup */
.col-filter-pop {
  position: fixed; z-index: 1000; background: #fff; border: 1px solid var(--line);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 8px 10px; min-width: 140px; max-height: 280px; overflow-y: auto; font-size: 13px;
}
.col-filter-pop label.cf-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 2px;
  margin: 0;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.col-filter-pop label.cf-row:hover { background: #f7f2e9; border-radius: 4px; }
.col-filter-pop label.cf-row input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.cf-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 0 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* context menu */
.ctx-menu {
  position: fixed; z-index: 999; background: #fff; border: 1px solid var(--line);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 170px; padding: 4px 0; font-size: 13px;
}
.ctx-item { padding: 5px 16px; cursor: pointer; white-space: nowrap; }
.ctx-item:hover { background: #f3eee4; }
.ctx-sep { height: 1px; background: var(--line); margin: 3px 0; }

/* status bar */
.sheet-status {
  display: flex; gap: 18px; padding: 6px 10px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); background: #faf8f4;
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { padding: 16px; }
  .nav-row { display: flex; gap: 6px; overflow-x: auto; }
  .nav-btn { width: auto; white-space: nowrap; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .main { padding: 18px 14px 40px; }
  .side-foot { margin-top: 12px; }
}
