/* Web chat: calm, light, teal accent. No external fonts or assets. */

:root {
  --bg: #f7f9f9;
  --surface: #ffffff;
  --sidebar: #eff4f4;
  --line: #dde5e6;
  --line-strong: #c9d4d6;
  --text: #1b2433;
  --muted: #5d6b78;
  --faint: #8a97a3;
  --accent: #0e8577;
  --accent-strong: #0a6b60;
  --accent-soft: #e2f3f0;
  --accent-tint: #f0f9f7;
  --mint: #34e0b0;
  --slate: #1b2433;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 36, 51, 0.06), 0 4px 16px rgba(27, 36, 51, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.button-primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 20px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
  transition: background 0.15s;
}
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }

.link-button {
  border: 0; background: none; padding: 4px 2px;
  color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}
.link-button:hover { color: var(--text); }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: none; color: var(--muted);
}
.icon-button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- login ---------- */

.login-page {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100%; padding: 32px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.login-card {
  width: 100%; max-width: 400px;
  padding: 36px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { display: block; margin: 0 auto 18px; border-radius: 18px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; line-height: 1.3; letter-spacing: -0.01em; }
.login-lead { margin: 0 0 26px; color: var(--muted); font-size: 15px; }

#login-form { display: flex; flex-direction: column; text-align: left; }
#login-form label { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
#login-form input {
  height: 46px; margin-bottom: 16px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff;
  font-size: 16px;
}
#login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#login-form .button-primary { margin-top: 6px; }

.form-error {
  margin: 0 0 12px; padding: 10px 12px;
  border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px;
}
.login-foot { margin: 22px 0 0; color: var(--muted); font-size: 14px; text-align: center; }

/* ---------- chat layout ---------- */

.chat-page { overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 16px 12px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; }
.brand img { border-radius: 9px; flex: none; }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.25; }

.button-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; margin: 0 4px 18px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); font-weight: 600; font-size: 15px; color: var(--accent-strong);
  transition: border-color 0.15s, background 0.15s;
}
.button-new:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-tint); }

.conversation-nav { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.nav-heading {
  margin: 0 8px 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--faint);
}
.conversation-list { list-style: none; margin: 0; padding: 0; }
.conversation { position: relative; display: flex; align-items: center; border-radius: 10px; }
.conversation:hover { background: rgba(14, 133, 119, 0.07); }
.conversation.active { background: var(--surface); box-shadow: 0 1px 2px rgba(27, 36, 51, 0.08); }
.conversation-link {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 9px 36px 9px 10px; color: inherit; text-decoration: none;
}
.conversation-title { font-size: 14px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation.active .conversation-title { font-weight: 600; }
.conversation-date { font-size: 12px; color: var(--faint); }
.conversation-delete {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 0; border-radius: 8px;
  background: none; color: var(--faint); opacity: 0; transition: opacity 0.15s;
}
.conversation:hover .conversation-delete, .conversation.active .conversation-delete, .conversation-delete:focus-visible { opacity: 1; }
.conversation-delete:hover { color: var(--danger); background: var(--danger-soft); }
.list-empty { margin: 4px 10px; font-size: 14px; color: var(--faint); }

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 10px; padding: 12px 8px 2px; border-top: 1px solid var(--line);
}
.user-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 20px; flex: none;
  border-bottom: 1px solid var(--line); background: rgba(247, 249, 249, 0.9);
}
.chat-title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-toggle, .new-chat-top { display: none; }

.scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 28px 20px 12px; }

/* ---------- intro ---------- */

.intro { max-width: 640px; margin: 4vh auto 0; text-align: center; }
.intro-logo { border-radius: 16px; margin-bottom: 14px; }
.intro h2 { margin: 0 0 8px; font-size: 24px; line-height: 1.3; letter-spacing: -0.01em; }
.intro-lead { margin: 0 auto 20px; max-width: 520px; color: var(--muted); }
.intro-facts {
  list-style: none; margin: 0 auto 26px; padding: 14px 18px; max-width: 520px;
  text-align: left; font-size: 15px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.intro-facts li { position: relative; padding: 5px 0 5px 26px; }
.intro-facts li::before {
  content: ""; position: absolute; left: 4px; top: 13px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.intro-examples-label { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.examples { display: flex; flex-direction: column; align-items: stretch; gap: 8px; max-width: 520px; margin: 0 auto; }
.example {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; text-align: left;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface);
  font-size: 15px; color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.example::after { content: "→"; flex: none; color: var(--accent); }
.example:hover { border-color: var(--accent); background: var(--accent-tint); }

/* ---------- messages ---------- */

.messages { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.message.user { display: flex; justify-content: flex-end; }
.message.user .bubble {
  max-width: 85%; padding: 10px 15px;
  background: var(--accent-soft); color: var(--text);
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.message.assistant { display: flex; align-items: flex-start; gap: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 8px; flex: none; margin-top: 2px; }
.assistant-body { flex: 1; min-width: 0; }

.progress {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  min-height: 34px; padding: 6px 12px;
  border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px;
}
.progress-label { min-width: 0; overflow-wrap: anywhere; }
.progress-count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.spinner {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.message.failed .error-text {
  margin: 0; padding: 10px 14px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger); font-size: 15px;
}

.steps { margin-top: 10px; font-size: 13px; color: var(--muted); }
.steps summary { cursor: pointer; width: fit-content; color: var(--faint); list-style: none; }
.steps summary::-webkit-details-marker { display: none; }
.steps summary::before { content: "▸ "; }
.steps[open] summary::before { content: "▾ "; }
.steps summary:hover { color: var(--accent-strong); }
.steps ol { margin: 6px 0 0; padding-left: 22px; }
.steps li { margin: 2px 0; overflow-wrap: anywhere; }

/* ---------- rendered Markdown ---------- */

.markdown { overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 12px; }
.markdown h3, .markdown h4, .markdown h5 { margin: 20px 0 8px; line-height: 1.3; }
.markdown h3 { font-size: 18px; }
.markdown h4 { font-size: 16px; }
.markdown h5 { font-size: 15px; color: var(--muted); }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 24px; }
.markdown li { margin: 4px 0; }
.markdown li > ul, .markdown li > ol { margin: 4px 0 0; }
.markdown strong { font-weight: 650; }
.markdown a { color: var(--accent-strong); text-underline-offset: 2px; }
.markdown code {
  font-family: var(--mono); font-size: 0.88em;
  padding: 0.12em 0.38em; border-radius: 5px;
  background: #e9eff0; color: #1d3a40;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.markdown pre {
  margin: 0 0 14px; padding: 12px 14px; overflow-x: auto;
  border-radius: 10px; background: var(--slate); color: #e6edf3;
  font-size: 13.5px; line-height: 1.5;
}
.markdown pre code { padding: 0; background: none; color: inherit; font-size: inherit; white-space: pre; overflow-wrap: normal; }
.markdown blockquote {
  margin: 0 0 12px; padding: 4px 14px;
  border-left: 3px solid var(--accent); color: var(--muted); background: var(--accent-tint); border-radius: 0 8px 8px 0;
}
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.markdown .table-wrap { margin: 0 0 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.markdown table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.markdown th, .markdown td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.markdown th { background: var(--accent-tint); font-weight: 600; }
.markdown tr:last-child td { border-bottom: 0; }
.markdown .align-center { text-align: center; }
.markdown .align-right { text-align: right; }
.markdown td code { overflow-wrap: normal; white-space: nowrap; }

/* ---------- composer ---------- */

.composer-wrap { flex: none; padding: 8px 20px 14px; background: linear-gradient(to bottom, rgba(247, 249, 249, 0), var(--bg) 30%); }
.notice {
  max-width: 760px; margin: 0 auto 8px; padding: 9px 14px;
  border-radius: 10px; background: #fff6e5; color: #7a4b00; border: 1px solid #f3d9a4; font-size: 14px;
}
.composer {
  position: relative; display: flex; align-items: flex-end; gap: 8px;
  max-width: 760px; margin: 0 auto; padding: 8px 8px 8px 16px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 220px; padding: 8px 0; resize: none;
  border: 0; outline: none; background: transparent; font-size: 16px; line-height: 1.5;
}
.composer textarea:disabled { background: transparent; opacity: 0.6; }
.send-button, .stop-button {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border: 0; border-radius: 11px;
  background: var(--accent); color: #fff; transition: background 0.15s;
}
.send-button:hover { background: var(--accent-strong); }
.stop-button { background: var(--slate); }
.stop-button:hover { background: #2c3a50; }
.composer-hint { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 12.5px; color: var(--faint); }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20;
    width: min(320px, 86vw);
    transform: translateX(-102%); transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(27, 36, 51, 0.18);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(27, 36, 51, 0.35); }
  .scrim[hidden] { display: none; }
  .menu-toggle, .new-chat-top { display: inline-flex; }
  .topbar { padding: 0 8px; }
  .chat-title { text-align: center; }
  .scroller { padding: 18px 14px 8px; }
  .intro { margin-top: 0; }
  .intro-logo { width: 48px; height: 48px; margin-bottom: 8px; }
  .intro h2 { font-size: 20px; }
  .intro-lead { font-size: 15px; margin-bottom: 16px; }
  .intro-facts { padding: 10px 14px; font-size: 14.5px; margin-bottom: 20px; }
  .intro-facts li { padding: 4px 0 4px 22px; }
  .intro-facts li::before { top: 12px; left: 2px; }
  .example { padding: 11px 14px; }
  .composer-wrap { padding: 6px 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .message.user .bubble { max-width: 92%; }
  .message.assistant { gap: 10px; }
  .avatar { width: 26px; height: 26px; }
  .conversation-delete { opacity: 1; }
}
