:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --accent: var(--tg-theme-button-color, #b5651d);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  padding: 12px 16px calc(10px);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.title { font-size: 17px; font-weight: 600; }
.subtitle { font-size: 12px; color: var(--hint); margin-top: 2px; }

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--secondary-bg);
  color: var(--text);
  border-bottom-left-radius: 5px;
}
.msg .imgnote {
  display: block;
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 4px;
}
.msg.assistant.typing::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.empty {
  margin: auto;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
  max-width: 260px;
  line-height: 1.5;
}

.thumbs {
  display: flex;
  gap: 8px;
  padding: 0 12px;
  overflow-x: auto;
  flex: 0 0 auto;
}
.thumbs:empty { display: none; }
.thumbs img {
  height: 56px;
  width: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.thumb-wrap { position: relative; flex: 0 0 auto; margin: 8px 0; }
.thumb-wrap button {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.attach {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--secondary-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--hint);
  cursor: pointer;
}
.input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 9px 13px;
  font: inherit;
  color: var(--text);
  background: var(--secondary-bg);
  outline: none;
}
.btn-analyze {
  flex: 0 0 auto;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}
.btn-analyze:disabled { opacity: 0.4; cursor: default; }
.btn-send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  cursor: pointer;
}
.btn-send:disabled { opacity: 0.5; cursor: default; }

.flash {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 88%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }
