*, *::before, *::after { box-sizing: border-box; }

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 9pt;
  background: #f2f4f8;
  overflow: hidden;
  color: #111;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1f497d;
  color: white;
  padding: 8px 10px 8px 12px;
  flex-shrink: 0;
}

#headerTitle {
  font-size: 10pt;
  font-weight: bold;
}

#btnSettings {
  background: transparent;
  border: none;
  color: white;
  font-size: 14pt;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 3px;
}
#btnSettings:hover { background: rgba(255,255,255,0.15); }

/* ── Action buttons ───────────────────────────────────────────────────────── */
#actions {
  display: flex;
  gap: 6px;
  padding: 8px 8px 0 8px;
  flex-shrink: 0;
}

.btn-blue {
  background: #1f497d;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: bold;
  font-family: inherit;
  font-size: 9pt;
}
.btn-blue:hover:not(:disabled) { background: #2d6bc4; }
.btn-blue:disabled { opacity: 0.5; cursor: default; }

.btn-green {
  background: #00703c;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: bold;
  font-family: inherit;
  font-size: 9pt;
}
.btn-green:hover:not(:disabled) { background: #008a4a; }
.btn-green:disabled { opacity: 0.5; cursor: default; }

.btn-outline {
  background: white;
  color: #1f497d;
  border: 1px solid #1f497d;
  border-radius: 3px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 9pt;
}
.btn-outline:hover:not(:disabled) { background: #e8f0fa; }
.btn-outline:disabled { opacity: 0.5; cursor: default; }

#actions .btn-blue,
#actions .btn-green { flex: 1; }

/* ── Chat display ─────────────────────────────────────────────────────────── */
#chatWrapper {
  flex: 1;
  overflow-y: auto;
  background: white;
  border: 1px solid #c8d4e4;
  margin: 8px 8px 4px 8px;
  padding: 8px;
  min-height: 0;
}

#chatDisplay { font-size: 9pt; line-height: 1.5; }

.msg-block { margin-bottom: 10px; }

.msg-user-label {
  color: #1f497d;
  font-weight: bold;
}
.msg-ai-label {
  color: #00703c;
  font-weight: bold;
}
.msg-body {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  color: #111;
}
.msg-error { color: firebrick !important; font-style: italic; }

/* ── Chat input ───────────────────────────────────────────────────────────── */
#chatInputRow {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 0 8px;
  flex-shrink: 0;
}

#chatInput {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: 9pt;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 5px;
  background: white;
}

#chatInputRow .btn-blue {
  flex: 0;
  padding: 6px 12px;
  white-space: nowrap;
  align-self: flex-end;
}

/* ── Status ───────────────────────────────────────────────────────────────── */
#statusBar {
  padding: 3px 10px 2px 10px;
  flex-shrink: 0;
  min-height: 20px;
}

#statusText {
  font-size: 8pt;
  font-style: italic;
  color: #286432;
}
#statusText.working { color: darkorange; }
#statusText.error   { color: firebrick; }

/* ── Bottom buttons ───────────────────────────────────────────────────────── */
#bottomButtons {
  display: flex;
  gap: 6px;
  padding: 0 8px 8px 8px;
  flex-shrink: 0;
}
#bottomButtons .btn-outline,
#bottomButtons .btn-blue { flex: 1; }

/* ── Settings overlay ─────────────────────────────────────────────────────── */
#settingsPanel {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#settingsPanel.hidden { display: none; }

#settingsInner {
  background: white;
  border-radius: 6px;
  padding: 18px 20px 16px 20px;
  width: 92%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}

#settingsInner h3 {
  margin: 0 0 4px 0;
  font-size: 10pt;
  color: #1f497d;
}

#settingsInner label {
  display: flex;
  flex-direction: column;
  font-size: 8.5pt;
  gap: 3px;
  color: #333;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
}

#settingsInner input[type=text],
#settingsInner input[type=password],
#settingsInner select {
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 5px;
  font-size: 8.5pt;
  font-family: inherit;
}

#modelRow {
  display: flex;
  gap: 4px;
}
#modelRow select { flex: 1; }
#fontRow {
  display: flex;
  gap: 4px;
}
#fontRow select:first-child { flex: 2; }
#fontRow select:last-child  { flex: 1; }
#btnRefreshModels {
  background: white;
  border: 1px solid #bbb;
  border-radius: 3px;
  cursor: pointer;
  padding: 0 8px;
  font-size: 11pt;
}
#btnRefreshModels:hover { background: #f0f0f0; }

#settingsStatus {
  font-size: 8pt;
  font-style: italic;
  min-height: 16px;
}

#settingsButtons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
#btnSettingsCancel {
  background: white;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 6px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 9pt;
}
#btnSettingsCancel:hover { background: #f0f0f0; }
#settingsButtons .btn-blue { flex: 0; padding: 6px 18px; }
