/* ─── Design Tokens ───────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  /* Palette — deep teal + warm amber accents */
  --bg-base: #0c1117;
  --bg-surface: #151b23;
  --bg-elevated: #1c2430;
  --bg-hover: #232d3b;
  --bg-input: #111820;

  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 170, 0.55);

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #636d77;
  --text-inverse: #0c1117;

  --accent: #38bdaa;
  --accent-hover: #2ea897;
  --accent-subtle: rgba(56, 189, 170, 0.12);
  --accent-glow: rgba(56, 189, 170, 0.25);

  --user-bubble: linear-gradient(135deg, #1a6b5f 0%, #1a5c6b 100%);
  --bot-bubble: var(--bg-elevated);

  --amber: #e5a93d;
  --red: #f85149;
  --green: #3fb950;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 20px var(--accent-glow);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ─── Animated background ─────────────────────────────────────────────────── */

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 600px 400px at 10% 20%, rgba(56, 189, 170, 0.06), transparent),
    radial-gradient(ellipse 500px 500px at 85% 80%, rgba(229, 169, 61, 0.04), transparent),
    radial-gradient(ellipse 400px 300px at 50% 50%, rgba(56, 189, 170, 0.03), transparent);
  animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0%   { opacity: 1; }
  50%  { opacity: 0.7; }
  100% { opacity: 1; }
}

/* ─── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(21, 27, 35, 0.85);
  backdrop-filter: blur(16px) saturate(1.4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--text-inverse);
  background: linear-gradient(135deg, var(--accent), #2980b9);
  box-shadow: var(--shadow-glow);
  transition: transform var(--transition);
}

.brand-mark:hover { transform: scale(1.05); }

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  min-width: 100px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}

.status-badge.ok {
  color: var(--green);
  border-color: rgba(63, 185, 80, 0.35);
  background: rgba(63, 185, 80, 0.08);
}

.status-badge.degraded {
  color: var(--amber);
  border-color: rgba(229, 169, 61, 0.35);
  background: rgba(229, 169, 61, 0.08);
}

.status-badge.error {
  color: var(--red);
  border-color: rgba(248, 81, 73, 0.35);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.icon-button,
.composer button,
.search-form button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--text-inverse);
  background: var(--accent);
  transition: all var(--transition);
  flex-shrink: 0;
}

.icon-button:hover,
.composer button:hover,
.search-form button:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.icon-button:active,
.composer button:active,
.search-form button:active {
  transform: translateY(0);
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 64px);
}

.side-panel,
.chat-panel {
  min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

/* ─── Side panel ──────────────────────────────────────────────────────────── */

.side-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.search-section,
.stats-section {
  min-height: 0;
  padding: 16px;
}

.search-section { border-bottom: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.section-heading h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.section-heading span {
  color: var(--text-muted);
  font-size: 12px;
}

/* ─── Search form ─────────────────────────────────────────────────────────── */

.search-form {
  height: 42px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 4px 0 12px;
  background: var(--bg-input);
  transition: border-color var(--transition), box-shadow var(--transition);
  flex-shrink: 0;
}

.search-form:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-form input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
}

.search-form input::placeholder { color: var(--text-muted); }

.search-icon { color: var(--text-muted); flex-shrink: 0; }

/* ─── Search results ──────────────────────────────────────────────────────── */

.result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-top: 12px;
  flex: 1;
  min-height: 0;
}

.result-list::-webkit-scrollbar { width: 5px; }
.result-list::-webkit-scrollbar-track { background: transparent; }
.result-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.result-item,
.source-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: inherit;
  text-decoration: none;
  background: var(--bg-elevated);
  transition: all var(--transition);
}

.result-item:hover,
.source-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.result-title,
.source-title {
  display: block;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
}

.result-meta,
.source-meta {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.result-snippet {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Info card ───────────────────────────────────────────────────────────── */

.info-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.info-card p { margin: 0 0 10px; }

.info-card ul {
  margin: 0;
  padding-left: 18px;
}

.info-card li {
  margin: 4px 0;
  color: var(--text-secondary);
}

.info-card li::marker { color: var(--accent); }

/* ─── Chat panel ──────────────────────────────────────────────────────────── */

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  overflow: hidden;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Messages ────────────────────────────────────────────────────────────── */

.message-row {
  display: flex;
  animation: msgSlide 0.3s ease-out;
}

@keyframes msgSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user { justify-content: flex-end; }

.message {
  max-width: min(760px, 85%);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  line-height: 1.6;
  font-size: 14px;
}

.message-row.user .message {
  color: var(--text-primary);
  background: var(--user-bubble);
  border: 1px solid rgba(56, 189, 170, 0.2);
}

.message-row.assistant .message {
  color: var(--text-primary);
  background: var(--bot-bubble);
  border: 1px solid var(--border);
}

.message p:first-child { margin-top: 0; }
.message p:last-child { margin-bottom: 0; }

/* ─── Source cards in messages ─────────────────────────────────────────────── */

.source-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

/* ─── Feedback ────────────────────────────────────────────────────────────── */

.feedback-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.feedback-actions button {
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-size: 12px;
  transition: all var(--transition);
}

.feedback-actions button:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

.feedback-actions button.active {
  color: var(--text-inverse);
  border-color: var(--accent);
  background: var(--accent);
}

/* ─── Composer ────────────────────────────────────────────────────────────── */

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.composer textarea {
  min-height: 42px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: 0;
  background: var(--bg-input);
  color: var(--text-primary);
  line-height: 1.45;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.composer textarea::placeholder { color: var(--text-muted); }

.composer textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.composer button {
  width: 42px;
  height: 42px;
  align-self: end;
}

/* ─── Disclaimer ──────────────────────────────────────────────────────────── */

.disclaimer {
  margin: 0;
  padding: 0 16px 12px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

/* ─── Empty state ─────────────────────────────────────────────────────────── */

.empty-state {
  color: var(--text-secondary);
  text-align: center;
  margin: auto;
  max-width: 440px;
  padding: 40px 20px;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 8px;
  background: linear-gradient(135deg, var(--accent), var(--amber));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

.empty-state .badge {
  display: inline-block;
  margin-top: 16px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
}

/* ─── Loading ─────────────────────────────────────────────────────────────── */

.loading {
  color: var(--text-muted);
  font-size: 13px;
}

.loading-dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app-shell {
    height: auto;
    min-height: calc(100vh - 64px);
    grid-template-columns: 1fr;
  }

  .side-panel { grid-template-rows: auto auto; }
  .search-section { max-height: 320px; }

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

@media (max-width: 560px) {
  .app-header {
    height: auto;
    min-height: 56px;
    padding: 10px 14px;
  }

  .brand h1 { font-size: 15px; }
  .brand-sub { display: none; }
  .status-badge { display: none; }

  .app-shell { padding: 8px; gap: 8px; }

  .message { max-width: 94%; font-size: 13px; }
}
