:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafc;
  --border: #d8dde8;
  --text: #1f2633;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #b42318;
  --success: #16803c;
  --warning: #b54708;
  --shadow: 0 18px 45px rgba(30, 41, 59, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 34%),
    linear-gradient(45deg, rgba(22, 128, 60, 0.06), transparent 28%),
    var(--bg);
}

button,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
}

h2 {
  font-size: 18px;
}

.status-panel {
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 28px rgba(30, 41, 59, 0.08);
}

.status-panel strong,
.status-panel span {
  display: block;
}

.model-picker {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.model-picker span {
  color: var(--muted);
  font-size: 13px;
}

.model-picker select {
  width: min(320px, 42vw);
  min-height: 36px;
  padding: 6px 34px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.model-picker select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.health-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(181, 71, 8, 0.14);
}

.health-dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 128, 60, 0.14);
}

.health-dot.failed {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

.app-footer {
  margin-top: 18px;
  padding: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.input-panel,
.chat-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 20px;
}

.chat-panel {
  height: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.chat-panel .panel-header {
  padding: 20px 20px 0;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 220px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
  outline: none;
  line-height: 1.6;
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.upload-box {
  display: grid;
  place-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 22px;
  min-height: 130px;
  border: 1px dashed #9aa7bd;
  border-radius: 8px;
  background: #fbfcff;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-box:hover {
  border-color: var(--primary);
  background: #f5f8ff;
}

.upload-box input {
  display: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
}

.upload-box small {
  color: var(--muted);
}

.selected-file {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

.actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.2);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.secondary-button,
.icon-button {
  color: var(--text);
  background: #ffffff;
  border-color: var(--border);
}

.secondary-button:hover,
.icon-button:hover {
  background: #f8fafc;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 20px;
}

.config-list {
  display: grid;
  gap: 12px;
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.config-list div {
  display: grid;
  gap: 4px;
}

.config-list dt {
  color: var(--muted);
  font-size: 13px;
}

.config-list dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.count-tag {
  padding: 4px 10px;
  border-radius: 999px;
  color: #1e3a8a;
  background: #dbeafe;
  font-size: 13px;
  font-weight: 700;
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 20px 20px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.empty-state {
  height: 100%;
  min-height: 420px;
  display: grid;
  place-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 20px;
}

.message {
  max-width: 88%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.message.user {
  align-self: flex-end;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.message.assistant {
  align-self: flex-start;
}

.message.error {
  align-self: stretch;
  max-width: 100%;
  color: var(--danger);
  border-color: #fecaca;
  background: #fff5f5;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.message-content {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

@media (max-width: 900px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .status-panel {
    min-width: 0;
  }

  .model-picker select {
    width: 100%;
  }

  .chat-panel {
    height: 620px;
  }

  .message {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1440px);
    padding: 16px 0;
  }

  .input-panel,
  .chat-panel .panel-header,
  .chat-log {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .chat-panel {
    height: 560px;
  }
}
