:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --text-dim: #9aa3b2;
  --accent: #4f8cff;
  --accent-dim: #2f5bb0;
  --pending: #6b7280;
  --processing: #3b82f6;
  --done: #22c55e;
  --failed: #ef4444;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --border: #dfe3e8;
    --text: #1a1d23;
    --text-dim: #667085;
    --accent: #2563eb;
    --accent-dim: #93b4f7;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.loading { padding: 3rem; text-align: center; color: var(--text-dim); }

/* ---------- layout ---------- */

header.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
header.topbar nav { display: flex; gap: 1rem; margin-left: auto; align-items: center; }
header.topbar nav a { color: var(--text-dim); text-decoration: none; font-size: 0.9rem; }
header.topbar nav a:hover { color: var(--text); }

main { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem 5rem; }
main.narrow { max-width: 420px; padding-top: 4rem; }

h1 { font-size: 1.45rem; margin: 0 0 1.25rem; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 0.6rem; color: var(--text-dim); font-weight: 600; }

.page-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .spacer { margin-left: auto; }

/* ---------- forms ---------- */

label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.35rem; }

input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 200px; font-family: var(--mono); font-size: 0.9rem; line-height: 1.55; }
select { width: auto; }

.field { margin-bottom: 1.1rem; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.counter { font-size: 0.75rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--failed); }
.hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.35rem; }

button {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); font-weight: 500; }
button.small { padding: 0.35rem 0.7rem; font-size: 0.82rem; }

.actions { display: flex; gap: 0.6rem; margin-top: 1.5rem; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ---------- alerts ---------- */

.alert {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.88rem;
  border: 1px solid;
}
.alert.error { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.alert.success { background: rgba(34, 197, 94, 0.1); border-color: rgba(34, 197, 94, 0.35); color: #86efac; }
.alert.info { background: rgba(79, 140, 255, 0.08); border-color: rgba(79, 140, 255, 0.3); color: var(--text-dim); }

@media (prefers-color-scheme: light) {
  .alert.error { color: #b91c1c; }
  .alert.success { color: #15803d; }
}

/* ---------- table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--border); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface); }
td.id { color: var(--text-dim); font-family: var(--mono); font-size: 0.85rem; }
td.time { color: var(--text-dim); font-size: 0.82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.title { font-weight: 500; }
.empty { padding: 3rem; text-align: center; color: var(--text-dim); }

/* ---------- status badge ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.badge.pending { background: var(--pending); }
.badge.processing { background: var(--processing); }
.badge.done { background: var(--done); }
.badge.failed { background: var(--failed); }

.spinner {
  width: 9px;
  height: 9px;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- detail ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.meta { display: flex; flex-wrap: wrap; gap: 1.5rem; font-size: 0.83rem; color: var(--text-dim); }
.meta div span { color: var(--text); font-variant-numeric: tabular-nums; }

details.prompt summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  list-style: none;
}
details.prompt summary::before { content: "▸ "; }
details.prompt[open] summary::before { content: "▾ "; }

pre.raw {
  margin: 0.75rem 0 0;
  padding: 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-x: auto;
}

.result-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.result-head h2 { margin: 0; }
.result-head .spacer { margin-left: auto; }

.markdown { overflow-wrap: break-word; }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { letter-spacing: -0.01em; color: var(--text); }
.markdown h1 { font-size: 1.3rem; margin: 1.5rem 0 0.7rem; }
.markdown h2 { font-size: 1.12rem; margin: 1.4rem 0 0.6rem; text-transform: none; letter-spacing: -0.01em; }
.markdown h3 { font-size: 1rem; margin: 1.2rem 0 0.5rem; }
.markdown code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.87em;
}
.markdown pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.9rem;
  border-radius: var(--radius);
  overflow-x: auto;
}
.markdown pre code { background: none; padding: 0; }
.markdown blockquote {
  margin: 1rem 0;
  padding-left: 0.9rem;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}
.markdown table { margin: 1rem 0; }
.markdown a { color: var(--accent); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.waiting { display: flex; align-items: center; gap: 0.6rem; color: var(--text-dim); }
.waiting .spinner { border-color: var(--border); border-top-color: var(--accent); width: 13px; height: 13px; }

.pagination { display: flex; gap: 0.5rem; align-items: center; justify-content: center; margin-top: 1.5rem; color: var(--text-dim); font-size: 0.85rem; }

@media (max-width: 640px) {
  main { padding: 1.25rem 1rem 4rem; }
  td.time, th.time { display: none; }
}
