:root {
  --tg-ai-z: 10000;
  --tg-ai-size-w: 360px;
  --tg-ai-size-h: 520px;
  --tg-ai-radius: 12px;
  --tg-ai-gap: 10px;
  --tg-ai-bg: #ffffff;
  --tg-ai-border: #e6e6e6;
  --tg-ai-shadow: 0 10px 30px rgba(0,0,0,0.15);
  --tg-ai-primary: #0b6ef3;
  --tg-ai-assistant: #f5f7fb;
  --tg-ai-user: #e8f0fe;
}

.tg-ai-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--tg-ai-z);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Launcher */
.tg-ai-chat__launcher {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #79C879;
  color: #fff;
  box-shadow: var(--tg-ai-shadow);
}
.tg-ai-chat__launcher:focus { outline: 3px solid #79C879; outline-offset: 2px; }

/* Panel */
.tg-ai-chat__panel {
  position: absolute;
  right: 0; bottom: 72px;
  width: var(--tg-ai-size-w);
  max-width: calc(100vw - 24px);
  height: var(--tg-ai-size-h);
  max-height: calc(100vh - 100px);
  background: var(--tg-ai-bg);
  border: 1px solid var(--tg-ai-border);
  border-radius: var(--tg-ai-radius);
  box-shadow: var(--tg-ai-shadow);
  display: flex;
  flex-direction: column;
  opacity: 0; transform: translateY(10px) scale(0.98);
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.tg-ai-chat__panel[aria-hidden="false"] {
  opacity: 1; transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.tg-ai-chat__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--tg-ai-border);
  background: #000000;
}
.tg-ai-chat__header h2 {
  margin: 0; font-size: 16px; font-weight: 600;
  color: #79C879;
}
.tg-ai-chat__header-actions button {
  border: none; background: transparent; cursor: pointer;
  font-size: 16px; margin-left: 6px; padding: 6px; border-radius: 6px;
  color: #79C879;
}
.tg-ai-chat__header-actions button:hover { background: #1a1a1a; }

/* Messages */
.tg-ai-chat__messages {
  padding: 12px;
  overflow: auto;
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
  background: #fafafa;
}
.tg-ai-chat__msg {
  max-width: 100%;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.35;
  word-wrap: break-word;
  border: 1px solid var(--tg-ai-border);
  background: #fff;
  box-sizing: border-box;
}
.tg-ai-chat__msg--assistant { background: var(--tg-ai-assistant); align-self: flex-start; }
.tg-ai-chat__msg--user { background: var(--tg-ai-user); align-self: flex-end; }

.tg-ai-chat__msg--typing {
  display: inline-flex; gap: 4px; align-items: center; opacity: 0.8;
}
.tg-ai-chat__dot { width: 6px; height: 6px; border-radius: 50%; background: #888; animation: tg-ai-bounce 1s infinite ease-in-out; }
.tg-ai-chat__dot:nth-child(2){ animation-delay: .15s; }
.tg-ai-chat__dot:nth-child(3){ animation-delay: .3s; }
@keyframes tg-ai-bounce { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1); } }

/* Composer */
.tg-ai-chat__composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px; border-top: 1px solid var(--tg-ai-border);
  background: var(--tg-ai-bg);
}
.tg-ai-chat__input {
  flex: 1; min-height: 36px; max-height: 120px; resize: none;
  border: 2px solid #79C879; border-radius: 10px; padding: 8px 10px;
}
.tg-ai-chat__input:focus {
  outline: none;
  border-color: #79C879;
  box-shadow: 0 0 0 2px rgba(121, 200, 121, 0.2);
}
.tg-ai-chat__send {
  padding: 8px 12px; border-radius: 10px; border: none; cursor: pointer;
  background: transparent; color: #79C879; font-weight: 600; font-size: 35px;
}
.tg-ai-chat__send:hover { background: #f0f0f0; }
.tg-ai-chat__send:disabled { opacity: 0.6; cursor: not-allowed; }

/* Minimized state */
.tg-ai-chat--minimized .tg-ai-chat__messages,
.tg-ai-chat--minimized .tg-ai-chat__composer {
  display: none;
}
.tg-ai-chat--minimized .tg-ai-chat__panel {
  height: auto;
}

/* Fullscreen state */
.tg-ai-chat--fullscreen .tg-ai-chat__panel {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  right: 0;
  bottom: 0;
  border-radius: 0;
}

/* Mobile: full-width bottom sheet */
@media (max-width: 520px) {
  .tg-ai-chat { right: 12px; bottom: 12px; }
  .tg-ai-chat__panel {
    width: calc(100vw - 24px);
    height: min(70vh, 560px);
    bottom: 68px;
  }
}

/* Screen reader only text */
.tg-ai-chat__sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  white-space: nowrap; clip-path: inset(50%); clip: rect(0 0 0 0); overflow: hidden; border: 0;
}
