:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #dcdcdc;
  --accent: #2f6fed;
  --card-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --fg: #ececec;
    --muted: #9a9a9a;
    --border: #33343a;
    --accent: #5b8dff;
    --card-bg: #1f2023;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
}

form#ask-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--fg);
  resize: vertical;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  align-self: flex-end;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

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

button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.cost-limit-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.cost-limit-label input {
  width: 70px;
  padding: 6px 8px;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
}

.form-buttons {
  display: flex;
  gap: 8px;
}

.status {
  margin-top: 20px;
  color: var(--muted);
  font-style: italic;
}

.status.error {
  color: #d64545;
  font-style: normal;
}

.progress-log {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-log li {
  padding-left: 1.2em;
  text-indent: -1.2em;
}

.progress-log li.tool-result {
  color: var(--fg);
}

.progress-log li.tool-error,
.progress-log li.error {
  color: #d64545;
}

.usage {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

section {
  margin-top: 32px;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 10px;
}

.answer {
  padding: 16px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 1.5;
  overflow-x: auto;
}

.answer > :first-child {
  margin-top: 0;
}

.answer > :last-child {
  margin-bottom: 0;
}

.answer p {
  margin: 0 0 12px;
}

.answer ul,
.answer ol {
  margin: 0 0 12px;
  padding-left: 22px;
}

.answer li {
  margin-bottom: 4px;
}

.answer strong {
  font-weight: 600;
}

.answer code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
}

.answer pre {
  background: var(--bg);
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 12px;
}

.answer pre code {
  background: none;
  padding: 0;
}

.answer table {
  border-collapse: collapse;
  margin: 0 0 12px;
  width: 100%;
}

.answer th,
.answer td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.answer th {
  background: var(--bg);
  font-weight: 600;
}

.answer blockquote {
  margin: 0 0 12px;
  padding-left: 14px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.answer a {
  color: var(--accent);
}

.answer h1,
.answer h2,
.answer h3 {
  margin: 16px 0 8px;
  font-size: 1rem;
}

.answer hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.sources {
  padding-left: 20px;
  margin: 0;
}

.sources li {
  margin-bottom: 10px;
  line-height: 1.4;
}

.sources a {
  color: var(--accent);
  text-decoration: none;
}

.sources a:hover {
  text-decoration: underline;
}

.sources .score {
  color: var(--muted);
  font-size: 0.85rem;
}

.login-page {
  text-align: center;
  padding-top: 96px;
}

.button-link {
  display: inline-block;
  margin-top: 24px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  text-decoration: none;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-bar button {
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.user-bar a {
  color: var(--muted);
  text-decoration: none;
}

.user-bar a:hover {
  text-decoration: underline;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.usage-table th,
.usage-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: right;
}

.usage-table th:first-child,
.usage-table td:first-child {
  text-align: left;
}

.usage-table th {
  background: var(--card-bg);
  font-weight: 600;
}

.usage-table tbody tr:nth-child(even) {
  background: var(--card-bg);
}

.usage-table tfoot td {
  font-weight: 600;
}

.usage-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.usage-controls select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
}

.usage-empty {
  color: var(--muted);
  font-style: italic;
}
