:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #647184;
  --line: #d8dee8;
  --line-strong: #b7c0ce;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #c24132;
  --green: #15803d;
  --amber: #b7791f;
  --shadow: 0 12px 28px rgba(29, 39, 61, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 210px;
}

h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  white-space: nowrap;
}

.sync-state {
  color: var(--muted);
  white-space: nowrap;
}

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

.author-field,
.search-box,
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.author-field input {
  width: 120px;
}

input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input {
  min-height: 36px;
  padding: 7px 10px;
}

textarea {
  display: block;
  width: 100%;
  min-height: 82px;
  max-height: 260px;
  resize: vertical;
  padding: 9px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

textarea:focus {
  background: #fff;
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover,
.icon-btn:hover {
  border-color: var(--line-strong);
  background: #f8fafc;
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.btn.danger,
.icon-btn.danger {
  color: var(--danger);
}

.btn:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-btn {
  min-width: 30px;
  min-height: 30px;
  padding: 4px 8px;
}

.page {
  width: min(1680px, calc(100% - 28px));
  margin: 14px auto 28px;
}

.toolbar {
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.search-box {
  flex: 1 1 340px;
}

.search-box input {
  width: min(520px, 100%);
}

.status-box {
  color: var(--muted);
}

.status-box span {
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf2f7;
}

.status-box .dirty {
  background: #fff4d6;
  color: var(--amber);
}

.status-box .saved {
  background: #e5f6ec;
  color: var(--green);
}

.toggle input {
  width: 16px;
  height: 16px;
  min-height: 16px;
}

.table-shell {
  position: relative;
  min-height: 420px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-scroll {
  max-height: calc(100vh - 170px);
  overflow: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  min-width: 120px;
  padding: 8px;
  background: #f8fafc;
}

th.action-col,
td.action-col {
  position: sticky;
  left: 0;
  z-index: 5;
  width: 116px;
  min-width: 116px;
  max-width: 116px;
  background: #fbfcfe;
}

th.action-col {
  z-index: 7;
}

.header-cell {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.header-cell input {
  min-height: 32px;
  padding: 5px 8px;
  font-weight: 700;
}

.column-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

td {
  min-width: 150px;
  padding: 0;
}

.row-tools {
  display: grid;
  gap: 7px;
  padding: 9px;
}

.row-id {
  color: var(--muted);
  font-size: 12px;
}

.row-updated {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

tr.is-dirty td,
tr.is-dirty .action-col {
  background: #fffdf4;
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 44px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .brand {
    width: 100%;
    justify-content: space-between;
  }

  .top-actions {
    width: 100%;
  }

  .page {
    width: calc(100% - 18px);
    margin-top: 9px;
  }

  .table-scroll {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 12px;
  }

  .brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .btn,
  .author-field,
  .author-field input,
  .search-box,
  .search-box input {
    width: 100%;
  }
}
