.tab-chat-widget {
  --tab-accent: #2563eb;
  --tab-border: #dbe2ea;
  box-sizing: border-box;
  font: 400 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.tab-chat-widget *,
.tab-chat-widget *::before,
.tab-chat-widget *::after {
  box-sizing: border-box;
}

.tab-chat-widget--popup {
  position: fixed;
  z-index: 999999;
  right: 24px;
  bottom: 24px;
  width: min(var(--tab-width), calc(100vw - 48px));
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 12px;
}

.tab-chat__launcher {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--tab-accent);
  color: #fff;
  box-shadow: 0 12px 30px rgba(37, 99, 235, .32);
  font: 700 15px/1 inherit;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}

.tab-chat__launcher:hover,
.tab-chat__launcher:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 15px 35px rgba(37, 99, 235, .4);
}

.tab-chat__launcher span {
  font-size: 21px;
}

.tab-chat-widget--inline .tab-chat__launcher,
.tab-chat-widget--inline .tab-chat__dismiss {
  display: none;
}

.tab-chat {
  width: min(var(--tab-width), calc(100vw - 32px));
  height: min(var(--tab-height), calc(100vh - 110px));
  min-height: 360px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--tab-border);
  border-radius: 18px;
  background: #fff;
  color: #16202a;
  box-shadow: 0 20px 55px rgba(22, 32, 42, .24);
  transform-origin: bottom right;
  animation: tab-chat-open .2s ease-out;
}

.tab-chat-widget--popup .tab-chat { width: 100%; }

.tab-chat[hidden] {
  display: none;
}

.tab-chat-widget--inline .tab-chat {
  width: min(var(--tab-width), 100%);
  height: var(--tab-height);
  box-shadow: 0 12px 35px rgba(22, 32, 42, .12);
}

.tab-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  background: #111827;
  color: #fff;
}

.tab-chat__header strong,
.tab-chat__header span {
  display: block;
}

.tab-chat__header span {
  font-size: 12px;
  opacity: .72;
}

.tab-chat__header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-chat__new,
.tab-chat__dismiss {
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 8px;
  padding: 7px 10px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}

.tab-chat__dismiss {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  font-size: 25px;
  line-height: 1;
}

.tab-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #f8fafc;
}

.tab-chat__message {
  display: flex;
  flex-direction: column;
  margin: 0 0 14px;
}

.tab-chat__message--user { align-items: flex-end; }
.tab-chat__message--assistant { align-items: flex-start; }

.tab-chat__bubble {
  max-width: 88%;
  padding: 10px 13px;
  border: 1px solid var(--tab-border);
  border-radius: 14px;
  background: #fff;
  overflow-wrap: anywhere;
}

.tab-chat__message--user .tab-chat__bubble {
  border-color: var(--tab-accent);
  border-bottom-right-radius: 4px;
  background: var(--tab-accent);
  color: #fff;
}

.tab-chat__message--assistant .tab-chat__bubble { border-bottom-left-radius: 4px; }
.tab-chat__message--preview .tab-chat__bubble {
  border-left: 3px solid var(--tab-accent);
  background: #f3f7fc;
}
.tab-chat__bubble a,
.tab-chat__sources a { color: #1d4ed8; text-decoration: underline; }

.tab-chat__preview-label,
.tab-chat__preview-note,
.tab-chat__preview-title,
.tab-chat__preview-excerpt { display: block; }

.tab-chat__preview-label {
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 750;
}

.tab-chat__preview-note {
  margin-top: 1px;
  color: #64748b;
  font-size: 11px;
}

.tab-chat__preview-title {
  margin-top: 7px;
  font-weight: 700;
}

.tab-chat__preview-excerpt {
  margin-top: 5px;
  color: #334155;
}

.tab-chat__sources {
  max-width: 88%;
  margin-top: 5px;
  font-size: 12px;
  color: #4b5563;
}

.tab-chat__response-time {
  display: block;
  margin-top: 10px;
  padding-top: 7px;
  border-top: 1px solid #e5e7eb;
  color: #64748b;
  font-size: 11px;
  line-height: 1.35;
}

.tab-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--tab-border);
  background: #fff;
}

.tab-chat__disclosure {
  margin: 0;
  padding: 8px 12px 0;
  border-top: 1px solid var(--tab-border);
  background: #fff;
  color: #5b6470;
  font-size: 11px;
  line-height: 1.35;
}

.tab-chat__disclosure + .tab-chat__form {
  border-top: 0;
}

.tab-chat__input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  border: 1px solid #bdc7d3;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
}

.tab-chat__input:focus {
  outline: 2px solid rgba(37, 99, 235, .25);
  border-color: var(--tab-accent);
}

.tab-chat__send,
.tab-chat__mic {
  height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 0 15px;
  background: var(--tab-accent);
  color: #fff;
  font: 600 14px/1 inherit;
  cursor: pointer;
}

.tab-chat__mic {
  flex: 0 0 42px;
  width: 42px;
  padding: 0;
  background: #e8eef7;
  color: #1f2937;
}

.tab-chat__mic:disabled { opacity: .45; cursor: not-allowed; }
.tab-chat__mic.is-recording { background: #dc2626; color: #fff; animation: tab-pulse 1s infinite; }
.tab-chat__send:disabled { opacity: .55; cursor: wait; }

.tab-chat__typing {
  position: relative;
  isolation: isolate;
  align-self: flex-start;
  display: inline-flex;
  max-width: calc(100% - 36px);
  margin: 0 18px 10px;
  padding: 9px 13px;
  overflow: hidden;
  border: 1px solid #d9e4f1;
  border-radius: 12px;
  background: #edf3fa;
  box-shadow: 0 3px 10px rgba(71, 85, 105, .08), inset 0 1px 0 rgba(255, 255, 255, .85);
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.tab-chat__typing[hidden] { display: none; }
.tab-chat__typing--continuing {
  border-color: rgba(37, 99, 235, .35);
  background: #e9f1fb;
  color: #334155;
}
.tab-chat__typing::before {
  position: absolute;
  z-index: 0;
  top: -20%;
  bottom: -20%;
  left: 0;
  width: 46%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .96), transparent);
  content: '';
  transform: translateX(-170%) skewX(-18deg);
  animation: tab-progress-shimmer 1.8s ease-in-out infinite;
}
.tab-chat__progress-text { display: block; position: relative; z-index: 1; }
.tab-chat__status { min-height: 0; margin: 0; padding: 0 14px 8px; font-size: 12px; color: #b42318; }

.screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes tab-chat-open { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes tab-progress-shimmer { 0% { transform: translateX(-170%) skewX(-18deg); } 58%, 100% { transform: translateX(330%) skewX(-18deg); } }
@keyframes tab-bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
@keyframes tab-pulse { 50% { opacity: .65; } }

@media (prefers-reduced-motion: reduce) {
  .tab-chat__typing::before { animation: none; opacity: .45; transform: translateX(80%) skewX(-18deg); }
}

@media (max-width: 520px) {
  .tab-chat-widget--popup { right: 12px; bottom: 12px; left: 12px; width: auto; }
  .tab-chat-widget--popup .tab-chat { width: 100%; height: min(var(--tab-height), calc(100vh - 92px)); }
  .tab-chat__launcher { align-self: flex-end; }
  .tab-chat__bubble,
  .tab-chat__sources { max-width: 94%; }
}
