:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1b2523;
  background: #f1f4f1;
  --muted: #4f605b;
  --line: #d5dfd9;
  --accent: #185c4e;
  --surface: #fff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.45rem; overflow-wrap: anywhere; }
h2 { font-size: 1rem; }

.topbar {
  min-height: 3.75rem;
  padding: .55rem max(1rem, calc((100% - 76rem) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  background: #143630;
  color: #fff;
}

.brand { white-space: nowrap; }
.brand strong { color: #a6e3cc; }
.account { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.account span { overflow-wrap: anywhere; }
.account .quiet { color: #fff; border-color: #8cb7aa; background: transparent; }
.account .quiet:hover { background: #285447; }

button, input, select, textarea { font: inherit; }
button, input, select, textarea { border-radius: .55rem; min-height: 2.75rem; }
button { cursor: pointer; padding: .5rem .8rem; font-weight: 600; }
button:disabled { cursor: default; opacity: .58; }
:focus-visible { outline: 2px solid #167861; outline-offset: 2px; }
.quiet { background: var(--surface); color: var(--accent); border: 1px solid var(--line); }
.quiet:hover:not(:disabled) { background: #eaf3ee; }
.primary { background: var(--accent); color: #fff; border: 1px solid transparent; }
.primary:hover:not(:disabled) { background: #104438; }
input, select, textarea { border: 1px solid #a8b8b0; color: inherit; background: var(--surface); padding: .6rem .7rem; }
label { font-weight: 600; font-size: .875rem; }
.error { color: #9b2626; overflow-wrap: anywhere; }
.notice, .session-retry { margin: 1rem auto; width: fit-content; max-width: calc(100% - 2rem); }
.session-retry { display: block; }

.workspace, .login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .9rem;
  margin: 1rem auto;
}
.login-panel { width: min(26rem, calc(100% - 2rem)); margin-top: 3rem; padding: 1.5rem; }
.login-panel form { display: grid; gap: .65rem; margin-top: 1.25rem; }
.login-panel button { margin-top: .4rem; }

.workspace {
  width: min(76rem, calc(100% - 2rem));
  display: grid;
  grid-template-columns: minmax(14rem, 19rem) minmax(0, 1fr);
  overflow: hidden;
}
.sidebar { background: #f8faf8; border-right: 1px solid var(--line); padding: 1rem; min-width: 0; }
.sidebar-header { display: grid; gap: .65rem; }
.sidebar p, .chat-header p, .history p, .composer p { font-size: .9rem; }
.sidebar p, .chat-header p, .history p { color: var(--muted); }
.sidebar p:not(:empty), .chat-header p:not(:empty) { margin-top: .65rem; }
#retry-list, #retry-catalog, #retry-history, #more-conversations { margin-top: .5rem; }
.conversation-list, .messages { list-style: none; margin: 0; padding: 0; }
.conversation-list { display: grid; gap: .35rem; margin-top: .75rem; max-height: 67vh; overflow: auto; }
.conversation-list button {
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  width: 100%;
  text-align: start;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.conversation-list button:hover, .conversation-list button[aria-current="true"] {
  background: #e2efe7;
  border-color: #c5ded1;
}
.conversation-list button:focus-visible { outline-offset: -3px; }

.chat { min-width: 0; min-height: min(45rem, calc(100vh - 6rem)); display: flex; flex-direction: column; }
.chat-header, .composer { padding: 1rem clamp(.9rem, 3vw, 1.5rem); }
.chat-header { border-bottom: 1px solid var(--line); }
.routing { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: .75rem; }
.field { display: grid; gap: .25rem; min-width: 0; }
.field select { max-width: 100%; }
.history { flex: 1; min-height: 11rem; max-height: 55vh; overflow: auto; padding: 1rem clamp(.9rem, 3vw, 1.5rem); }
.messages { display: grid; gap: .85rem; }
.messages:not(:empty) + p:not(:empty) { margin-top: .85rem; }
.message { min-width: 0; padding: .75rem .95rem; border-radius: .75rem; background: #f0f4f1; max-width: 90%; justify-self: start; }
.message.user { background: #dff1e8; justify-self: end; }
.message strong { display: block; margin-bottom: .3rem; font-size: .8rem; color: var(--muted); }
.message div { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }

.composer { border-top: 1px solid var(--line); }
.composer p { margin-bottom: .55rem; }
.run-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.run-actions:not(:empty) button:not([hidden]) { margin-bottom: .55rem; }
#prompt-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .7rem; align-items: end; }
#prompt-form label { grid-column: 1 / -1; }
textarea { width: 100%; resize: vertical; }

@media (max-width: 42rem) {
  .workspace { grid-template-columns: minmax(0, 1fr); width: calc(100% - 1rem); margin: .5rem auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: .75rem .9rem; }
  .sidebar-header { display: flex; align-items: center; justify-content: space-between; }
  .conversation-list { display: flex; flex-wrap: wrap; max-height: 8.5rem; }
  .conversation-list:empty { margin-top: 0; }
  .conversation-list li { max-width: 100%; }
  .conversation-list button { border-color: var(--line); }
  .chat { min-height: 30rem; }
  .history { max-height: 48vh; }
  .message { max-width: 96%; }
}
