.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.chat-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
}

body.chat-panel-open::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(1.5px);
  z-index: 1090;
  pointer-events: none;
}

.chat-fab {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 999px;
  background: #0d6efd;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(13, 110, 253, 0.35);
  font-size: 1.25rem;
}

.chat-fab:focus-visible,
.chat-close:focus-visible,
#chat-send:focus-visible,
#chat-input:focus-visible,
.chat-download-btn:focus-visible {
  outline: 3px solid rgba(13, 110, 253, 0.45);
  outline-offset: 2px;
}

.chat-panel {
  position: fixed;
  right: 16px;
  bottom: 84px;
  width: min(920px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  height: min(86vh, calc(100vh - 110px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.28);
  border: 1px solid #dbe4ef;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.chat-panel.is-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #e4ecf6;
  background: linear-gradient(180deg, #f8fbff 0%, #f4f8ff 100%);
}

.chat-panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
  font-weight: 700;
  color: #1e293b;
}

.chat-close {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #475569;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.chat-close:hover {
  background: #eaf1fb;
  color: #0f172a;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #f8fbff;
}

.chat-bubble {
  max-width: 92%;
  margin-bottom: 12px;
  padding: 11px 13px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  margin-left: auto;
  background: #dbeafe;
  color: #0f172a;
  border: 1px solid #bfdbfe;
}

.chat-bubble.assistant {
  margin-right: auto;
  background: #eef2ff;
  color: #111827;
  border: 1px solid #dbe7ff;
}

.chat-bubble.loading {
  margin-right: auto;
  background: #f1f5f9;
  color: #475569;
  font-style: italic;
}

.chat-chart-card {
  margin: 10px 0 14px;
  padding: 12px;
  border: 1px solid #d9e3f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.chat-chart-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: #1f2937;
}

.chat-chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: clamp(340px, 60vh, 620px);
}

.chat-download-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid #c8d6ea;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.chat-download-btn:hover {
  background: #f2f7ff;
  border-color: #9db5db;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5edf7;
  background: #fff;
}

#chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #b8c7db;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 1rem;
  color: #0f172a;
  background: #fdfefe;
}

#chat-input::placeholder {
  color: #64748b;
}

#chat-send {
  border: none;
  border-radius: 12px;
  background: #0d6efd;
  color: #fff;
  padding: 0 18px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

#chat-send:hover {
  background: #0b5ed7;
}

#chat-send:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .chat-widget {
    right: 12px;
    bottom: 12px;
  }

  .chat-panel {
    right: 8px;
    left: 8px;
    bottom: 78px;
    width: auto;
    max-width: none;
    height: min(86vh, 720px);
  }

  .chat-chart-canvas-wrap {
    height: min(48vh, 420px);
  }
}
