/* === Design tokens === */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d8e0ea;
  --text: #1a2230;
  --muted: #5b6b80;
  --primary: #173f6d;
  --primary-hover: #0f2e54;
  --accent: #1d8f6e;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(20, 40, 70, 0.08), 0 4px 12px rgba(20, 40, 70, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); }

/* === Layout === */
.app-header {
  background: var(--primary);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.app-header .nav-btn {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
}
.app-header .nav-btn:hover { background: rgba(255,255,255,0.1); }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 24px;
}
.container.narrow { max-width: 560px; }

/* === Login page === */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #173f6d 0%, #1d8f6e 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  padding: 36px 32px;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 420px;
}
.login-card h1 {
  margin: 0 0 6px 0;
  font-size: 22px;
  color: var(--primary);
}
.login-card p { color: var(--muted); margin: 0 0 22px 0; font-size: 14px; }

/* === Scenario picker === */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 12px;
}
.scenario-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scenario-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}
.scenario-card .badge {
  display: inline-block;
  background: var(--surface-2);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  align-self: flex-start;
}
.scenario-card h3 { margin: 4px 0 0 0; font-size: 17px; color: var(--text); }
.scenario-card p { color: var(--muted); margin: 0; font-size: 14px; }

/* === Forms === */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 63, 109, 0.12);
}
textarea {
  min-height: 110px;
  resize: vertical;
  font-family: inherit;
}
.field { margin-bottom: 14px; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn.secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn.accent { background: var(--accent); }
.btn.accent:hover:not(:disabled) { background: #156b53; }
.btn.danger-link {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 4px 8px;
  font-weight: 500;
  cursor: pointer;
}
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* === Chat / message UI === */
.chat-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 500px;
}
.chat-messages {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafbfd;
}
.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
}
.msg.user { align-self: flex-end; background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-style: italic; font-size: 13px; }
.msg.error { align-self: center; background: #fde2e0; color: var(--danger); }

/* Markdown rendered inside assistant bubbles */
.msg.assistant p { margin: 0 0 8px 0; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h2, .msg.assistant h3, .msg.assistant h4, .msg.assistant h5, .msg.assistant h6 {
  margin: 10px 0 6px 0;
  color: var(--primary);
  font-weight: 600;
}
.msg.assistant h2 { font-size: 1.05em; }
.msg.assistant h3 { font-size: 1.02em; }
.msg.assistant h4, .msg.assistant h5, .msg.assistant h6 { font-size: 1em; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px 0; padding-left: 22px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant code {
  background: rgba(23, 63, 109, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg.assistant strong { font-weight: 700; }
.msg.assistant a { color: var(--primary); text-decoration: underline; }

.chat-input {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  margin: 0;
}

/* === Wizard stepper === */
.stepper {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.step {
  flex: 1;
  min-width: 110px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.step.active { background: var(--primary); color: white; border-color: var(--primary); }
.step.done { background: var(--accent); color: white; border-color: var(--accent); }

/* === Section card === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin-top: 0; font-size: 18px; color: var(--primary); }
.card .helper { color: var(--muted); font-size: 14px; margin-top: -4px; margin-bottom: 14px; }

/* === Alerts === */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 14px;
}
.alert.error { background: #fde2e0; color: var(--danger); border: 1px solid #f5b4ad; }
.alert.info  { background: #e0eaf5; color: var(--primary); border: 1px solid #b9cce0; }

/* === Loading dots === */
.thinking::after {
  content: "▊";
  display: inline-block;
  animation: blink 1s steps(2,start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* === Mobile === */
@media (max-width: 600px) {
  .container { padding: 18px 14px; }
  .app-header { padding: 12px 16px; }
  .app-header h1 { font-size: 16px; }
}
