:root {
  --bg: #0b1020;
  --card: rgba(255,255,255,0.06);
  --card-border: rgba(255,255,255,0.18);
  --text: #e9ecf1;
  --muted: #a7b0c0;
  --accent: #6ae1b9;
  --accent-strong: #22c694;
  --bubble-user: rgba(30,42,74,0.95);
  --bubble-ai: rgba(10,16,32,0.85);
  --chip: rgba(255,255,255,0.08);
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--text);
  /* Global background image outside the app card */
  background-color: var(--bg);
  background-image: 
    radial-gradient(1200px 900px at 10% -10%, #122257 0%, transparent 60%),
    radial-gradient(1200px 900px at 110% 10%, #163b34 0%, transparent 60%),
    url('assets/city-bg.jpg');
  background-size: 1200px 900px, 1200px 900px, cover;
  background-position: 10% -10%, 110% 10%, center;
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-attachment: fixed, fixed, fixed;
  display: grid;
  place-items: center;
  padding: 16px;
}

.app {
  width: min(980px, 100%);
  height: min(92vh, 900px);
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  border: 1px solid var(--card-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(0,0,0,0.2), transparent);
}
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #22c694, #6ae1b9);
  color: #04251c; font-weight: 900;
  letter-spacing: -0.5px;
  box-shadow: 0 6px 18px rgba(34,198,148,0.35);
}
.title { display: flex; flex-direction: column; }
.title h1 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* Intro Hero */
.hero { padding: 12px 18px 0; }
.hero-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  overflow: hidden;
  /* Show fallback hero image via background to avoid broken <img> */
  background-image: url('assets/stockchat.png');
  /* Fit entire image without cropping inside a square box */
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  /* Make the hero box a responsive square */
  width: 100%;
  aspect-ratio: 1 / 1;
  /* Cap width so selectors below remain visible */
  max-width: 520px;
  margin: 0 auto;
}
.hero img {
  width: 100%;
  height: 100%;
  display: block;
  /* Ensure the full image fits without cropping */
  object-fit: contain;
}
/* Ensure hero-card images render nicely; allow <img> to show when valid */
.hero-card img {
  width: 100%;
  height: 100%;
  display: block; /* show when valid src is used */
  object-fit: contain;
}
/* Hide broken local absolute-path images if present */
.hero-card img[src^="C:\\"] {
  display: none !important;
}

.messages {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Ensure chat layout allows the messages area to scroll */
#chat {
  display: grid;
  grid-template-rows: 1fr auto auto; /* messages, chips, composer */
  min-height: 0; /* allow inner overflow */
}
.messages { min-height: 0; }

.bubble {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--card-border);
}
.bubble.ai { background: var(--bubble-ai); }
.bubble.user { background: var(--bubble-user); margin-left: auto; }

.row { display: flex; gap: 10px; align-items: flex-end; }
.avatar { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px; display: grid; place-items: center; font-size: 13px; }
.avatar.ai { background: #132128; border: 1px solid var(--card-border); }
.avatar.user { background: #1c2a4d; border: 1px solid var(--card-border); }

.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 18px 10px; border-bottom: 1px dashed var(--card-border);
}
.chip {
  background: var(--chip);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 12px; padding: 8px 10px; border-radius: 999px;
  cursor: pointer; transition: transform .12s ease, background .12s ease;
}
.chip:hover { transform: translateY(-1px); background: rgba(255,255,255,0.12); }

.composer {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  padding: 14px 16px; border-top: 1px solid var(--card-border);
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.25));
}
.inputWrap {
  display: flex; background: rgba(0,0,0,0.25);
  border: 1px solid var(--card-border); border-radius: 14px;
  padding: 10px 12px; gap: 10px; align-items: flex-end;
}
textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  max-height: 160px; min-height: 22px; line-height: 1.5; font-size: 14px;
}
.sendBtn {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #082117; border: 0; padding: 10px 14px; border-radius: 12px;
  font-weight: 700; cursor: pointer; box-shadow: 0 8px 20px rgba(34,198,148,0.35);
  transition: transform .12s ease, filter .12s ease; white-space: nowrap;
}
.sendBtn:disabled { filter: saturate(.3) brightness(.8); cursor: not-allowed; }
.sendBtn:hover:not(:disabled) { transform: translateY(-1px); }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #cfe9de; opacity: .45; animation: blink 1.2s infinite; }
.dot:nth-child(2){ animation-delay: .15s }
.dot:nth-child(3){ animation-delay: .3s }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

@media (max-width: 640px) {
  .bubble { max-width: 86%; }
  .app { height: 90vh; }
}
