:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #5d6d7e;
  --line: #d9e1e8;
  --brand: #0f766e;
  --brand-strong: #0b5f59;
  --red-bg: #fde2e2;
  --red-ink: #991b1b;
  --orange-bg: #fff0d0;
  --orange-ink: #92400e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.35 "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.password-field {
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 8px;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--brand);
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

.login-panel h1 {
  font-size: 22px;
  margin-bottom: 20px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

#loginForm {
  display: grid;
  gap: 14px;
}

#loginForm button,
.top-actions button:first-child,
#addBtn {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

#loginForm button:hover,
.top-actions button:first-child:hover,
#addBtn:hover {
  background: var(--brand-strong);
}

.error {
  min-height: 20px;
  color: var(--red-ink);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 18px;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.share-address {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.share-address a {
  border: 1px solid #a7d7d2;
  border-radius: 4px;
  padding: 2px 6px;
  background: #eefaf8;
  color: var(--brand-strong);
  text-decoration: none;
}

.share-address a:hover {
  border-color: var(--brand);
}

.top-actions,
.toolbar,
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.metrics div {
  background: var(--panel);
  padding: 10px 16px;
}

.metrics span {
  display: block;
  font-size: 20px;
  font-weight: 700;
}

.metrics label {
  margin-top: 2px;
}

.toolbar {
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.toolbar input {
  max-width: 420px;
}

.toolbar select {
  max-width: 140px;
}

.inline-field {
  display: grid;
  grid-template-columns: auto 76px;
  align-items: center;
  gap: 6px;
}

.inline-field span {
  color: var(--muted);
  white-space: nowrap;
}

.file-input {
  display: none;
}

.table-wrap {
  overflow: auto;
  min-height: 0;
  user-select: none;
}

table {
  width: 100%;
  min-width: 1310px;
  border-collapse: collapse;
  background: var(--panel);
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  font-size: 12px;
  height: 28px;
  line-height: 18px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e9f1f3;
  color: #183b3b;
  font-weight: 700;
}

td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th:nth-child(1),
.data-table td:nth-child(1) {
  width: 50px;
  text-align: center;
}

.data-table th:nth-child(2),
.data-table td:nth-child(2) {
  width: 76px;
}

.data-table th:nth-child(3),
.data-table td:nth-child(3),
.data-table th:nth-child(15),
.data-table td:nth-child(15) {
  width: 88px;
}

.data-table th:nth-child(4),
.data-table td:nth-child(4) {
  width: 190px;
}

.data-table th:nth-child(5),
.data-table td:nth-child(5) {
  width: 150px;
}

.data-table th:nth-child(6),
.data-table td:nth-child(6),
.data-table th:nth-child(8),
.data-table td:nth-child(8),
.data-table th:nth-child(9),
.data-table td:nth-child(9),
.data-table th:nth-child(11),
.data-table td:nth-child(11),
.data-table th:nth-child(16),
.data-table td:nth-child(16) {
  width: 92px;
}

.data-table th:nth-child(7),
.data-table td:nth-child(7) {
  width: 170px;
}

.data-table th:nth-child(10),
.data-table td:nth-child(10),
.data-table th:nth-child(12),
.data-table td:nth-child(12) {
  width: 120px;
}

.data-table th:nth-child(13),
.data-table td:nth-child(13) {
  width: 190px;
}

.data-table th:nth-child(14),
.data-table td:nth-child(14) {
  width: 88px;
}

.row-select {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.row-select:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

tr[data-allowed="禁止"] td[data-col="12"],
tr[data-allowed="禁止"] td[data-col="13"],
tr[data-allowed="禁止"] td[data-col="14"],
tr[data-allowed="禁止"] td[data-col="15"] {
  background: var(--red-bg);
  color: var(--red-ink);
}

tbody tr {
  cursor: default;
}

tbody td:hover,
th[data-col]:hover {
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--brand);
}

.data-table .col-active,
.data-table .col-hover {
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--brand);
}

.data-table td[data-col="1"],
.data-table td[data-col="2"],
.data-table td[data-col="3"],
.data-table td[data-col="4"],
.data-table td[data-col="5"],
.data-table td[data-col="6"],
.data-table td[data-col="7"],
.data-table td[data-col="8"],
.data-table td[data-col="9"],
.data-table td[data-col="10"],
.data-table td[data-col="11"] {
  cursor: text;
}

.inline-editing {
  padding: 0;
  box-shadow: inset 0 0 0 2px var(--brand);
}

.inline-cell-input {
  width: 100%;
  height: 27px;
  border: 0;
  border-radius: 0;
  padding: 4px 7px;
  background: #ffffff;
  font-size: 12px;
  line-height: 18px;
  outline: none;
}

.pager {
  justify-content: center;
  padding: 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

dialog {
  width: min(900px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.4);
}

#rowForm,
#auditDialog {
  padding: 20px;
}

#rowForm h2 {
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 18px 0 0;
}

.audit-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.audit-list {
  display: grid;
  gap: 8px;
  max-height: 70vh;
  overflow: auto;
}

.audit-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.audit-item code {
  white-space: pre-wrap;
}

.backup-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.backup-item strong,
.backup-item span {
  display: block;
}

.backup-meta {
  color: var(--muted);
  margin-top: 4px;
}

.dialog-note {
  color: var(--muted);
  margin-bottom: 10px;
}

#pasteForm {
  padding: 20px;
}

#importPreviewForm {
  padding: 20px;
}

#pasteText {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font: 12px/1.45 Consolas, "Microsoft YaHei", monospace;
}

.preview-table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.preview-table {
  min-width: 980px;
}

.preview-table th,
.preview-table td {
  height: 28px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 760px) {
  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}
