:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e7ecf3;
  --muted: #8b98a5;
  --accent: #4c9aed;
  --border: #2f3d52;
  --ok: #3dd68c;
  --warn: #f5a524;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #1e2a3d 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 2rem clamp(1rem, 4vw, 3rem) 1rem;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
  margin: 0 0 0.65rem;
}

.warn-banner {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
  font-size: 0.9rem;
}

.warn-banner code {
  font-size: 0.85em;
  color: #fde68a;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.panel {
  margin: 1.25rem clamp(1rem, 4vw, 3rem) 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.span-2 {
  grid-column: span 2;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
  color: var(--text);
}

input,
select,
textarea {
  background: #0c1118;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

button,
.link {
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button.primary {
  background: linear-gradient(180deg, #5aa7ff, var(--accent));
  border: 1px solid #3b7fcf;
  color: #061018;
  font-weight: 600;
}

button.ghost,
a.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.ghost.danger {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
}

button.ghost.danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.btn-row {
  font-size: 0.8rem;
  padding: 0.35rem 0.55rem;
}

.status {
  margin-top: 0.75rem;
  min-height: 1.25rem;
}

.trace-log {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: 0.65rem 0.85rem;
  font-size: 0.78rem;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #0c1118;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #c8d0dc;
}

.trace-entry {
  margin-bottom: 0.65rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.trace-entry:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.trace-head {
  font-weight: 600;
}

.trace-detail {
  margin: 0.35rem 0 0;
  padding: 0.4rem 0.5rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.72rem;
  color: #9aa5b5;
}

.trace-log .phase-start .trace-head {
  color: #7eb6ff;
}
.trace-log .phase-request .trace-head {
  color: #f5a524;
}
.trace-log .phase-response .trace-head {
  color: #3dd68c;
}
.trace-log .phase-analyze .trace-head {
  color: #c9a0ff;
}
.trace-log .phase-persist .trace-head {
  color: #5eead4;
}
.trace-log .phase-done .trace-head {
  color: #86efac;
}
.trace-log .phase-error .trace-head {
  color: #f87171;
}

.small {
  font-size: 0.8rem;
  margin: 0 0 0.75rem;
}

.trace-log {
  max-height: 360px;
  overflow: auto;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1118;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

.trace-line {
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(47, 61, 82, 0.6);
}

.trace-line:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.trace-head {
  color: var(--text);
  font-weight: 500;
}

.trace-line.phase-request .trace-head {
  color: #7eb6ff;
}

.trace-line.phase-response .trace-head {
  color: #3dd68c;
}

.trace-line.phase-analyze .trace-head {
  color: #f5a524;
}

.trace-line.phase-persist .trace-head {
  color: #c9a0ff;
}

.trace-line.phase-done .trace-head {
  color: #3dd68c;
}

.trace-line.phase-error .trace-head {
  color: #ff6b6b;
}

.trace-line.phase-start .trace-head {
  color: #8b98a5;
}

.trace-detail {
  margin: 0.35rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.table-wrap {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.2);
}

tbody tr:hover {
  background: rgba(76, 154, 237, 0.06);
}

a.cell-link {
  color: var(--accent);
  word-break: break-all;
}

@media (max-width: 800px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}
