:root {
  --bg: #0f1412;
  --panel: #17201c;
  --panel-2: #1e2a24;
  --ink: #e8f0ea;
  --muted: #9bb0a3;
  --accent: #c4a35a;
  --accent-ink: #1a1408;
  --line: rgba(232, 240, 234, 0.1);
  --danger: #d97b6c;
  --ok: #6fbf8d;
  --warn: #d2b15a;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #24352c 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2a2418 0%, transparent 50%),
    var(--bg);
}

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(165deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  padding: 2rem;
}
.login-card .brand, .brand { font-family: var(--font); font-size: 1.35rem; color: var(--accent); letter-spacing: 0.02em; }
.login-card h1 { font-family: var(--font); font-weight: 500; font-size: 1.6rem; margin: 0.4rem 0 0.2rem; }
.sub, .muted { color: var(--muted); font-size: 0.9rem; }
.login-card label { display: grid; gap: 0.35rem; margin: 0.9rem 0; font-size: 0.85rem; color: var(--muted); }
.login-card input, textarea {
  width: 100%;
  background: #0c100e;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.7rem 0.8rem;
  font: inherit;
}
.error { color: var(--danger); }

.shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}
.sidebar {
  background: rgba(15, 20, 18, 0.92);
  border-right: 1px solid var(--line);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: hidden;
  min-height: 0;
}
.brand-block { margin-bottom: 0.2rem; flex-shrink: 0; }
.section-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.25rem;
  flex-shrink: 0;
}
.agent-list {
  display: grid;
  gap: 0.25rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.15rem;
}
.agent-btn {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  font: inherit;
}
.agent-btn:hover, .agent-btn.active {
  background: var(--panel);
  border-color: var(--line);
}
.agent-name { display: block; font-family: var(--font); }
.agent-title {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}
.history-block.is-open {
  flex: 1 1 auto;
  min-height: 200px;
  overflow: hidden;
}
.history-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.history-toggle:hover {
  background: var(--panel);
}
.history-toggle-label {
  font-family: var(--font);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.history-toggle-chevron {
  color: var(--accent);
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}
.history-block.is-open .history-toggle-chevron {
  transform: rotate(90deg);
}
.history-panel {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}
.history-block.is-open .history-panel {
  display: flex;
}
.history-panel[hidden] {
  display: none !important;
}
.history {
  flex: 1 1 auto;
  min-height: 160px;
  max-height: min(48vh, 420px);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.15rem 0.2rem 0.35rem 0;
  border: 1px solid var(--line);
  background: rgba(12, 16, 14, 0.45);
}
.history-block.is-open .history {
  max-height: none;
}
.history button,
.history .history-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  width: 100%;
  flex-shrink: 0;
}
.history button:hover,
.history .history-item:hover {
  background: var(--panel);
  border-color: var(--line);
}
.history button.active,
.history .history-item.active {
  color: var(--ink);
  background: rgba(196, 163, 90, 0.14);
  border-color: rgba(196, 163, 90, 0.55);
  box-shadow: inset 3px 0 0 var(--accent);
}
.history-item-title {
  display: block;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--ink);
}
.history-item-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.history-empty {
  padding: 0.85rem 0.7rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.sidebar-foot {
  margin-top: 0;
  display: grid;
  gap: 0.35rem;
  flex-shrink: 0;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  font: inherit;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: wait; }

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}
.main-header {
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}
.responding { font-family: var(--font); font-size: 1.15rem; }
.route-hint { max-width: 42ch; }

.messages {
  overflow: auto;
  padding: 1.25rem 1.4rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.bubble {
  max-width: min(720px, 92%);
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  background: rgba(23, 32, 28, 0.85);
  white-space: pre-wrap;
  line-height: 1.45;
}
.bubble.user { align-self: flex-end; background: rgba(196, 163, 90, 0.12); }
.bubble.assistant { align-self: flex-start; }
.bubble .who {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.35rem;
  font-family: var(--font);
}

.composer {
  border-top: 1px solid var(--line);
  padding: 0.9rem 1.4rem 1.2rem;
  background: rgba(15, 20, 18, 0.9);
}
#chat-form { display: grid; gap: 0.55rem; }
#message-input {
  resize: vertical;
  min-height: 64px;
  background: #0c100e;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.75rem 0.9rem;
  font: inherit;
}
#file-input { display: none; }
.composer-actions { display: flex; align-items: center; gap: 0.75rem; }
.attach { cursor: pointer; color: var(--accent); font-size: 0.9rem; }

dialog {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  width: min(640px, 92vw);
  padding: 1rem 1.1rem 1.2rem;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.dialog-head h2 { margin: 0; font-family: var(--font); font-weight: 500; font-size: 1.2rem; }
.connector-row, .approval-card {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.approval-card { flex-direction: column; }
.approval-actions { display: flex; gap: 0.5rem; }
.status { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.status-connected { color: var(--ok); }
.status-not_configured { color: var(--warn); }
.status-disabled { color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { max-height: none; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .agent-list { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
  .history-block.is-open { min-height: 180px; max-height: 46vh; }
  .history { max-height: 36vh; }
}
