:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(145deg, var(--bg) 0%, #162032 100%);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.card h1,
.card h2 {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.card h1 {
  font-size: 1.75rem;
}

.card h2 {
  font-size: 1.25rem;
  color: var(--text-muted);
}

.meta {
  display: grid;
  gap: 0.35rem;
  margin: 1rem 0 1.5rem;
  font-size: 0.95rem;
}

.meta dt {
  color: var(--text-muted);
  font-weight: 500;
  display: inline;
}

.meta dt::after {
  content: ": ";
}

.meta dd {
  display: inline;
  margin: 0;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.nav-links a {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}

.nav-links a:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.back-link:hover {
  color: var(--accent);
}

.chat-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

select,
textarea,
button {
  font: inherit;
}

select {
  min-width: 220px;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

textarea {
  width: 100%;
  min-height: 90px;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

button {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.messages {
  min-height: 280px;
  max-height: 480px;
  overflow-y: auto;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.message {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  background: rgba(59, 130, 246, 0.15);
  border-left: 3px solid var(--accent);
}

.message.assistant {
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid var(--success);
}

.message.system {
  background: rgba(139, 156, 179, 0.1);
  border-left: 3px solid var(--text-muted);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.message-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.error-box {
  display: none;
  padding: 0.75rem 1rem;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--error);
  border-radius: 8px;
  color: #fca5a5;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.error-box.visible {
  display: block;
}

.status-bar {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.toggle-label input {
  accent-color: var(--accent);
}

@media (max-width: 600px) {
  .container {
    padding: 1rem 0.75rem 2rem;
  }

  .card {
    padding: 1.25rem;
  }

  select {
    min-width: 100%;
  }
}
