:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #e2e1dc;
  --accent: #c27c0e;
  --accent-text: #ffffff;
  --user-bubble: #c27c0e;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --error: #b42318;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1f1f1d;
    --text: #ecebe6;
    --muted: #9a9993;
    --border: #33332f;
    --accent: #e5a00d;
    --accent-text: #1a1406;
    --user-bubble: #e5a00d;
    --user-text: #1a1406;
    --bot-bubble: #262624;
    --error: #f97066;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }

h1 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.error { color: var(--error); margin: 0; font-size: 0.92rem; }

button {
  font: inherit;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; color: var(--text); border-color: var(--border); }

/* ----- login ----- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  display: grid;
  gap: 0.9rem;
}
.card p { margin: 0; }
label { display: grid; gap: 0.35rem; font-size: 0.92rem; font-weight: 500; }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
}

/* ----- chat ----- */
.chat {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  max-width: 820px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 16px;
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.topbar-actions button { padding: 0.4rem 0.75rem; font-size: 0.9rem; }

.messages {
  overflow-y: auto;
  padding: 1rem 16px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.msg {
  max-width: min(85%, 640px);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bot-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.notice { align-self: center; background: transparent; color: var(--muted); font-size: 0.9rem; padding: 0.2rem; }
.msg.error-msg { align-self: flex-start; color: var(--error); border: 1px solid var(--error); background: transparent; }

.typing { display: inline-flex; gap: 4px; padding: 0.85rem 1rem; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: 0.6; } }

.empty { margin: auto; text-align: center; color: var(--muted); }
.suggestions { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.suggestion { background: var(--surface); color: var(--text); border-color: var(--border); font-size: 0.92rem; }

.confirm-bar {
  margin: 0 16px 0.5rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.confirm-actions { display: flex; gap: 0.5rem; }

.composer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.75rem 16px calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer textarea { resize: none; max-height: 10rem; }

@media (max-width: 520px) {
  #whoami { display: none; }
  .msg { max-width: 92%; }
}
