:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ------------------------- Login ------------------------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 340px;
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-name { font-size: 26px; font-weight: 700; letter-spacing: 2px; color: var(--blue); }
.brand-sub { font-size: 12px; letter-spacing: 2px; color: var(--muted); margin-top: 4px; }

#login-form { display: flex; flex-direction: column; }
#login-form label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
#login-form input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
#login-form input:focus { outline: none; border-color: var(--blue); }

/* ------------------------- Buttons ------------------------- */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
}

/* ------------------------- Header ------------------------- */
.app-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand { font-weight: 700; color: var(--blue); letter-spacing: 1px; }
.header-divider { color: var(--border); margin: 0 8px; }
.header-title { color: var(--text); }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.header-email { color: var(--text); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }

/* ------------------------- Layout ------------------------- */
.layout {
  max-width: 900px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; }

/* ------------------------- Search ------------------------- */
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.search-row input:focus { outline: none; border-color: var(--blue); }

.result-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
}
.result-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.result-list li:last-child { border-bottom: none; }
.result-list li:hover { background: #f0f5ff; }
.result-list .r-name { font-weight: 600; }
.result-list .r-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ------------------------- Selected ------------------------- */
.selected-box {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fafbfc;
}
.selected-title { font-weight: 600; margin-bottom: 12px; }
.selected-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; margin-bottom: 16px; }
.selected-grid > div { display: flex; flex-direction: column; }
.selected-grid .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.mono { font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; word-break: break-all; }

/* ------------------------- Chat ------------------------- */
.chat-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 14px;
  gap: 16px;
}
.chat-meta, .chat-endpoint { display: flex; flex-direction: column; gap: 4px; }
.chat-meta .lbl, .chat-endpoint .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.chat-endpoint select {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.messages {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 260px;
  max-height: 440px;
  overflow-y: auto;
  padding: 14px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { max-width: 85%; }
.msg .role { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 4px; }
.msg .bubble {
  padding: 10px 12px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { align-self: flex-end; text-align: right; }
.msg.user .role { color: var(--blue); }
.msg.user .bubble { background: var(--blue); color: #fff; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .role { color: var(--muted); }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--border); }

.composer { display: flex; gap: 8px; margin-top: 14px; }
.composer input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.composer input:focus { outline: none; border-color: var(--blue); }

.session-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.error-text { color: var(--red); font-size: 13px; margin: 10px 0 0; }
