:root {
  --bg: #0b1210;
  --panel: #0f1715;
  --muted: #93a29b;
  --text: #ebf5f0;
  --mint: #4fe3b4;
  --mint-600: #28c89b;
  --card: #121c19;
  --border: #1f2a26;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 20% 20%, rgba(46, 164, 123, 0.12), transparent), var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
}

#app {
  display: grid;
  grid-template-columns: 480px 1fr;
  height: 100vh;
  height: 100dvh; /* modern browsers */
  min-height: 0; /* allow children to shrink inside grid */
}

/* Chat pane */
.chat {
  background: linear-gradient(180deg, rgba(25, 39, 34, 0.7), rgba(16, 25, 22, 0.7)), var(--panel);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0; /* so messages can scroll inside */
}
.chat__header { padding: 16px 16px 12px 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 36px; height: 36px; display: grid; place-items: center; font-size: 24px; background: #133d31; border: 1px solid #185340; border-radius: 10px; box-shadow: 0 6px 20px var(--shadow); }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.5px; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }

/* Mode Toggle Switch - iOS Style */
.mode-toggle {
  margin-top: 12px;
  position: relative;
  display: inline-flex;
  align-items: center;
  background: #0a0f0d;
  padding: 3px;
  border-radius: 20px;
  border: 1px solid #1a2622;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
  width: 240px;
  height: 40px;
}

/* Animated sliding pill */
.mode-toggle::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: linear-gradient(135deg, var(--mint) 0%, var(--mint-600) 100%);
  border-radius: 17px;
  box-shadow: 
    0 2px 8px rgba(79, 227, 180, 0.3),
    0 4px 16px rgba(79, 227, 180, 0.2);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.mode-toggle[data-active-mode="advisor"]::before {
  transform: translateX(calc(100% + 3px));
}

.mode-btn {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: none;
  color: #4a5854;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  height: 100%;
  user-select: none;
}

.mode-btn:hover {
  color: #6a7874;
}

.mode-btn--active {
  color: #0b1210;
}

.mode-icon {
  font-size: 15px;
  transition: transform 0.3s ease;
  display: inline-block;
}

.mode-btn--active .mode-icon {
  transform: scale(1.15);
}

.mode-label {
  letter-spacing: 0.3px;
  font-weight: 700;
}

.chat__messages { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.msg { display: flex; gap: 10px; }
.msg .bubble {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.4;
  font-size: 14px;
  box-shadow: 0 8px 24px var(--shadow);
  white-space: pre-wrap;  /* Preserve line breaks and wrap text */
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: #17342c; border: 1px solid #1d4b3d; }
.msg.bot .bubble { background: #151f1c; border: 1px solid #21322d; }

/* Typing indicator */
.msg.typing-indicator .bubble { display: flex; gap: 4px; align-items: center; padding: 12px 16px; }
.msg.typing-indicator .dot {
  width: 8px;
  height: 8px;
  background: var(--mint);
  border-radius: 50%;
  animation: typing-dot 1.4s infinite ease-in-out;
}
.msg.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.msg.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

.chat__input { padding: 10px 14px 14px; border-top: 1px solid var(--border); background: linear-gradient(180deg, rgba(12, 18, 16, 0.6), rgba(12, 18, 16, 0.9)); }
#chat-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#message-input {
  width: 100%;
  padding: 12px 14px;
  background: #0c1311;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}
.btn {
  background: linear-gradient(180deg, var(--mint), var(--mint-600));
  color: #0a1411;
  border: none;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(79, 227, 180, 0.25);
}
.btn:disabled { filter: saturate(0.2) brightness(0.8); cursor: default; }
.hints { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* Results pane */
.results { display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.results__header { padding: 16px 18px; border-bottom: 1px solid var(--border); backdrop-filter: blur(6px); background: linear-gradient(180deg, rgba(8,12,11,0.5), rgba(8,12,11,0.2)); }
.results__header h2 { margin: 0; font-size: 16px; opacity: 0.9; }
.summary { margin-top: 4px; color: var(--muted); font-size: 13px; }

.cards { padding: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; overflow: auto; min-height: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 28px var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 16px 40px var(--shadow); }
.card__media { width: 100%; aspect-ratio: 16/10; background: #0b0f0e; position: relative; overflow: hidden; min-height: 160px; }
/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 1 / 1) {
  .card__media::before { content: ""; display: block; padding-top: 62.5%; }
}
.card__media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card__body { padding: 14px; display: grid; gap: 6px; }
.card__title { margin: 0; font-size: 15px; }
.pillrow { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; color: #0a1411; background: #c2ffe9; border-radius: 999px; padding: 4px 8px; }
.meta { color: var(--muted); font-size: 12px; }
.card__description { margin: 8px 0 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.card__footer { padding: 12px 14px 14px; display: flex; gap: 10px; }
.link { text-decoration: none; background: #14382f; border: 1px solid #1c4a3e; color: #caffee; padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.source { margin-left: auto; color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 420px 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 3fr 2fr; }
  .cards { grid-template-columns: 1fr; }
}
