:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef3f8;
  --line: #d8e0ea;
  --text: #17202a;
  --muted: #667085;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --primary-soft: #d9f3ef;
  --accent: #b42318;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand h1,
.brand p,
.chat-header h2,
.chat-header p {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.25;
}

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

.new-chat,
.send-button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
}

.new-chat:hover,
.send-button:hover {
  background: var(--primary-strong);
}

.graph-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--primary-strong);
  font-weight: 800;
  text-decoration: none;
}

.graph-link:hover {
  border-color: #9bc9c3;
  background: var(--primary-soft);
}

.quick-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-panel h2 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.prompt-chip {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 11px 12px;
  text-align: left;
  line-height: 1.35;
}

.prompt-chip:hover {
  border-color: #9bc9c3;
  background: var(--primary-soft);
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.status-panel div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #f59e0b;
}

.status-dot.online {
  background: #12b76a;
}

.status-dot.offline {
  background: var(--accent);
}

.text-ok { color: #12b76a; }
.text-warn { color: #f59e0b; }
.text-muted { color: #9ca3af; }

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
}

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

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

.chat-header h2 {
  margin-top: 2px;
  font-size: 20px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-graph-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 0 14px;
  text-decoration: none;
}

.header-graph-link:hover {
  background: var(--primary-strong);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  border-color: #c4d3df;
  color: var(--text);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 24px;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  max-width: 960px;
  width: 100%;
  animation: message-enter 220ms ease-out both;
}

.message.user {
  align-self: flex-end;
  grid-template-columns: minmax(0, 1fr) 36px;
}

.avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
  background: #344054;
}

.bubble {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  line-height: 1.6;
}

.bubble.answering {
  background:
    linear-gradient(90deg, rgba(217, 243, 239, 0.55), rgba(255, 255, 255, 0.9), rgba(238, 243, 248, 0.75)),
    var(--panel);
  background-size: 220% 100%;
  animation: answer-sheen 1.6s ease-in-out infinite;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  border-color: #cae6e1;
  background: var(--primary-soft);
  box-shadow: none;
}

.bubble > :first-child {
  margin-top: 0;
}

.bubble > :last-child {
  margin-bottom: 0;
}

.bubble p,
.bubble ul,
.bubble ol {
  margin: 0 0 10px;
}

.bubble ul,
.bubble ol {
  padding-left: 22px;
}

.bubble table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.bubble th,
.bubble td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.bubble th {
  background: var(--panel-soft);
  font-weight: 800;
}

.sources {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.sources span {
  display: inline-flex;
  margin: 4px 6px 0 0;
  border-radius: 999px;
  background: var(--panel-soft);
  padding: 3px 8px;
}

.typing-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

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

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #98a2b3;
  animation: pulse 1s infinite ease-in-out;
}

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

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

.answer-stream {
  white-space: normal;
}

.typing-cursor {
  display: inline-block;
  width: 8px;
  height: 18px;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--primary);
  vertical-align: -3px;
  animation: cursor-blink 880ms steps(2, start) infinite;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 16px 24px 20px;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  line-height: 1.45;
}

.composer textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.send-button {
  min-height: 46px;
  padding: 0 16px;
}

.send-button:disabled {
  cursor: not-allowed;
  background: #98a2b3;
}

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

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes answer-sheen {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

@keyframes cursor-blink {
  0%,
  45% {
    opacity: 1;
  }

  46%,
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .quick-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-panel h2 {
    grid-column: 1 / -1;
  }

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

@media (max-width: 560px) {
  .sidebar,
  .messages,
  .chat-header,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .quick-panel {
    grid-template-columns: 1fr;
  }

  .message,
  .message.user {
    grid-template-columns: 32px minmax(0, 1fr);
    max-width: 100%;
  }

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

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

  .avatar {
    width: 32px;
    height: 32px;
  }

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

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

  .chat-actions,
  .header-graph-link {
    width: 100%;
  }
}
