:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #5d6876;
  --border: #dde1e6;
  --field-border: #8b95a1;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --user: #1f2a37;
  --user-text: #f8fafc;
  --error: #b42318;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #182029;
    --text: #e7eaee;
    --muted: #9aa5b1;
    --border: #2a333d;
    --field-border: #6b7684;
    --accent: #f97316;
    --accent-text: #111111;
    --user: #2c3a49;
    --user-text: #f3f5f7;
    --error: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #182029; --text: #e7eaee; --muted: #9aa5b1; --border: #2a333d; --field-border: #6b7684;
  --accent: #f97316; --accent-text: #111111; --user: #2c3a49; --user-text: #f3f5f7; --error: #ff8a80;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* login */
.login { height: 100%; overflow-y: auto; padding: 12vh 16px 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 16px; }
.login-card input { width: 100%; height: 48px; padding: 0 14px; font-size: 16px; border: 1px solid var(--field-border); border-radius: 12px; background: var(--bg); margin-bottom: 12px; }
.primary { width: 100%; height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }

/* app shell: sized to the visible viewport so the composer stays above the iOS keyboard */
.app {
  position: fixed;
  left: 0; right: 0;
  top: var(--app-top, 0px);
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}
.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title { font-weight: 650; font-size: 17px; }
.ghost { min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 22px; background: transparent; cursor: pointer; font-size: 14px; }
.ghost.armed { border-color: var(--error); color: var(--error); }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg.welcome { color: var(--muted); }
.md p { margin: 0 0 8px; }
.md p:last-child, .md ul:last-child, .md ol:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 2px 0 8px; padding-left: 20px; }
.md li { margin: 3px 0; }
.md strong { font-weight: 650; }
.md code { font-size: 14px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.msg .err { color: var(--error); font-size: 14px; margin-top: 6px; }
.fb { display: flex; gap: 6px; margin-top: 8px; }
.fb button { min-width: 48px; height: 40px; border: 1px solid var(--border); border-radius: 20px; background: transparent; cursor: pointer; font-size: 15px; }
.fb button.on { background: var(--accent); border-color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.status { flex: none; display: flex; align-items: center; gap: 8px; padding: 2px 16px; min-height: 36px; color: var(--muted); font-size: 14px; }
.status .link { margin-left: auto; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite ease-in-out; }

.composer { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 12px calc(env(safe-area-inset-bottom) + 6px); }
.row { display: flex; align-items: flex-end; gap: 8px; }
textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 10px 14px;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--field-border);
  border-radius: 22px;
  outline: none;
}
textarea:focus { border-color: var(--muted); }
.icon, .send {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--text);
}
.icon.live { background: #b42318; border-color: #b42318; color: #ffffff; }
.send { border: 0; background: var(--accent); color: var(--accent-text); }
.send:disabled { opacity: 0.4; cursor: default; }
.previews { display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px 10px; }
.preview { position: relative; flex: none; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.preview .remove { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); background: var(--text); color: var(--surface); font-size: 17px; line-height: 1; cursor: pointer; padding: 0; }
.preview .remove::before { content: ""; position: absolute; inset: -9px; }  /* 46px touch area */
.hint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 6px; min-height: 1em; }

/* links that act as buttons; padding grows the touch area without moving the text */
.link { background: none; border: 0; padding: 10px 4px; margin: -10px 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; font-size: inherit; }
.on-dark { color: inherit; }
.failed { margin-top: 6px; font-size: 14px; color: #fecaca; white-space: normal; }

.toast {
  position: absolute; /* inside .app, so it follows the visible area when the keyboard is up */
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 110px);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
