* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: #f6f4f0;
  color: #1f1f1f;
  overflow-x: hidden;
}

header,
footer {
  padding: 24px 32px;
  background: #1f2933;
  color: #fef6e4;
}

footer a {
  color: #fef6e4;
  text-decoration: none;
}

footer a:hover {
  opacity: 0.85;
}

header h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

header p,
footer p {
  margin: 0;
  opacity: 0.8;
}

.footer-divider {
  margin: 0 8px;
}

main {
  padding: 24px 32px 48px;
  display: grid;
  gap: 20px;
}

.panel {
  background: #ffffff;
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 10px 24px rgba(20, 25, 35, 0.08);
  overflow-x: hidden;
}

.panel h2 {
  margin-top: 0;
  font-size: 20px;
}

.scroll-box {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid #e6e8ec;
  border-radius: 12px;
  padding: 10px 12px;
  background: #faf8f4;
}

.field {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-row input[type="text"] {
  flex: 1;
}

.field.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 16px 24px;
}

.field.inline label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
}

.field.inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

label {
  font-weight: 600;
}

input[type="text"] {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  font-size: 14px;
}

textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  font-size: 13px;
  font-family: "Courier New", Courier, monospace;
  resize: vertical;
}

input[type="file"] {
  border: 1px solid #d0d5dd;
  padding: 10px;
  border-radius: 10px;
  background: #fafafa;
}

.hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: #5a5f66;
}

.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.sql-block {
  margin-top: 12px;
}

.sql-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.mono {
  font-family: "Courier New", Courier, monospace;
}

progress {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background-color: #e6e8ec;
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, #f6a25c, #e36e3b);
  border-radius: 999px;
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, #f6a25c, #e36e3b);
  border-radius: 999px;
}

progress.is-complete::-webkit-progress-value {
  background: linear-gradient(90deg, #31b45a, #1f8f46);
}

progress.is-complete::-moz-progress-bar {
  background: linear-gradient(90deg, #31b45a, #1f8f46);
}

button {
  align-self: flex-start;
  background: #1f2933;
  color: #fef6e4;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) {
  background: #2f3d4a;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
}

.scroll-box table {
  width: max-content;
  min-width: 100%;
}

th,
td {
  border-bottom: 1px solid #e6e8ec;
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f2f0eb;
  font-weight: 600;
}

.badge {
  display: inline-block;
  background: #fee1c7;
  color: #a35200;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

/* ---- AI Chat ---- */
.chat-messages {
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid #e6e8ec;
  border-radius: 12px;
  padding: 14px 16px;
  background: #faf8f4;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.chat-placeholder {
  text-align: center;
  padding: 24px 0;
}

.chat-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.status-ok {
  color: #1f8f46;
}

.status-warn {
  color: #b8860b;
}

.status-err {
  color: #c0392b;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg.user {
  align-self: flex-end;
  background: #1f2933;
  color: #fef6e4;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #e8e4dd;
  color: #1f1f1f;
  border-bottom-left-radius: 4px;
}

.chat-msg.assistant code {
  background: #d5cfc4;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
}

.chat-msg.assistant pre {
  background: #2d2d2d;
  color: #f0f0f0;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
  margin: 8px 0;
}

.chat-table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  width: auto;
  min-width: 50%;
  max-width: 100%;
}

.chat-table th,
.chat-table td {
  border: 1px solid #c5c0b6;
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.chat-table th {
  background: #d5cfc4;
  font-weight: 600;
}

.chat-table tbody tr:nth-child(even) {
  background: #f0ece4;
}

.chat-table tbody tr:hover {
  background: #e8e3d9;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.chat-input-row button {
  align-self: flex-end;
  padding: 10px 20px;
  font-size: 14px;
}

.btn-secondary {
  background: #6c757d;
}

.btn-secondary:hover {
  background: #5c636a;
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #6c757d;
  padding: 10px 14px;
}

.chat-loading .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c757d;
  animation: pulse 1.2s infinite ease-in-out;
}

.chat-loading .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-loading .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 800px) {
  main {
    padding: 16px;
  }

  header,
  footer {
    padding: 20px 16px;
  }

  header h1 {
    font-size: 22px;
  }

  .panel {
    padding: 16px;
  }

  .scroll-box {
    max-height: 320px;
  }

  .field.inline {
    flex-direction: column;
    gap: 8px;
  }
}
