:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1d2b3a;
  --line: #2a3a4d;
  --text: #e7eef5;
  --muted: #93a4b6;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
  --user: #23415c;
  --error: #f87171;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  height: 100%; margin: 0; overflow-x: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }

/* Login */
.login-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  overflow: auto;
  background: radial-gradient(1200px 600px at 50% -10%, #14303a, var(--bg));
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-card h1 { font-size: 22px; margin: 0; }
.login-card p { color: var(--muted); margin: 0; font-size: 14px; }
.login-card input, #input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 13px 14px; font-size: 16px; outline: none; /* 16px: no iOS zoom */
  width: 100%; font-family: inherit;
}
.login-card input:focus, #input:focus { border-color: var(--accent); }
.login-card button, #send {
  background: var(--accent); color: #06231f; border: none; border-radius: 10px;
  padding: 13px 16px; font-weight: 700; font-size: 16px; cursor: pointer; min-height: 48px;
}
.login-error { color: var(--error); font-size: 13px; min-height: 16px; }

/* App layout: dynamic viewport height so the mobile keyboard never hides the input */
#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 880px; margin: 0 auto;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.title { font-weight: 700; font-size: 17px; }
.subtitle { color: var(--muted); font-size: 12.5px; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 9px 12px; cursor: pointer; font-size: 13px; flex: none;
  min-height: 38px; white-space: nowrap;
}

.chat {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
.welcome { color: var(--muted); font-size: 15px; }
.header-actions { display: flex; gap: 8px; flex: none; align-items: center; }
#help { min-width: 38px; font-weight: 700; }
.help-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; align-self: flex-start; max-width: 92%; }
.help-heading { color: var(--text); font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.help-cat { color: var(--muted); font-size: 12px; margin: 14px 0 6px; }
.help-hint { color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 10px 14px; font-size: 13.5px; cursor: pointer;
  min-height: 40px; display: inline-flex; align-items: center;
}

.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.bubble {
  padding: 11px 15px; border-radius: 16px; white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.error .bubble { border-color: var(--error); }

.trace { margin-top: 6px; font-size: 12px; color: var(--muted); }
.trace summary { cursor: pointer; user-select: none; padding: 4px 0; }
.trace .row {
  padding: 4px 0 0 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
  overflow-wrap: anywhere; word-break: break-word;
}
.trace .row b { color: var(--accent-2); font-weight: 600; }

.typing { color: var(--muted); font-style: italic; }

footer {
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
#chat-form { display: flex; gap: 10px; align-items: flex-end; }
#input { flex: 1; resize: none; max-height: 140px; min-height: 48px; line-height: 1.35; }
#send { white-space: nowrap; flex: none; padding: 0 20px; }
#send:disabled { opacity: .5; cursor: default; }
.disclaimer { color: var(--muted); font-size: 11px; margin-top: 8px; text-align: center; }

/* Installed-to-home-screen (standalone) app: fill the real screen height so there is no
   dead strip at the bottom where Safari's bar used to be. The input bar sits flush above
   the home-indicator safe area. */
@media (display-mode: standalone) {
  #app { height: -webkit-fill-available; }
}

/* Hover effects only where a real pointer exists (avoid sticky hover on touch) */
@media (hover: hover) {
  .ghost:hover { color: var(--text); border-color: var(--accent); }
  .chip:hover { border-color: var(--accent); }
}
/* Touch press feedback */
.chip:active { border-color: var(--accent); background: var(--panel-2); }
.ghost:active { border-color: var(--accent); color: var(--text); }
#send:active:not(:disabled) { filter: brightness(0.94); }

@media (max-width: 600px) {
  .msg { max-width: 92%; }
  .chat { padding: 14px; gap: 12px; }
  .subtitle { display: none; }            /* reclaim header height on phones */
  .bubble { padding: 10px 14px; }
}
