:root {
  --bg: #eef2ef;
  --surface: #ffffff;
  --surface-soft: #f8faf8;
  --line: #d5ddd7;
  --line-strong: #aab8af;
  --text: #1d2522;
  --muted: #66736c;
  --primary: #275c48;
  --primary-hover: #1f4939;
  --accent: #b45309;
  --danger: #b42318;
  --danger-hover: #8f1d14;
  --shadow: 0 10px 24px rgba(24, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  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;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  letter-spacing: 0;
}

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

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 650;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
  background: var(--surface-soft);
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 44px;
}

.search-layout,
.settings-layout,
.split-layout {
  display: grid;
  gap: 18px;
}

.query-panel,
.output-panel,
.list-panel,
.editor-panel,
.settings-layout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.query-panel,
.output-panel,
.list-panel,
.editor-panel,
.settings-layout {
  padding: 18px;
}

.query-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-top: 14px;
}

.history-field {
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

label,
.checkbox-field {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(39, 92, 72, 0.14);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.secondary {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--line-strong);
}

.secondary:hover:not(:disabled) {
  border-color: var(--primary);
}

.danger {
  background: var(--danger);
  color: #fff;
}

.danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.status[data-kind="ok"] {
  color: var(--primary);
}

.status[data-kind="error"] {
  color: var(--danger);
}

.status[data-kind="busy"] {
  color: var(--accent);
}

.status-panel {
  margin-top: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef2f0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-badge[data-kind="ok"] {
  background: #e5f4ec;
  color: var(--primary);
}

.status-badge[data-kind="error"] {
  background: #fff1f0;
  color: var(--danger);
}

.status-badge[data-kind="busy"] {
  background: #fff7ed;
  color: var(--accent);
}

.status-output {
  max-height: 420px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.ai-output {
  min-height: 52vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.55;
}

.output-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.download-link {
  color: var(--primary);
  font-weight: 750;
}

.split-layout {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  align-items: start;
}

.prompt-list {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.prompt-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.prompt-item:hover,
.prompt-item.selected {
  border-color: var(--primary);
  background: #edf5f0;
}

.prompt-item span {
  overflow-wrap: anywhere;
  font-weight: 750;
}

.prompt-item small {
  color: var(--muted);
  font-size: 12px;
}

.upload-form,
.prompt-form,
.settings-form {
  display: grid;
  gap: 14px;
}

.upload-form {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-span {
  grid-column: 1 / -1;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--text);
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-weight: 700;
}

.notice.success {
  border: 1px solid #8ab59f;
  background: #eef8f2;
  color: var(--primary);
}

.notice.error {
  border: 1px solid #db9b94;
  background: #fff1f0;
  color: var(--danger);
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

#delete-prompt-form {
  display: none;
}

@media (max-width: 780px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
  }

  .nav {
    width: 100%;
    overflow-x: auto;
  }

  .page {
    width: min(100% - 20px, 1180px);
    margin-top: 14px;
  }

  .query-actions,
  .split-layout,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .status {
    text-align: left;
  }

  .button {
    width: 100%;
  }

  .ai-output {
    min-height: 48vh;
  }
}
