: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,
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,
.card-actions,
.hint-row,
.preview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

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

.sync-state,
.hint-row,
.preview-head,
.saved-meta {
  color: var(--muted);
}

.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,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

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

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 10px;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

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

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

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

.side-panel,
.meta-panel,
.sql-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.side-panel {
  align-self: start;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  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 {
  font-size: 12px;
}

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

.meta-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(260px, 1fr) 150px auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
}

.hint-row {
  min-height: 34px;
  padding: 0 4px;
}

.hint-row span:first-child {
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--text);
}

.sql-items {
  display: grid;
  gap: 14px;
}

.sql-card {
  overflow: hidden;
}

.card-head {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.item-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
}

.note-field {
  padding: 0 14px 14px;
}

.note-field textarea {
  min-height: 68px;
  white-space: pre-wrap;
}

.preview-head {
  justify-content: space-between;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  font-size: 13px;
}

.item-stats {
  color: var(--text);
  font-weight: 700;
}

.preview-scroll {
  max-height: 260px;
  overflow: auto;
}

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

th,
td {
  max-width: 320px;
  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: 3;
  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;
}

.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: 1120px) {
  .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: 250px;
  }

  .meta-panel,
  .item-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .meta-panel,
  .card-head,
  .item-grid {
    padding: 12px;
  }

  .brand,
  .top-actions,
  .card-actions,
  .btn {
    width: 100%;
  }

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

  .card-head {
    grid-template-columns: 1fr;
  }
}
