:root {
  color-scheme: light;
  --page-bg: #eaf3f8;
  --panel-bg: #ffffff;
  --panel-border: #b8d8ee;
  --text: #112334;
  --muted: #5d7182;
  --accent: #3f79b6;
  --accent-dark: #2f659e;
  --accent-soft: #e8f3ff;
  --user-bg: #2474b8;
  --user-text: #ffffff;
  --ai-bg: #f7fafc;
  --danger-bg: #fff0f0;
  --danger-text: #9f1d1d;
  --shadow: 0 18px 48px rgba(32, 86, 124, 0.20);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    linear-gradient(rgba(241, 248, 252, 0.82), rgba(226, 240, 249, 0.84)),
    linear-gradient(115deg, rgba(255, 255, 255, 0.92) 0 28%, rgba(170, 209, 232, 0.62) 28% 63%, rgba(87, 125, 154, 0.35) 63% 100%),
    var(--page-bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chat-shell {
  width: min(1180px, calc(100vw - 32px));
  height: min(92vh, 940px);
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  border-top: 3px solid #2f9ee8;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-logo {
  width: 122px;
  height: auto;
  display: block;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.context-badge {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1rem;
}

.messages {
  overflow-y: auto;
  padding: 22px 26px;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  margin: 0 0 14px;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.ai,
.message-row.error {
  justify-content: flex-start;
}

.bubble {
  max-width: min(620px, 88%);
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  font-size: 0.96rem;
  overflow-wrap: anywhere;
}

.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
}

.ai .bubble {
  background: var(--ai-bg);
  color: var(--text);
  border: 1px solid #dce8f1;
}

.error .bubble {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid #ffd2d2;
}

.small-note {
  font-size: 0.88rem;
  color: var(--muted);
}

.debug-block {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  color: #344044;
}

.markdown h3 {
  margin: 8px 0 6px;
  font-size: 1rem;
  line-height: 1.3;
}

.markdown strong {
  font-weight: 700;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing span {
  width: 7px;
  height: 7px;
  display: block;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.message-row.report {
  width: 100%;
}

.message-row.report .bubble {
  width: 100%;
  max-width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
}

.chart-card {
  width: 100%;
  background: #ffffff;
  border: 1px solid #c8ddeb;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(39, 91, 130, 0.10);
}

.chart-card iframe {
  width: 100%;
  height: min(620px, 62vh);
  display: block;
  border: 0;
  background: #ffffff;
}

.excel-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  color: #ffffff;
  background: #3f79b6;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
  transition: background 0.16s ease, transform 0.16s ease;
}

.excel-button:hover {
  background: #2f659e;
  transform: translateY(-1px);
}

.suggestions-row {
  margin-top: -4px;
}

.suggestions-bubble {
  width: min(720px, 94%);
}

.suggestions-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggested-question-button {
  max-width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #b9d5e9;
  border-radius: 8px;
  background: #ffffff;
  color: #245b8c;
  font-size: 0.9rem;
  line-height: 1.25;
  text-align: left;
  overflow-wrap: anywhere;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.suggested-question-button:hover {
  background: #edf7ff;
  border-color: #7fb7df;
  color: #174b78;
  transform: translateY(-1px);
}

.audio-attachment,
.recording-status {
  margin: 0 16px 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.audio-attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-soft);
  color: #275d90;
}

.audio-attachment[hidden],
.recording-status[hidden] {
  display: none;
}

.audio-attachment button {
  padding: 6px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--accent-dark);
}

.recording-status {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}

.composer {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--panel-border);
  background: #f8fbfd;
}

.composer form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
}

#messageInput {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  overflow-y: hidden;
  padding: 11px 12px;
  border: 1px solid #ccd5d8;
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

#messageInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 121, 182, 0.16);
}

.send-button {
  min-height: 44px;
  border-radius: 8px;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.icon-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  background: #edf5fb;
  color: #2f659e;
  border-radius: 50%;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.icon-button:hover {
  background: #dcecf7;
  transform: translateY(-1px);
}

.icon-button.recording {
  background: #dc2626;
  color: #ffffff;
}

.mic-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.send-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

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

@media (max-width: 640px) {
  body {
    padding: 8px;
    place-items: stretch;
  }

  .chat-shell {
    width: 100%;
    height: calc(100vh - 16px);
    min-height: 0;
  }

  .chat-header {
    padding: 14px 16px;
  }

  .brand-block {
    gap: 12px;
  }

  .brand-logo {
    width: 96px;
  }

  .messages {
    padding: 16px;
  }

  .bubble {
    max-width: 94%;
  }

  .suggestions-bubble {
    width: 100%;
  }

  .suggestions-list {
    display: grid;
  }

  .composer form {
    grid-template-columns: 1fr auto;
  }

  #messageInput {
    grid-column: 1 / -1;
  }

  .icon-button {
    justify-self: end;
  }

  .chart-card iframe {
    height: 500px;
  }
}
