:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #647086;
  --line: #dce3ee;
  --accent: #1167d8;
  --accent-dark: #0b4fa8;
  --success: #13895b;
  --danger: #c93535;
  --shadow: 0 24px 70px rgba(23, 32, 51, .14);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #eef4ff 0%, #f8fafc 55%, #ecfdf5 100%);
  color: var(--ink);
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.chat-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: center;
  padding: 24px 0;
}

.chat-panel, .context-panel {
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(220, 227, 238, .9);
  box-shadow: var(--shadow);
}

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

.chat-header {
  min-height: 82px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}
.chat-header p { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.chat-header h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--success);
}
.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-dark);
  font-size: 22px;
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.message {
  max-width: min(680px, 88%);
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.message.assistant { align-self: flex-start; background: #eef5ff; border: 1px solid #d7e7ff; }
.message.user { align-self: flex-end; background: var(--accent); color: #fff; }

.typing { padding: 0 22px 12px; display: flex; gap: 5px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.error-message { margin: 0 22px 12px; padding: 10px 12px; border-radius: 8px; background: #fff1f1; color: var(--danger); border: 1px solid #ffd4d4; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 16px; border-top: 1px solid var(--line); background: #fbfdff; }
textarea {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 13px 14px;
  outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(17, 103, 216, .12); }
#send-button {
  min-width: 104px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
#send-button:disabled { opacity: .6; cursor: wait; }

.context-panel { border-radius: 8px; padding: 18px; align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.context-panel h2 { margin: 0 0 6px; font-size: 18px; }
.context-panel button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 12px; color: var(--ink); }
.context-panel button:hover { border-color: var(--accent); color: var(--accent-dark); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

@media (max-width: 880px) {
  .chat-shell { grid-template-columns: 1fr; align-items: stretch; }
  .chat-panel { min-height: calc(100vh - 220px); }
  .context-panel { order: -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .context-panel h2 { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
}

@media (max-width: 560px) {
  .chat-shell { width: 100%; padding: 0; }
  .chat-panel, .context-panel { border-radius: 0; box-shadow: none; }
  .context-panel { grid-template-columns: 1fr; }
  .message { max-width: 96%; }
  .chat-form { grid-template-columns: 1fr; }
  #send-button { min-height: 46px; }
}

