:root {
  color-scheme: light;
  --ink: #1f262b;
  --muted: #66727a;
  --line: #d8dedb;
  --panel: #ffffff;
  --paper: #f4f1e8;
  --paper-strong: #eee8dc;
  --teal: #08766e;
  --teal-deep: #064f4b;
  --coral: #bd4f3f;
  --amber: #c58b26;
  --violet: #5a55a8;
  --green-soft: #dcebe5;
  --coral-soft: #f2ded8;
  --amber-soft: #f3e5c7;
  --shadow: 0 18px 50px rgba(31, 38, 43, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(31, 38, 43, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 38, 43, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.left-panel,
.right-panel,
.chat-panel {
  border: 1px solid rgba(31, 38, 43, 0.12);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: calc(100vh - 36px);
  padding: 22px;
  border-radius: 8px;
}

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

.mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  color: var(--teal-deep);
  border: 1px solid rgba(8, 118, 110, 0.25);
  background: var(--green-soft);
  border-radius: 8px;
}

.mark svg {
  width: 30px;
  height: 30px;
}

.brand-title {
  font-size: 22px;
  font-weight: 760;
  line-height: 1.05;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-tile {
  min-height: 82px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.metric-tile span,
.section-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric-tile strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(22px, 2.3vw, 30px);
  line-height: 1;
}

.panel-section {
  display: grid;
  gap: 12px;
}

.top-section {
  padding-bottom: 4px;
}

.round-bars,
.type-bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 66px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #e7e2d8;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.type-bars .bar-row {
  grid-template-columns: minmax(110px, 1fr) 86px;
}

.type-bars .bar-track {
  grid-column: 1 / -1;
}

.type-bars .bar-fill:nth-child(1) {
  background: var(--coral);
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ece7dc;
}

.segment {
  height: 36px;
  border: 0;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 720;
}

.segment.is-active {
  color: #fff;
  background: var(--teal-deep);
}

.prompt-list {
  display: grid;
  gap: 9px;
}

.prompt-list button {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  background: #fbfaf7;
  border-radius: 8px;
}

.prompt-list button:hover {
  border-color: rgba(8, 118, 110, 0.45);
  background: var(--green-soft);
}

.utility-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line);
  color: var(--teal-deep);
  background: #fbfaf7;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 760;
}

.utility-button:hover {
  border-color: rgba(8, 118, 110, 0.45);
  background: var(--green-soft);
}

.utility-button svg {
  width: 18px;
  height: 18px;
}

.context-note {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.conversation-list {
  display: grid;
  max-height: 286px;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  padding: 5px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
}

.conversation-item.is-active {
  border-color: rgba(8, 118, 110, 0.28);
  background: var(--green-soft);
}

.conversation-main,
.conversation-delete,
.query-stack-item {
  border: 0;
  background: transparent;
}

.conversation-main {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding: 7px 8px;
  color: var(--ink);
  text-align: left;
  border-radius: 6px;
}

.conversation-main span,
.query-stack-item span {
  overflow: hidden;
  font-size: 13px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-main small,
.query-stack-item small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-delete {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  align-self: center;
  color: var(--muted);
  border-radius: 6px;
}

.conversation-delete:hover {
  color: #fff;
  background: var(--coral);
}

.conversation-delete svg {
  width: 17px;
  height: 17px;
}

.empty-state {
  min-height: 46px;
  padding: 13px;
  border: 1px dashed var(--line);
  color: var(--muted);
  background: #fbfaf7;
  border-radius: 8px;
  font-size: 12px;
}

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

.chat-header {
  position: relative;
  min-height: 178px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #f8f7f1;
}

.chat-header canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.header-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 28px;
}

.eyebrow {
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 680px;
  margin: 8px 0 0;
  font-size: clamp(31px, 4.2vw, 56px);
  line-height: 0.98;
  letter-spacing: 0;
}

.active-chat-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.active-chat-line span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(31, 38, 43, 0.12);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.76);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 720;
}

.active-chat-line span:first-child {
  max-width: min(520px, 100%);
  overflow: hidden;
  color: var(--teal-deep);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 86px;
  height: 34px;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid rgba(8, 118, 110, 0.2);
  color: var(--teal-deep);
  background: rgba(220, 235, 229, 0.92);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 760;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}

.status-pill.is-busy {
  border-color: rgba(197, 139, 38, 0.28);
  color: #7b5210;
  background: var(--amber-soft);
}

.status-pill.is-busy .status-dot {
  background: var(--amber);
}

.status-pill.is-error {
  border-color: rgba(189, 79, 63, 0.28);
  color: #833126;
  background: var(--coral-soft);
}

.status-pill.is-error .status-dot {
  background: var(--coral);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px;
  background: linear-gradient(180deg, rgba(255,255,255,0.62), rgba(255,255,255,0.92));
}

.message {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.message.user-message {
  grid-template-columns: minmax(0, 1fr) 40px;
}

.avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: #fff;
  background: var(--teal-deep);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 820;
}

.user-message .avatar {
  grid-column: 2;
  background: var(--coral);
}

.bubble {
  max-width: min(860px, 100%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(31, 38, 43, 0.07);
}

.user-message .bubble {
  justify-self: end;
  grid-row: 1;
  color: #fff;
  border-color: rgba(189, 79, 63, 0.28);
  background: var(--coral);
}

.bubble p {
  margin: 0;
  line-height: 1.45;
}

.summary-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.answer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.answer-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fbfaf7;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 760;
}

.loading-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.loader {
  width: 16px;
  height: 16px;
  border: 2px solid #d8dedb;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.result-table-wrap {
  overflow-x: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}

.result-table th,
.result-table td {
  padding: 9px 11px;
  border-bottom: 1px solid #e8ece9;
  text-align: left;
  vertical-align: top;
}

.result-table th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: #f6f5ef;
  font-size: 11px;
  text-transform: uppercase;
}

.result-table tr:last-child td {
  border-bottom: 0;
}

.result-details,
.sql-details {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: #fbfaf7;
  border-radius: 8px;
}

.result-details summary,
.sql-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 13px;
  color: var(--teal-deep);
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 780;
}

.result-details summary::-webkit-details-marker,
.sql-details summary::-webkit-details-marker {
  display: none;
}

.result-details summary::before,
.sql-details summary::before {
  content: "+";
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid rgba(8, 118, 110, 0.28);
  border-radius: 50%;
  font-weight: 760;
}

.result-details[open] summary::before,
.sql-details[open] summary::before {
  content: "-";
}

.result-details summary span,
.sql-details summary span {
  flex: 1;
}

.result-details summary strong,
.sql-details summary strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.result-details .result-table-wrap {
  margin: 0 12px 12px;
}

.sql-details pre {
  overflow: auto;
  max-height: 220px;
  margin: 0 12px 12px;
  padding: 12px;
  color: #f0f4ec;
  background: #20282d;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.mini-chart {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(80px, 42%) 74px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 10px;
  padding: 18px;
  border-top: 1px solid var(--line);
  background: #fbfaf7;
}

.composer textarea {
  width: 100%;
  max-height: 138px;
  min-height: 48px;
  resize: none;
  padding: 13px 14px;
  border: 1px solid var(--line);
  color: var(--ink);
  outline: none;
  background: #fff;
  border-radius: 8px;
}

.composer textarea:focus {
  border-color: rgba(8, 118, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(8, 118, 110, 0.13);
}

.send-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 0;
  color: #fff;
  background: var(--teal-deep);
  border-radius: 8px;
}

.send-button:hover {
  background: var(--teal);
}

.send-button:disabled {
  cursor: not-allowed;
  background: #9ba6a8;
}

.send-button svg {
  width: 23px;
  height: 23px;
}

.query-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.query-meta span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  background: #fbfaf7;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.sql-box {
  overflow: auto;
  min-height: 190px;
  max-height: 360px;
  margin: 0;
  padding: 14px;
  border: 1px solid #263238;
  color: #f0f4ec;
  background: #20282d;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.query-stack {
  display: grid;
  max-height: 236px;
  gap: 8px;
  overflow-y: auto;
}

.query-stack-item {
  display: grid;
  min-height: 54px;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  background: #fbfaf7;
  border-radius: 8px;
}

.query-stack-item:hover {
  border-color: rgba(8, 118, 110, 0.45);
  background: var(--green-soft);
}

.seat-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seat-chip {
  padding: 7px 9px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fbfaf7;
  border-radius: 999px;
  font-size: 12px;
}

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

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .left-panel,
  .right-panel,
  .chat-panel {
    min-height: auto;
  }

  .conversation-list,
  .query-stack {
    max-height: none;
  }

  .header-content {
    flex-direction: column;
    padding: 22px;
  }

  .messages {
    max-height: 62vh;
    padding: 18px;
  }

  .message,
  .message.user-message {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .avatar {
    width: 34px;
    height: 34px;
    font-size: 11px;
  }

  .user-message .avatar {
    grid-column: 1;
  }

  .user-message .bubble {
    grid-column: 2;
    justify-self: stretch;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }
}
