:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef3f8;
  --text: #17202a;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f3ef;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

h1, h2, p { margin: 0; }
.brand h1 { font-size: 18px; }
.brand p, .landing-copy p, .conversationMeta, .list-card span, .message-meta span { color: var(--muted); font-size: 13px; }

.base-url {
  flex: 1;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}

.primary-button, .secondary-button, .ghost-button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 700;
}

.primary-button { color: #fff; background: var(--accent); }
.secondary-button { color: var(--accent-strong); border-color: #9ad8cf; background: var(--accent-soft); }
.ghost-button { color: var(--muted); border-color: var(--line); background: #fff; }
.ghost-button.danger { color: var(--danger); border-color: #f2b8b5; background: var(--danger-soft); }

.status-badge {
  min-width: 96px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  text-align: center;
  font-size: 13px;
}
.status-badge.ok { color: var(--accent-strong); border-color: #9ad8cf; background: var(--accent-soft); }
.status-badge.error { color: var(--danger); border-color: #f2b8b5; background: var(--danger-soft); }

.landing-view {
  padding: 48px 24px;
  display: grid;
  gap: 28px;
  align-content: start;
}

.landing-copy h2 { margin-bottom: 10px; font-size: 32px; }
.user-cards { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 16px; }
.user-card {
  min-height: 180px;
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-align: left;
  text-decoration: none;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.user-card strong { font-size: 24px; }
.user-card p { color: var(--muted); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(480px, 1fr) 420px;
}

.sidebar, .debug-panel {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: var(--panel);
}
.sidebar { border-right: 1px solid var(--line); }
.debug-panel { border-left: 1px solid var(--line); }

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 18px;
}

.identity-card, .panel-section {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.identity-card { display: grid; gap: 6px; }
.identity-card span, .section-title span { font-size: 13px; font-weight: 800; }
.identity-card strong { font-size: 22px; }
.identity-card p { color: var(--muted); }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.item-list { display: grid; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; }
.list-card {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  background: #fff;
}
.list-card.active { border-color: #9ad8cf; background: var(--accent-soft); }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.chat-header h2 { font-size: 22px; }
.chat-header p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.chat-actions { display: flex; align-items: center; gap: 8px; }
.live-badge {
  min-width: 84px;
  padding: 8px 10px;
  border: 1px solid #9ad8cf;
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}
.live-badge.paused { color: var(--muted); border-color: var(--line); background: #fff; }
.live-badge.error { color: var(--danger); border-color: #f2b8b5; background: var(--danger-soft); }

.message-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.message-card {
  max-width: 78%;
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.message-card.mine { justify-self: end; border-color: #9ad8cf; background: var(--accent-soft); }
.message-meta { display: flex; justify-content: space-between; gap: 10px; }
.message-card code { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.composer { margin-top: 12px; display: grid; gap: 10px; }
.composer-row { display: grid; grid-template-columns: 1fr 100px; gap: 8px; }
.composer-row.compact { grid-template-columns: 1fr 1fr; }

.detail-box pre, pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 280px 1fr; }
  .debug-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .workspace, .user-cards, .composer-row, .composer-row.compact { grid-template-columns: 1fr; }
  .message-card { max-width: 100%; }
}
