/* Hermes Bot Web — mobile-first chat UI
   Optimized for instant first paint + 60fps streaming render
   No framework — direct DOM manipulation, rAF batching */

:root {
  --bg: #0a0a0c;
  --bg-elev: #15151a;
  --bg-input: #1c1c22;
  --border: #2a2a32;
  --text: #e8e8ec;
  --text-dim: #888894;
  --text-faint: #55555f;
  --accent: #6c8aff;
  --accent-soft: rgba(108, 138, 255, 0.12);
  --user-bubble: #2a3a6e;
  --success: #4ade80;
  --error: #f87171;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  user-select: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  font-feature-settings: "kern" 1, "liga" 1;
  text-rendering: optimizeLegibility;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ── Loading state (first paint) ───────────────────────── */
.loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.loading .dot {
  width: 8px; height: 8px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.loading .dot:nth-child(2) { animation-delay: 0.15s; }
.loading .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.7); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Header ───────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 10;
}
.header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}
.status-dot.offline { background: var(--error); }

/* ── Messages ──────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 12px 0;
  scroll-behavior: smooth;
  user-select: text;
}

.bubble {
  max-width: 85%;
  margin-bottom: 12px;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15.5px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  animation: fadeIn 0.18s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble.user {
  margin-left: auto;
  background: var(--user-bubble);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  margin-right: auto;
  background: var(--bg-elev);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble.system {
  margin: 8px auto;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: center;
  padding: 4px 12px;
  max-width: 100%;
}

/* streaming cursor */
.bubble.assistant.streaming::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s infinite;
  margin-left: 2px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* tool call indicator inside bubble */
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  padding: 4px 9px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 13px;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.tool.running { animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* inline code */
.bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
}

/* code blocks */
.bubble pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
  margin: 6px 0;
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13.5px;
  line-height: 1.4;
}

/* empty state */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-dim);
  text-align: center;
}
.empty h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.empty p { font-size: 14px; max-width: 320px; }
.empty .chips {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 360px;
}
.chip {
  padding: 8px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
.chip:active { background: var(--accent-soft); }

/* ── Input bar ─────────────────────────────────────────── */
.input-bar {
  flex-shrink: 0;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
}

.input-wrap {
  flex: 1;
  background: var(--bg-input);
  border-radius: 22px;
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 4px 4px 4px 14px;
  transition: border-color 0.15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
}

#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  line-height: 1.4;
  padding: 8px 4px;
  resize: none;
  max-height: 140px;
  min-height: 38px;
  user-select: text;
  -webkit-user-select: text;
}

#send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
  touch-action: manipulation;
}
#send:disabled {
  background: var(--border);
  color: var(--text-faint);
  cursor: default;
}
#send:active:not(:disabled) { transform: scale(0.92); }
#send.stop { background: var(--error); }

/* ── Mobile landscape tweaks ───────────────────────────── */
@media (max-height: 500px) {
  .header { padding-top: 6px; padding-bottom: 6px; }
  .header h1 { font-size: 15px; }
  .empty h2 { font-size: 18px; }
  .empty p { font-size: 13px; }
}

/* ── Dark mode focus rings ─────────────────────────────── */
button:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
