:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --user: #1d4ed8;
  --asst: #334155;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid #334155;
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 17px; margin: 0; color: var(--accent); }
header button {
  background: transparent; border: 0; color: var(--muted); font-size: 18px; cursor: pointer;
}
#chat {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 88%; padding: 10px 14px; border-radius: 14px;
  white-space: pre-wrap; word-break: break-word; line-height: 1.5; font-size: 15px;
}
.msg.user { align-self: flex-end; background: var(--user); color: #fff; }
.msg.asst { align-self: flex-start; background: var(--asst); }
.msg.error { align-self: center; background: #7f1d1d; color: #fee2e2; font-size: 13px; }
.msg.thinking { align-self: flex-start; background: var(--asst); color: var(--muted); font-style: italic; }
.msg code, .msg pre {
  background: rgba(0,0,0,.35); padding: 2px 6px; border-radius: 4px; font-size: 13px;
}
.msg pre { padding: 8px; overflow-x: auto; }
#form {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px; background: var(--panel); border-top: 1px solid #334155;
}
#input {
  flex: 1; resize: none; border: 0; border-radius: 18px; padding: 10px 14px;
  background: #0f172a; color: var(--text); font-size: 16px; max-height: 140px;
  font-family: inherit;
}
#input:focus { outline: 1px solid var(--accent); }
#sendBtn {
  background: var(--accent); color: #0f172a; border: 0; border-radius: 18px;
  padding: 10px 16px; font-weight: bold; font-size: 14px; cursor: pointer;
}
#sendBtn:disabled { opacity: .5; }
#micBtn, #attachBtn {
  background: #334155; color: var(--text); border: 0; border-radius: 50%;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer; flex-shrink: 0;
}
#micBtn.recording { background: #dc2626; }
#attachBtn.has-files { background: #0ea5e9; }
#attachments {
  display: flex; gap: 6px; padding: 4px 8px; flex-wrap: wrap; background: var(--panel);
}
#attachments .chip {
  background: #334155; color: var(--text); padding: 4px 8px; border-radius: 12px;
  font-size: 12px; display: inline-flex; align-items: center; gap: 4px;
}
#attachments .chip button {
  background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 0;
}
.timestamp { font-size: 11px; color: var(--muted); margin-top: 4px; }
