:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #eef3f0;
  --text: #17201b;
  --muted: #68736d;
  --border: #d9ddd4;
  --green: #1f7a63;
  --blue: #2454b3;
  --coral: #c7523c;
  --shadow: 0 18px 55px rgba(28, 37, 33, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(31, 122, 99, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(199, 82, 60, 0.07), transparent 30%),
    var(--bg);
}

button,
select,
textarea,
a {
  font: inherit;
  letter-spacing: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.sidebar,
.chat-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: 8px;
  padding: 18px;
}

.brand {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 58px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(145deg, var(--green), var(--blue));
  font-weight: 800;
}

.brand h1,
.chat-header h2 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 {
  font-size: 1.1rem;
}

.brand p,
.eyebrow {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.panel.compact {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(199, 82, 60, 0.12);
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(31, 122, 99, 0.14);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.primary,
.send {
  color: #ffffff;
  background: var(--green);
}

.secondary {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--border);
}

label,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
}

.hidden {
  display: none !important;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  border-radius: 8px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.78);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-weight: 700;
}

.badge {
  max-width: 42ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 0.9rem;
}

.quick-prompts {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.quick-prompts button {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

.quick-prompts button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
}

.message-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

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

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
}

.message-row.user .avatar {
  order: 2;
  background: var(--green);
}

.bubble {
  max-width: min(760px, 78%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  white-space: pre-wrap;
  line-height: 1.55;
  background: var(--surface);
}

.message-row.assistant .bubble.with-data-view {
  max-width: min(980px, 92%);
}

.message-row.user .bubble {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.message-row.error .bubble {
  border-color: rgba(199, 82, 60, 0.35);
  background: rgba(199, 82, 60, 0.08);
}

.data-view {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  white-space: normal;
}

.data-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.data-view h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.data-view p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.data-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.data-actions select {
  width: auto;
  max-width: 220px;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 8px;
  font-size: 0.85rem;
}

.data-actions button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

.data-actions button.active {
  color: #ffffff;
  border-color: var(--blue);
  background: var(--blue);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}

.summary-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-strong);
}

.summary-card span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card strong {
  font-size: 1.05rem;
  line-height: 1.2;
}

.chart-wrap {
  width: 100%;
  min-height: 278px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.table-wrap {
  overflow: auto;
  max-height: 380px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.table-wrap table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table-wrap th,
.table-wrap td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-strong);
  font-weight: 700;
}

.table-wrap tr:nth-child(even) td {
  background: rgba(238, 243, 240, 0.45);
}

.table-wrap td.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px 20px 18px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
}

textarea {
  width: 100%;
  max-height: 150px;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface);
  line-height: 1.4;
}

textarea:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(36, 84, 179, 0.24);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 12px;
  }

  .sidebar {
    min-height: auto;
  }

  .chat-panel {
    min-height: 68vh;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .badge {
    max-width: 100%;
  }

  .bubble {
    max-width: 86%;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 15px;
  }

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

  .button.send {
    width: 100%;
  }

  .bubble {
    max-width: 100%;
  }

  .data-view-header {
    align-items: stretch;
  }

  .data-actions {
    justify-content: flex-start;
  }

  .data-actions select {
    max-width: 100%;
  }
}
