* {
  box-sizing: border-box;
}

/* `#session { display: grid }` would otherwise beat the UA `[hidden] { display: none }`. */
[hidden] {
  display: none !important;
}

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c2030;
  --line: #262b3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7c9cff;
  --user: #2a3550;
  --tool: #1f2430;
  --error: #ff8b8b;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button {
  background: var(--accent);
  color: #0b0d12;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

input,
textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

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

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

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

#home {
  max-width: 34rem;
  margin: 18vh auto;
  padding: 0 1.5rem;
}

.lede {
  color: var(--muted);
  line-height: 1.5;
}

#home label {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin: 1.5rem 0 1rem;
}

.row {
  display: flex;
  gap: 0.6rem;
}

.steps {
  margin: 1.5rem 0 1.75rem;
  padding-left: 1.25rem;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.92rem;
}

.steps li + li {
  margin-top: 0.35rem;
}

.steps strong {
  color: var(--text);
  font-weight: 600;
}

#recent {
  margin-top: 1.75rem;
}

#recent h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

#session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#session-list li {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}

.session-link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.session-link strong {
  font-weight: 500;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-link .muted {
  font-size: 0.75rem;
}

.session-actions {
  display: flex;
  gap: 0.35rem;
  flex: none;
}

button.tiny {
  padding: 0.25rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 6px;
}

.join {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.join input {
  flex: 1;
  min-width: 0;
}

#session {
  display: grid;
  grid-template-columns: 17rem 1fr;
  height: 100vh;
}

aside {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

aside header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

aside header button {
  padding: 0.15rem 0.6rem;
  font-size: 1.1rem;
}

#conversations {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  overflow-y: auto;
  flex: 1;
}

#conversations li button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

#conversations li button:hover {
  background: var(--panel-2);
}

#conversations li button.active {
  background: var(--panel-2);
  box-shadow: inset 2px 0 0 var(--accent);
}

aside footer {
  border-top: 1px solid var(--line);
  padding: 0.8rem 1rem;
  display: grid;
  gap: 0.6rem;
}

aside footer label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

aside footer input {
  width: 9rem;
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

#transcript {
  list-style: none;
  margin: 0;
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.msg {
  max-width: 46rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.msg .who {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.bubble {
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.user .bubble {
  background: var(--user);
}

.msg.assistant .bubble {
  background: var(--panel-2);
}

.msg.tool .bubble {
  background: var(--tool);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  max-height: 12rem;
  overflow: auto;
}

.msg.tool .bubble.error {
  color: var(--error);
}

.streaming .bubble::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.tool-activity {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1.25rem 0.5rem;
}

.chip {
  font-size: 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  color: var(--muted);
}

.chip.running {
  border-color: var(--accent);
  color: var(--accent);
}

#composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#input {
  flex: 1;
  resize: none;
  max-height: 12rem;
  font-family: inherit;
}

@media (max-width: 720px) {
  #session {
    grid-template-columns: 1fr;
  }
  aside {
    display: none;
  }
}
