/* ─── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-50:  #f0faf4;
  --green-100: #d9f2e3;
  --green-200: #b3e5c8;
  --green-300: #6ecf99;
  --green-500: #2a9d5c;
  --green-700: #1a6b3c;
  --green-900: #0d3d22;

  --bg:        #f5fbf7;
  --surface:   #ffffff;
  --surface-2: #edf7f1;
  --border:    #c8e8d4;
  --border-2:  #a0d4b8;

  --text-primary:   #0d3d22;
  --text-secondary: #3a6e52;
  --text-muted:     #7aab8e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-sans: 'Georgia', 'Times New Roman', serif;
  --font-ui:   system-ui, -apple-system, sans-serif;
  --font-mono: 'Menlo', 'Consolas', monospace;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 4rem;
}

/* ─── Layout ────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 720px;
}

/* ─── Header ────────────────────────────────────────────────── */
.header {
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.leaf-icon {
  width: 26px;
  height: 26px;
  color: var(--green-500);
  flex-shrink: 0;
}

.header h1 {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 700;
  color: var(--green-900);
  letter-spacing: -0.01em;
}

.header p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 36px;
}

/* ─── API Key ───────────────────────────────────────────────── */
.key-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 1.25rem;
}

.key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.key-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#api-key {
  flex: 1;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color 0.15s;
}

#api-key:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(42, 157, 92, 0.12);
}

.key-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ─── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 1rem;
}

.tab {
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
  color: var(--text-secondary);
  transition: all 0.15s;
}

.tab:hover:not(.active) {
  border-color: var(--green-300);
  color: var(--green-700);
  background: var(--green-50);
}

.tab.active {
  background: var(--green-500);
  color: #fff;
  border-color: var(--green-500);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(42,157,92,0.25);
}

/* ─── Suggestions ───────────────────────────────────────────── */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
}

.sug {
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 99px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
  color: var(--text-secondary);
  text-align: left;
  transition: all 0.15s;
}

.sug:hover {
  background: var(--green-100);
  color: var(--green-700);
  border-color: var(--green-300);
}

/* ─── Divider ───────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* ─── Messages ──────────────────────────────────────────────── */
.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 1rem;
  min-height: 100px;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 4px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.msg-bubble {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg.user .msg-bubble {
  background: var(--surface-2);
  border-color: var(--green-200);
}

.msg.assistant .msg-bubble {
  background: var(--surface);
}

.msg.thinking .msg-bubble {
  color: var(--text-muted);
  font-style: italic;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ─── Source pills ──────────────────────────────────────────── */
.source-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  margin-top: 7px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pill-pearl { background: #e8e6ff; color: #3c3489; }
.pill-sggk  { background: var(--green-100); color: var(--green-700); }
.pill-both  { background: #fff3cd; color: #6b4c00; }

/* ─── Empty state ───────────────────────────────────────────── */
.empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 2.5rem 0;
  font-style: italic;
}

/* ─── Input row ─────────────────────────────────────────────── */
.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#question {
  flex: 1;
  resize: none;
  font-size: 14px;
  font-family: var(--font-ui);
  min-height: 44px;
  max-height: 120px;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  color: var(--text-primary);
  background: var(--surface);
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#question:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(42, 157, 92, 0.12);
}

#send-btn {
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
  font-family: var(--font-ui);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  background: var(--green-500);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}

#send-btn:hover { background: var(--green-700); }
#send-btn:active { transform: scale(0.97); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
