:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #1d252c;
  --muted: #65727d;
  --line: #d9e0e5;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --code: #101820;
  --code-soft: #17212b;
  --warn: #a15c00;
  --good: #12805c;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
.file-picker {
  font: inherit;
}

.app-shell {
  height: 100vh;
  padding: 18px;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.schema-panel,
.chat-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.schema-panel {
  padding: 18px;
  overflow: auto;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}
.panel-logo {
  width: 48px;
  height: 48px;
  border-radius: 11px;
  flex-shrink: 0;
  display: block;
}
.panel-titles {
  min-width: 0;
}

.kicker {
  display: block;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #aeb7bf;
}

.status-dot.ok {
  background: var(--good);
}

.status-dot.fail {
  background: #c2410c;
}

.status-dot.pending {
  background: #a15c00;
}

.history-panel {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.history-header strong {
  font-size: 14px;
}

.history-header button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 0;
}

.history-header button:hover {
  color: var(--accent-dark);
}

.sql-history-list {
  display: grid;
  gap: 6px;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.sql-history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfd;
}

.sql-history-card button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.sql-history-card button:first-child {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sql-history-card span {
  grid-column: 1;
  color: var(--muted);
  font-size: 11px;
}

.sql-history-card button:last-child {
  grid-column: 2;
  grid-row: 1 / span 2;
  color: var(--accent-dark);
  font-size: 12px;
}

.quick-prompts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.quick-prompts button,
#clearBtn,
.composer button,
.file-picker {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.quick-prompts button {
  min-height: 38px;
  padding: 8px;
}

.quick-prompts button:hover,
#clearBtn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.schema-card {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.schema-card strong {
  display: block;
  font-size: 14px;
}

.schema-intro {
  border-top: 1px solid var(--line);
  padding: 14px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.schema-card code {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}

.schema-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  min-height: 0;
}

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

.chat-header p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.chat-header strong {
  font-size: 18px;
}

#clearBtn {
  min-width: 64px;
  height: 34px;
}

.messages {
  padding: 18px 20px;
  overflow: auto;
  min-height: 0;
}

.message {
  max-width: 980px;
  margin-bottom: 14px;
}

.message.user {
  margin-left: auto;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: #e8f5f2;
  border-color: #b9ddd5;
}

.progress-bubble {
  background: #fff8ed;
  border-color: #f0d7ad;
}

.progress-bubble strong {
  display: block;
  margin-bottom: 8px;
}

.progress-status {
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  height: 4px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #f2dfbd;
}

.progress-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--warn);
  animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    transform: translateX(-105%);
  }
  100% {
    transform: translateX(245%);
  }
}

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

.sql-block {
  position: relative;
  margin-top: 10px;
}

pre {
  margin: 0;
  overflow: auto;
  background: var(--code);
  color: #e6edf3;
  border-radius: 8px;
  padding: 14px;
  line-height: 1.5;
  font-size: 13px;
}

.copy-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  border: 1px solid #3d4d5c;
  border-radius: 6px;
  background: var(--code-soft);
  color: #e6edf3;
  padding: 5px 8px;
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.detail-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.detail-box b {
  display: block;
  color: var(--text);
  margin-bottom: 4px;
}

.confirmation-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.confirmation-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.confirmation-option:hover {
  border-color: var(--accent);
  background: #e8f5f2;
}

.option-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 800;
}

.other-option .option-number {
  min-width: 48px;
  background: #f1f5f9;
  color: var(--muted);
}

.option-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.option-text strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.option-text small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.example-cards {
  margin: 4px 0 8px;
}
.example-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.example-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.example-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.example-card:hover {
  border-color: var(--accent);
  background: #e8f5f2;
}
.example-card:active {
  transform: scale(0.99);
}
.example-card strong {
  font-size: 13px;
  color: var(--accent-dark);
}
.example-card span {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
@media (max-width: 540px) {
  .example-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.discovery-steps {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 10px;
  padding: 10px;
  background: #fbfcfd;
}

.discovery-steps > b {
  display: block;
  margin-bottom: 8px;
}

.discovery-step {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.discovery-step:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.discovery-step strong {
  display: block;
  font-size: 14px;
}

.discovery-step p {
  margin: 6px 0;
  color: var(--text);
}

.discovery-step span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.discovery-step pre {
  margin-top: 8px;
}

.step-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.step-upload {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.step-upload:hover {
  background: #e8f5f2;
}

.step-upload input {
  display: none;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.file-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 10px;
}

.file-picker:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.file-picker input {
  display: none;
}

#fileName {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.composer button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}

.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* ---------- Header actions / user badge ---------- */

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-badge {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 10px;
  background: #eef3f5;
  border-radius: 999px;
  white-space: nowrap;
}

.user-badge.admin::after {
  content: " · 管理员";
  color: var(--accent-dark);
  font-weight: 700;
}

.header-actions button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.header-actions button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.header-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#feedbackBtn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

#feedbackBtn:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

#adminBtn {
  background: #1f2937;
  color: #fff;
  border-color: #1f2937;
}

#adminBtn:hover:not(:disabled) {
  background: #111827;
  border-color: #111827;
  color: #fff;
}

/* ---------- Modal overlay ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.hidden,
.hidden {
  display: none !important;
}

.modal-card {
  background: var(--panel);
  border-radius: 12px;
  padding: 24px;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3);
}

.modal-card.wide {
  width: min(720px, 100%);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.modal-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.5;
}

.modal-hint code {
  background: #eef3f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text);
}

.modal-form input[type="text"],
.modal-form input[type="password"],
.modal-form textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  outline: none;
}

.modal-form input:focus,
.modal-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.modal-form button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}

.modal-form button[type="submit"]:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.modal-actions button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
}

.modal-actions button.ghost:hover {
  color: var(--text);
  border-color: var(--text);
}

.modal-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

.rating-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.rating-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

.tag-row {
  display: flex;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.tag-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  flex-direction: row;
}

/* ---------- Admin feedback list ---------- */

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.admin-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfd;
  font-size: 13px;
}

.admin-item header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.admin-item header strong {
  color: var(--text);
  font-size: 13px;
}

.admin-item .rating-up {
  color: var(--good);
}

.admin-item .rating-down {
  color: #b91c1c;
}

.admin-item .tag-chip {
  display: inline-block;
  background: #eef3f5;
  color: var(--muted);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  margin-right: 4px;
}

.admin-item .comment {
  margin: 6px 0 6px;
  white-space: pre-wrap;
  color: var(--text);
}

.admin-item details {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.admin-item details pre {
  background: var(--code);
  color: #e2e8f0;
  padding: 8px;
  border-radius: 6px;
  overflow: auto;
  max-height: 280px;
  font-size: 11px;
}

.admin-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    padding: 10px;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .schema-panel {
    max-height: 420px;
  }

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

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