:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --line: #e5e6eb;
  --line-strong: #c9cdd4;
  --text: #1d2129;
  --muted: #86909c;
  --header: #f7f8fa;
  --rownum: #f2f3f5;
  --brand: #3370ff;
  --brand-soft: #e8f3ff;
  --tab: #00d6b9;
  --green: #00b42a;
  --red: #f53f3f;
  --orange: #ff7d00;
  --blue: #165dff;
  --purple: #722ed1;
  --gold: #d48806;
  --fs: 16px;
  --fs-account: 18px;
  --fs-ui: 14px;
  --row-h: 34px;
  --account-w: 520px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: 56px 1fr 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.topbar .tool-btn { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 6px;
  background: linear-gradient(135deg, #14c9c9, #3370ff);
}
.brand h1 { margin: 0; font-size: calc(var(--fs) + 2px); font-weight: 650; }
.sub { margin: 2px 0 0; font-size: var(--fs-ui); color: var(--muted); }
.search-wrap { flex: 1; margin: 0; }
.search-wrap input {
  width: 100%;
  max-width: 560px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 12px;
  font-size: var(--fs-ui);
  outline: none;
}
.search-wrap input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.count { color: var(--muted); font-size: var(--fs-ui); white-space: nowrap; }
.tool-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: var(--fs-ui);
  cursor: pointer;
  white-space: nowrap;
}
.tool-btn:hover { border-color: var(--brand); color: var(--brand); }
.tool-btn:disabled { opacity: 0.5; cursor: default; }
a.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: inherit;
}
a.tool-btn:hover { color: var(--brand); }

.docs-page {
  min-height: 100%;
  background: var(--bg);
}
.docs-page .topbar { position: sticky; top: 0; z-index: 5; }
.docs-wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}
.docs-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 24px;
}
.docs-toc a {
  font-size: var(--fs-ui);
  color: var(--brand);
  text-decoration: none;
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 4px 12px;
}
.docs-toc a:hover { text-decoration: underline; }
.docs-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 18px;
  margin: 0 0 16px;
}
.docs-card h2 {
  margin: 0 0 10px;
  font-size: 18px;
}
.docs-card h3 {
  margin: 16px 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
.docs-card p, .docs-card li { font-size: 14px; line-height: 1.65; }
.docs-card ul { margin: 6px 0 10px; padding-left: 20px; }
.docs-meta {
  display: inline-block;
  font-size: 12px;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 4px;
  padding: 1px 8px;
  margin-right: 6px;
  font-family: Consolas, "Segoe UI", monospace;
}
.docs-card pre, .docs-card code {
  font-family: Consolas, "Cascadia Mono", "Segoe UI", monospace;
}
.docs-card pre {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 8px 0 0;
}
.docs-card code {
  font-size: 13px;
  background: #f2f3f5;
  padding: 1px 5px;
  border-radius: 4px;
}
.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
}
.docs-card { overflow-x: auto; }
.docs-table th, .docs-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.docs-table th { background: var(--header); font-weight: 600; }
.docs-table td:first-child { font-family: Consolas, "Segoe UI", monospace; white-space: nowrap; }
.docs-req { color: var(--red); font-weight: 600; }
.docs-opt { color: var(--muted); }
@media (max-width: 720px) {
  .docs-wrap { padding: 12px 10px 48px; }
  .docs-card { padding: 12px; }
  .docs-table td:first-child { white-space: normal; }
}

.grid-wrap {
  overflow: auto;
  background: var(--panel);
}
.sheet {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
  font-size: var(--fs);
  user-select: none;
  -webkit-user-select: none;
}
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--header);
  border-bottom: 1px solid var(--line-strong);
  border-right: 1px solid var(--line);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  padding: 0 8px;
  height: 30px;
  font-size: var(--fs-ui);
}
.sheet thead tr.letters th {
  top: 0;
  height: 26px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
  font-size: var(--fs-ui);
}
.sheet thead tr.headers th {
  top: 26px;
  height: 58px;
  vertical-align: middle;
  padding: 4px 6px;
  white-space: normal;
}
.th-inner {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 88px;
}
.th-title { line-height: 16px; }
.sheet thead th.has-filter { background: #f2f6ff; }
.sheet thead th.is-filtered { background: #e8f3ff; }
.dd-btn {
  width: 100%;
  max-width: 160px;
  height: auto;
  min-height: calc(var(--fs) + 10px);
  border: 0;
  border-radius: 11px;
  background: #f2f3f5;
  font-size: var(--fs);
  font-weight: 600;
  color: #111;
  text-align: center;
  padding: 0 18px 0 8px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}
.dd-btn::after {
  content: "";
  position: absolute;
  right: 6px;
  top: calc(50% - 2px);
  border: 4px solid transparent;
  border-top-color: currentColor;
  opacity: 0.55;
}
.dd-btn:hover { filter: brightness(0.97); }
#cell-input {
  position: fixed;
  z-index: 50;
  box-sizing: border-box;
}
#cell-input input {
  width: 100%;
  height: 100%;
  border: 2px solid var(--brand);
  padding: 0 8px;
  margin: 0;
  font-size: var(--fs);
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  box-sizing: border-box;
}
.dd-menu {
  position: fixed;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 4px;
  max-height: 320px;
  overflow: auto;
}
.dd-item {
  display: block;
  width: 100%;
  border: 0;
  background: #f2f3f5;
  color: #111;
  text-align: center;
  font-size: var(--fs);
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 11px;
  cursor: pointer;
  margin: 3px 0;
}
.dd-item:hover { filter: brightness(0.96); }
.dd-item.is-on { outline: 2px solid var(--brand); outline-offset: -2px; }
.sheet .corner {
  position: sticky; left: 0; z-index: 5;
  background: var(--header);
  min-width: 52px; width: 52px;
}
.sheet tr.virt-pad td {
  padding: 0 !important;
  border: 0 !important;
  height: auto;
  max-width: none;
  background: transparent;
  cursor: default;
}
.sheet tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--rownum);
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-weight: 500;
  min-width: 52px;
}
.sheet thead tr.letters th:not(.corner) { cursor: pointer; }
.sheet td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  height: var(--row-h);
  font-size: var(--fs);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
  cursor: cell;
}
.sheet td.col-account {
  position: relative;
  width: var(--account-w);
  min-width: var(--account-w);
  max-width: var(--account-w);
  overflow: hidden;
  font-size: var(--fs-account);
}
.account-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  pointer-events: none;
  font-size: var(--fs-account);
}
.sheet td.is-edited {
  background: #fff6d4;
  box-shadow: inset 0 0 0 2px #f5c242, 0 0 10px rgba(245, 194, 66, 0.4);
}
.sheet td.is-selected {
  background: #d6e6ff !important;
  box-shadow: inset 0 0 0 1px #3370ff;
}
.sheet td.is-edited.is-selected {
  box-shadow: inset 0 0 0 2px #3370ff, 0 0 10px rgba(245, 194, 66, 0.4);
}
.sheet td.is-fill {
  background: #e8f3ff !important;
  box-shadow: inset 0 0 0 2px #3370ff;
}
#fill-handle {
  position: fixed;
  width: 10px;
  height: 10px;
  margin: 0;
  padding: 0;
  background: #3370ff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #3370ff;
  box-sizing: border-box;
  cursor: crosshair;
  z-index: 40;
  touch-action: none;
  user-select: none;
}
#fill-handle::after {
  content: "";
  position: absolute;
  inset: -8px;
}
#fill-handle[hidden] {
  display: none !important;
}
.jump-btn {
  display: none;
  position: absolute;
  right: 4px;
  top: 3px;
  z-index: 2;
  height: 22px;
  line-height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  background: var(--brand);
  color: #fff !important;
  font-size: var(--fs-ui);
  text-decoration: none !important;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.sheet td.col-account:hover .jump-btn { display: inline-block; }
.sheet td.col-account:hover .account-text { padding-right: 48px; }
body.is-selecting .jump-btn { display: none !important; }
body.is-selecting, body.is-selecting * { cursor: cell !important; }
body.is-filling, body.is-filling * { cursor: crosshair !important; }
#toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(29, 33, 41, 0.92);
  color: #fff;
  padding: 16px 28px;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.4;
  z-index: 80;
  pointer-events: none;
  white-space: nowrap;
}
#toast.toast-cell {
  padding: 8px 14px;
  font-size: 16px;
  border-radius: 8px;
}
.sheet tbody tr:hover td:not(.is-selected):not(.is-edited),
.sheet tbody tr:hover th { background: #f7fbff; }
.sheet a.cell-link { color: var(--brand); text-decoration: none; cursor: pointer; }
.sheet a.cell-link:hover { text-decoration: underline; }

.pill {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 11px;
  line-height: 20px;
  font-weight: 600;
  font-size: var(--fs);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.c-green { background: #34c724; color: #111; }
.c-yellow { background: #fff258; color: #111; }
.c-cyan { background: #7edafb; color: #111; }
.c-lavender { background: #bacdfe; color: #111; }
.c-orange { background: #ffba6b; color: #111; }
.c-coral { background: #f76964; color: #111; }
.c-mint { background: #64e8d6; color: #111; }
.c-red { background: #f54a45; color: #111; }
.c-olive { background: #667901; color: #111; }
.c-blue { background: #3370ff; color: #111; }
.c-sky { background: #b1e8fc; color: #111; }
.c-magenta { background: #f01d94; color: #111; }
.c-hotpink { background: #f57ac0; color: #111; }
.c-pink { background: #fbbfbc; color: #111; }
.c-purple { background: #ad82f7; color: #111; }
.c-peach { background: #fed4a4; color: #111; }
.c-gray { background: #8f959e; color: #111; }
.c-teal { background: #04b49c; color: #111; }
.c-empty { background: #e5e6eb; color: #111; }

.empty {
  padding: 48px;
  text-align: center;
  color: var(--muted);
}

.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f7f8fa;
  border-top: 1px solid var(--line);
  padding: 0 8px 0 12px;
}
.sel-count {
  margin-left: auto;
  margin-right: 16px;
  color: var(--brand);
  font-size: var(--fs-ui);
  font-weight: 650;
  white-space: nowrap;
}
.tabs { display: flex; gap: 4px; height: 100%; align-items: flex-end; }
.tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  padding: 6px 14px;
  font-size: var(--fs-ui);
  cursor: pointer;
  color: var(--text);
  border-radius: 6px 6px 0 0;
}
.tab.active {
  background: #fff;
  border-color: var(--line);
  box-shadow: inset 0 2px 0 var(--tab);
  font-weight: 600;
}
.pager { display: flex; align-items: center; gap: 8px; font-size: var(--fs-ui); color: var(--muted); }
.pager select {
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fff;
  font-size: var(--fs-ui);
}
.pager button {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.pager button:disabled { opacity: 0.45; cursor: default; }

#ops-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 60;
}
#ops-mask.is-open { display: block; }
#ops-panel {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 100%);
  height: 100%;
  background: #fff;
  z-index: 61;
  box-shadow: -8px 0 24px rgba(0,0,0,.12);
  flex-direction: column;
}
#ops-panel.is-open { display: flex; }
.ops-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: calc(var(--fs) + 2px);
}
.ops-list {
  flex: 1;
  overflow: auto;
  padding: 8px 12px 24px;
}
.ops-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  background: #fafafa;
  font-size: var(--fs-ui);
}
.ops-item .ops-time { color: var(--muted); margin-bottom: 4px; }
.ops-item .ops-acc {
  font-size: var(--fs);
  margin: 4px 0;
  word-break: break-all;
}
.ops-item .ops-change { margin-top: 6px; }
.ops-old, .ops-new { font-weight: 600; }
.ops-arrow { margin: 0 6px; color: var(--muted); }
.ops-item.is-undone { opacity: 0.55; }
.ops-item .ops-undo { margin-top: 8px; }
.ops-undone-tag { color: var(--muted); font-size: 12px; margin-left: 6px; }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  background: var(--bg);
}
.login-card {
  width: min(400px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.06);
}
.login-card .brand { min-width: 0; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-ui);
  color: var(--muted);
}
.login-card input {
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 15px;
  color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-submit {
  height: 40px;
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  font-size: 15px;
}
.login-submit:hover { color: #fff; filter: brightness(1.05); }
.login-err { margin: 0; color: var(--red); font-size: 13px; }

#admin-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 60;
}
#admin-mask.is-open { display: block; }
#admin-panel {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100%);
  height: 100%;
  background: #fff;
  z-index: 61;
  box-shadow: -8px 0 24px rgba(0,0,0,.12);
  flex-direction: column;
}
#admin-panel.is-open { display: flex; }
.admin-body {
  flex: 1;
  overflow: auto;
  padding: 8px 16px 32px;
}
.admin-body section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px 14px;
  margin: 12px 0;
  background: #fafafa;
}
.admin-body h3 { margin: 0 0 8px; font-size: 15px; }
.admin-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
  font-size: 13px;
  color: var(--muted);
}
.admin-body input, .admin-body textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: Consolas, "Segoe UI", monospace;
}
.admin-body textarea { resize: vertical; }
.admin-actions { display: flex; gap: 8px; margin-top: 8px; }
.admin-help { color: var(--muted); font-size: 12px; line-height: 1.5; white-space: pre-wrap; }
.user-list { font-size: 13px; margin-bottom: 8px; }
.user-list div { padding: 4px 0; border-bottom: 1px dashed var(--line); }

#add-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 70;
}
#add-mask.is-open { display: block; }
#add-dialog {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  background: #fff;
  z-index: 71;
  border-radius: 12px;
  padding: 22px 22px 18px;
  box-shadow: 0 12px 36px rgba(0,0,0,.16);
  flex-direction: column;
  gap: 12px;
}
#add-dialog.is-open { display: flex; }
#add-dialog h3 { margin: 0; font-size: 16px; }
#add-dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-ui);
  color: var(--muted);
}
#add-dialog textarea,
#add-dialog input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  font-family: Consolas, "Segoe UI", monospace;
}
#add-dialog textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.45;
}
#add-dialog input { height: 36px; }
#add-dialog textarea:focus,
#add-dialog input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
#add-dialog .admin-help { margin: 0; white-space: normal; }
