:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --text: #182033;
  --muted: #667085;
  --line: #d8e0ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  --ok-bg: #eef8f2;
  --user: #e8f0ff;
  --assistant: #ffffff;
  --shadow: 0 18px 45px rgba(16, 24, 40, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: #b8c4d2;
  background: #f8fafc;
}

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

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.chat-panel {
  min-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.chat-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.context-panel {
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  padding: 12px 20px;
}

.context-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.context-panel pre {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.document-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid #cbe5d4;
  background: var(--ok-bg);
  color: #12512d;
  font-size: 14px;
}

.document-bar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status,
.error-box {
  margin: 12px 20px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.status {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #ffd2cc;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(#fff, #f8fafc);
}

.message {
  display: flex;
  width: 100%;
}

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

.message.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: min(880px, 88%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--assistant);
  overflow: hidden;
}

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

.message-text {
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 14px;
}

.message-html {
  margin-top: 12px;
}

.message-downloads {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 11px;
  border-radius: 8px;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 13px;
}

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

.composer-tools,
.voice-options,
.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.voice-options {
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.voice-options label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.input-row {
  align-items: stretch;
}

textarea {
  flex: 1 1 280px;
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  background: #fff;
}

textarea:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

#sendBtn {
  min-width: 112px;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

#sendBtn:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.loading-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-radius: 999px;
  background: currentColor;
  animation: pulse 0.9s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

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

  .bubble {
    max-width: 96%;
  }

  .composer-tools button,
  #sendBtn {
    flex: 1 1 auto;
  }
}
