* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --error: #b42318;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -16px rgba(15, 23, 42, 0.22);
  --shadow-panel: 0 16px 40px -28px rgba(15, 23, 42, 0.34);
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, #e6fffb 0%, rgba(230, 255, 251, 0) 38%),
    radial-gradient(circle at 100% 0%, #ecfeff 0%, rgba(236, 254, 255, 0) 42%),
    var(--bg);
  line-height: 1.45;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -44px;
  z-index: 40;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: #f8fffe;
  text-decoration: none;
  font-weight: 600;
  transition: top 0.16s ease;
}

.skip-link:focus-visible {
  top: 10px;
  outline: none;
  box-shadow: 0 0 0 4px rgba(204, 251, 241, 0.82);
}

.auth-panel {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.auth-title {
  margin-right: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.auth-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-form .field {
  min-width: 180px;
  margin-bottom: 0;
}

.auth-actions {
  display: flex;
  gap: 8px;
}

.app {
  width: min(1280px, calc(100% - 28px));
  margin: 14px auto 22px;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100dvh - 92px);
}

.sidebar,
.detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
}

.sidebar {
  padding: 16px;
}

.detail-pane {
  padding: 18px;
  overflow: hidden;
}

.toolbar,
.detail-header,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar h1,
.detail-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.detail-header {
  margin-bottom: 12px;
}

.search-field,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-field {
  margin-bottom: 10px;
}

.field {
  margin-bottom: 12px;
}

.search-field > span,
.field > span,
.section-label,
.muted {
  color: var(--text-muted);
}

.section-label {
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #2e9b90;
  box-shadow: 0 0 0 4px rgba(204, 251, 241, 0.75);
}

textarea {
  min-height: 420px;
  resize: vertical;
  line-height: 1.5;
}

button {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease,
    box-shadow 0.16s ease;
}

button:hover {
  border-color: #6ec7bd;
  background: #f4fcfb;
}

button:active {
  transform: translateY(1px) scale(0.985);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(204, 251, 241, 0.82);
}

button[type="submit"],
#save-button,
#new-prompt-button,
#restore-version-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #f8fffe;
}

button[type="submit"]:hover,
#save-button:hover,
#new-prompt-button:hover,
#restore-version-button:hover {
  background: #0d6861;
  border-color: #0d6861;
  box-shadow: 0 8px 16px -10px rgba(15, 118, 110, 0.65);
}

.results-meta,
.muted {
  font-size: 13px;
}

.results-list,
.versions-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
}

.result-item,
.version-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.result-item {
  padding: 11px 12px;
  margin-bottom: 8px;
}

.version-item {
  padding: 9px 11px;
  margin-bottom: 7px;
}

.result-item:hover,
.version-item:hover {
  background: var(--surface-muted);
  border-color: #6ec7bd;
  transform: translateY(-1px);
}

.result-item:focus-visible,
.version-item:focus-visible {
  outline: none;
  border-color: #2e9b90;
  box-shadow: 0 0 0 4px rgba(204, 251, 241, 0.75);
}

.result-item.selected,
.version-item.selected {
  border-color: #2e9b90;
  background: #effcf9;
  box-shadow: var(--shadow-soft);
}

.result-title,
.version-inspector-title {
  font-weight: 700;
}

.result-title {
  margin-bottom: 4px;
}

.result-snippet,
.version-snippet {
  color: var(--text-muted);
  line-height: 1.35;
}

.result-snippet {
  font-size: 13px;
}

.version-snippet {
  font-size: 12px;
}

.preview-body,
.version-inspector-body {
  margin: 0;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fcfdff;
  padding: 14px;
  line-height: 1.56;
}

.preview-body {
  min-height: 280px;
}

.versions-section {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

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

.versions-header h3 {
  margin: 0;
  font-size: 15px;
}

.versions-header button {
  padding: 5px 10px;
}

.version-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.version-inspector {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 12px;
}

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

.version-inspector-body {
  max-height: 260px;
  overflow: auto;
}

.version-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 11px;
}

.empty-state {
  min-height: 320px;
  display: grid;
  place-content: center;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  padding: 24px;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

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

.error {
  color: var(--error);
  font-size: 13px;
  margin-top: 2px;
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #020617;
    --surface: #0f172a;
    --surface-muted: #111d33;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --border-strong: #334155;
    --accent: #14b8a6;
    --accent-soft: #0f766e;
    --error: #f87171;
    --shadow-soft: 0 1px 2px rgba(2, 6, 23, 0.45), 0 8px 20px -16px rgba(0, 0, 0, 0.65);
    --shadow-panel: 0 16px 40px -30px rgba(0, 0, 0, 0.8);
  }

  body {
    background:
      radial-gradient(circle at 0% 0%, #032d2a 0%, rgba(3, 45, 42, 0) 34%),
      radial-gradient(circle at 100% 0%, #082f49 0%, rgba(8, 47, 73, 0) 38%),
      var(--bg);
  }

  .auth-panel {
    background: rgba(2, 6, 23, 0.72);
  }

  .skip-link:focus-visible {
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.28);
  }

  input::placeholder,
  textarea::placeholder {
    color: #64748b;
  }

  input:focus,
  textarea:focus {
    border-color: #1cc6b3;
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.22);
  }

  button:hover {
    border-color: #1cc6b3;
    background: #0f2e32;
  }

  button:focus-visible {
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.28);
  }

  .result-item.selected,
  .version-item.selected {
    border-color: #1cc6b3;
    background: #132f3b;
  }

  .result-item:focus-visible,
  .version-item:focus-visible {
    border-color: #1cc6b3;
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.22);
  }

  .preview-body,
  .version-inspector-body {
    background: #0b1220;
  }

  .versions-section,
  .empty-state {
    background: linear-gradient(180deg, #0f172a 0%, #0b1427 100%);
  }
}

@media (max-width: 980px) {
  .app {
    width: min(1280px, calc(100% - 20px));
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .sidebar,
  .detail-pane {
    box-shadow: var(--shadow-soft);
  }

  .auth-panel {
    padding: 12px 12px;
  }

  .auth-form {
    width: 100%;
  }

  .auth-form .field {
    min-width: 0;
    flex: 1 1 220px;
  }
}

@media (max-width: 640px) {
  .app {
    width: calc(100% - 14px);
    gap: 10px;
    margin-top: 10px;
    margin-bottom: 14px;
  }

  .sidebar,
  .detail-pane {
    border-radius: 14px;
    padding: 12px;
  }

  .toolbar,
  .detail-header {
    flex-wrap: wrap;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  button {
    padding: 8px 12px;
  }

  textarea {
    min-height: 300px;
  }

  .preview-body {
    min-height: 220px;
  }
}
