:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #18222e;
  --muted: #5c6b7a;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --me: #1f3a5f;
  --bot: #e9eef4;
  --error: #b00020;
  --line: #dfe5ec;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 16px 0;
  height: calc(52px + env(safe-area-inset-top));
  background: var(--brand);
  color: var(--brand-ink);
}
.brand { font-weight: 600; letter-spacing: 0.2px; }

#app { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 720px; margin: 0 auto; }
.view { flex: 1; display: flex; flex-direction: column; padding: 16px; }

h1 { font-size: 1.4rem; margin: 8px 0 4px; }
.muted { color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
label { font-size: 0.85rem; color: var(--muted); }
input {
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1.02rem;
  font-weight: 600;
}
.primary:active { opacity: 0.9; }

.link-btn { background: none; border: none; color: var(--brand); font-size: 0.95rem; padding: 4px; }
.topbar .link-btn { color: var(--brand-ink); opacity: 0.9; }

.msg { color: var(--muted); min-height: 1.2em; }
.msg.error { color: var(--error); }

/* Chat */
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.me { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--bot); color: var(--ink); border-bottom-left-radius: 4px; }
.bubble.pending { opacity: 0.6; font-style: italic; }

.composer {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
}
.composer input { flex: 1; }
