:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #647184;
  --line: #d8dee8;
  --line-strong: #b7c0ce;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #c24132;
  --green: #15803d;
  --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,
select,
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,
.top-actions,
.paste-actions,
.table-toolbar,
.pager,
.copy-actions,
.stats-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  align-items: baseline;
  min-width: 220px;
}

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

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

.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 {
  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 {
  color: var(--danger);
}

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

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

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

textarea {
  width: 100%;
  min-height: 168px;
  max-height: 360px;
  resize: vertical;
  padding: 11px;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

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

.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 14px;
  width: min(1720px, calc(100% - 28px));
  margin: 14px auto 28px;
}

.side-panel,
.paste-panel,
.table-toolbar,
.stats-strip,
.result-shell {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.side-panel {
  align-self: start;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  border-radius: 8px;
  overflow: hidden;
}

.side-head {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.saved-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 190px);
  overflow: auto;
  padding: 10px;
}

.saved-item {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.saved-item:hover,
.saved-item.active {
  border-color: var(--accent);
  background: #f7fbff;
}

.saved-title {
  font-weight: 700;
  word-break: break-word;
}

.saved-meta {
  color: var(--muted);
  font-size: 12px;
}

.main-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.paste-panel {
  border-radius: 8px;
  padding: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 160px;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.source-field {
  margin-bottom: 12px;
}

.table-toolbar {
  justify-content: space-between;
  border-radius: 8px 8px 0 0;
  padding: 12px 14px;
}

.search-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 300px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.stats-strip {
  border-radius: 8px;
  padding: 10px 14px;
}

.stats-strip span {
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--muted);
}

.result-shell {
  position: relative;
  min-height: 430px;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}

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

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

th,
td {
  max-width: 340px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 7px 9px;
  background: #fff;
  vertical-align: top;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  min-width: 120px;
  background: #f8fafc;
  font-weight: 700;
  white-space: nowrap;
}

.result-header-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.mini-btn {
  min-width: 24px;
  min-height: 24px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

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

.mini-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

td {
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  white-space: pre-wrap;
}

tbody tr:nth-child(even) td {
  background: #fbfcfe;
}

.empty-state {
  padding: 42px;
  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: 1080px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    width: calc(100% - 18px);
    margin-top: 9px;
  }

  .side-panel {
    position: static;
    max-height: none;
  }

  .saved-list {
    max-height: 260px;
  }

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

@media (max-width: 680px) {
  .topbar,
  .paste-panel,
  .table-toolbar {
    padding: 12px;
  }

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

  .top-actions,
  .paste-actions,
  .pager,
  .copy-actions,
  .btn,
  .search-box,
  .search-box input,
  .form-grid {
    width: 100%;
  }

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