:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1d2125;
  --muted: #5d656e;
  --line: #e3ddd3;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --bot: #ffffff;
  --user: #2f6fed;
  --user-text: #ffffff;
  --ok: #1f9d55;
  --bad: #d64545;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --surface: #1f2226; --text: #eef0f2; --muted: #a3abb4; --line: #30353b;
    --accent: #4b86f7; --bot: #262a2f; --user: #3b7bf5; --ok: #3ccf7a; --bad: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1f2226; --text: #eef0f2; --muted: #a3abb4; --line: #30353b;
  --accent: #4b86f7; --bot: #262a2f; --user: #3b7bf5; --ok: #3ccf7a; --bad: #ff6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 19px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 1.2em; height: 1.2em; flex: none; }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.avatar svg { width: 34px; height: 34px; }
.who h1 { margin: 0; font-size: 21px; }
.presence { margin: 0; font-size: 15px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.presence.on .dot { background: var(--ok); }
.presence.off .dot { background: var(--bad); }

.chat {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px;
  overscroll-behavior: contain;
}
.msg { display: flex; gap: 8px; max-width: 100%; animation: pop .28s ease-out both; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; }
.msg .mini { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); margin-top: 2px; }
.msg .mini svg { width: 24px; height: 24px; }
.bubble {
  padding: 12px 16px; border-radius: 20px; box-shadow: var(--shadow); max-width: min(560px, 82vw);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bot .bubble { background: var(--bot); border-top-left-radius: 6px; }
.user .bubble { background: var(--user); color: var(--user-text); border-top-right-radius: 6px; }
.user .bubble img { display: block; width: 100%; max-width: 260px; border-radius: 12px; margin-bottom: 8px; }
.caret::after { content: "▍"; animation: blink 1s steps(1) infinite; margin-left: 1px; color: var(--accent); }

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

.card { display: flex; flex-direction: column; gap: 10px; min-width: min(300px, 70vw); }
.bar { height: 14px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 15%, transparent); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .8s ease; }
.bar.waiting > i { width: 30% !important; animation: slide 1.6s ease-in-out infinite; }
.card .line { font-weight: 600; }
.card .sub { color: var(--muted); font-size: 16px; }
.result img { display: block; width: 100%; max-width: 420px; border-radius: 14px; cursor: zoom-in; margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.send, .ghost, .size, .photo-btn {
  min-height: 52px; border-radius: 16px; border: 0; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; text-decoration: none; font-weight: 600;
}
.send { background: var(--accent); color: var(--accent-text); min-width: 56px; padding: 0 16px; }
.send.wide { padding: 0 24px; flex: 1; }
.send:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; color: var(--accent); padding: 0 14px; border: 2px solid currentColor; }
.ghost.small { min-height: 42px; font-size: 16px; }
.ghost.light { color: #fff; }

.composer {
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
}
.send-row { display: flex; gap: 10px; align-items: flex-end; }
.send-row textarea, .send-row input[type=password] {
  flex: 1; min-height: 52px; max-height: 40vh; resize: none; padding: 12px 14px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--bg); outline: none; font-size: 19px;
}
.send-row textarea:focus, .send-row input:focus { border-color: var(--accent); }
.photo-btn { background: var(--bg); border: 2px solid var(--line); padding: 0 12px; color: var(--accent); flex-direction: column; gap: 0; font-size: 13px; min-width: 60px; }
.photo-btn svg { width: 26px; height: 26px; }
.photo-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-btn:focus-within { border-color: var(--accent); }

.sizes { display: flex; gap: 8px; }
.size {
  flex: 1; min-height: 56px; padding: 4px 6px; background: var(--bg); border: 2px solid var(--line);
  flex-direction: column; gap: 0; line-height: 1.15;
}
.size b { font-size: 18px; }
.size small { font-size: 13px; font-weight: 500; color: var(--muted); }
.size[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.size[aria-checked="true"] small { color: var(--accent-text); opacity: .9; }
.who h1 .role { font-weight: 500; color: var(--muted); font-size: 17px; display: inline-block; white-space: nowrap; }
.clear { margin-left: auto; flex-direction: column; gap: 0; font-size: 12px; min-height: 48px; padding: 2px 10px; }
.clear svg { width: 22px; height: 22px; }
.who { min-width: 0; }

.attach-preview { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 16px; background: var(--bg); border: 2px dashed var(--accent); }
.attach-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.attach-text { flex: 1; display: flex; flex-direction: column; font-size: 16px; }
.attach-text span { color: var(--muted); }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: flex; flex-direction: column; z-index: 10; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer-bar { display: flex; gap: 10px; padding: 12px 16px; }
[hidden] { display: none !important; }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) {
  .msg, .typing i, .bar.waiting > i, .caret::after { animation: none; }
}
@media (max-width: 420px) {
  body { font-size: 18px; }
  .who h1 { font-size: 19px; }
  .who h1 .role { font-size: 15px; }
}
