/* ARC 2.0 — Main Stylesheet */
/* Clean light theme, REF colour system */

:root {
  --bg-start: #EBF3FA;
  --bg-end: #EBF3FA;
  --glass-bg: rgba(255, 255, 255, 0.95);
  --glass-border: rgba(0, 0, 0, 0.08);
  --user-bubble-start: #5B3FCE;
  --user-bubble-end: #7B52C1;
  --bot-bubble-bg: #FFFFFF;
  --text-primary: #1A1A2E;
  --text-secondary: #4A5568;
  --text-muted: #94A3B8;
  --accent-default: #5B3FCE;
  --input-bg: #FFFFFF;
  --input-border: #CBD5E1;
  --refs-pane-width: 320px;
  --refs-pane-collapsed: 48px;
  --left-strip-width: 64px;
  --transition: 0.25s ease;

  /* REF Colour Accents */
  --ref-lavender: #E040FB;
  --ref-yellow: #FBC02D;
  --ref-orange: #F4511E;
  --ref-blue: #0288D1;
  --ref-green: #388E3C;
  --ref-bronze: #8D6E63;
  --ref-silver: #78909C;
  --ref-gold: #F9A825;
  --ref-platinum: #90A4AE;

  /* Source Type Badge Colours */
  --badge-document: #78909C;
  --badge-research: #0D47A1;
  --badge-community: #E65100;
  --badge-synthesis: #4B2D8F;
  --badge-manual: #1B5E20;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  color: var(--text-primary);
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────────── */
#arc-layout {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — accounts for mobile browser chrome */
  width: 100vw;
  overflow: hidden;
}

/* Left strip */
#left-strip {
  width: var(--left-strip-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  background: #F1F4F9;
  border-right: 1px solid var(--glass-border);
  gap: 12px;
}

#new-chat-btn {
  width: 56px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--user-bubble-start), var(--user-bubble-end));
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: white;
  padding: 8px 4px;
  transition: opacity 0.2s, transform 0.2s;
  flex-shrink: 0;
}

#new-chat-btn .nc-icon  { font-size: 18px; line-height: 1; }
#new-chat-btn .nc-label { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.3px; opacity: 0.9; }

#new-chat-btn:hover {
  opacity: 0.85;
  transform: scale(1.04);
}

/* Centre chat area */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
#arc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

#arc-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ref-logo-mark {
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #A78BFA, #7B52C1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  border: 1.5px solid rgba(167, 139, 250, 0.45);
  border-radius: 6px;
  padding: 3px 7px;
  flex-shrink: 0;
}

.ref-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.ref-logo-arc {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.ref-logo-arc span {
  color: var(--accent-default);
}

.ref-logo-sub {
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

/* ── Header brand (center) ────────────────────────────────────────────────── */
#header-brand {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 16px;
  text-align: center;
}

.header-brand-title {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.header-brand-plain { color: #1A1A2E; }
.header-brand-accent { color: #5B3FCE; }

.header-brand-sub {
  font-size: 0.68rem;
  color: #4A5568;
  line-height: 1.35;
  max-width: 380px;
  margin: 0;
}

/* ── Header logos ─────────────────────────────────────────────────────────── */
.header-logo-hsrc {
  height: 60px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  background: white;
  border-radius: 8px;
  padding: 0;
}

.header-logo-yf {
  height: 60px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.header-logo-divider {
  width: 1px;
  height: 60px;
  background: var(--glass-border);
  flex-shrink: 0;
}

/* ── Welcome screen logos ──────────────────────────────────────────────────── */
.welcome-logos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  margin-bottom: 28px;
}

.welcome-logo-yf {
  height: 100px;
  width: auto;
  object-fit: contain;
}

.welcome-logo-hsrc {
  height: 100px;
  width: auto;
  object-fit: contain;
  background: white;
  border-radius: 10px;
  padding: 0;
}

#model-badge {
  font-size: 0.72rem;
  background: #EDE9FB;
  border: 1px solid rgba(91, 63, 206, 0.3);
  border-radius: 20px;
  padding: 3px 10px;
  color: #5B3FCE;
}

#quarantine-banner {
  display: none;
  background: rgba(220, 100, 30, 0.18);
  border: 1px solid rgba(220, 100, 30, 0.4);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.72rem;
  color: #F9A825;
  cursor: pointer;
}

#quarantine-banner button.dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  margin-left: 8px;
  cursor: pointer;
  font-size: 0.8rem;
}

#config-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.1rem;
  transition: color 0.2s;
}
#config-link:hover { color: var(--text-primary); }

#about-link {
  color: var(--accent-default);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border: 1px solid var(--accent-default);
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
#about-link:hover { background: var(--accent-default); color: #fff; }

#mobile-about-link {
  display: none;  /* hidden on desktop */
}

/* Chanua logo link — transparent wrapper on desktop, active on mobile */
#chanua-logo-about-link {
  display: contents;  /* invisible layout wrapper on desktop */
  text-decoration: none;
}

/* ── Chat messages ────────────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 2px; }

/* ── Avatars ─────────────────────────────────────────────────────────────────── */
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar svg {
  width: 46px;
  height: 46px;
}

.avatar-bot {
  margin-top: 2px;
  filter: drop-shadow(0 2px 6px rgba(91,63,206,0.3));
}

.avatar-user {
  margin-bottom: 2px;
  filter: drop-shadow(0 2px 6px rgba(71,85,105,0.3));
}

/* User bubble */
.msg-user {
  align-self: flex-end;
  max-width: 78%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  justify-content: flex-end;
}

.msg-user .bubble {
  background: linear-gradient(135deg, var(--user-bubble-start), var(--user-bubble-end));
  color: white;
  padding: 12px 16px;
  border-radius: 12px 12px 2px 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

/* Bot bubble */
.msg-bot {
  align-self: flex-start;
  max-width: 86%;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.msg-bot .bubble {
  background: var(--bot-bubble-bg);
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--accent-default);
  color: var(--text-primary);
  padding: 14px 54px 14px 16px;
  border-radius: 2px 12px 12px 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}

/* REF colour accent via CSS variable */
.msg-bot .bubble[data-colour="lavender"] { border-left-color: var(--ref-lavender); }
.msg-bot .bubble[data-colour="yellow"]   { border-left-color: var(--ref-yellow); }
.msg-bot .bubble[data-colour="orange"]   { border-left-color: var(--ref-orange); }
.msg-bot .bubble[data-colour="blue"]     { border-left-color: var(--ref-blue); }
.msg-bot .bubble[data-colour="green"]    { border-left-color: var(--ref-green); }
.msg-bot .bubble[data-colour="bronze"]   { border-left-color: var(--ref-bronze); }
.msg-bot .bubble[data-colour="silver"]   { border-left-color: var(--ref-silver); }
.msg-bot .bubble[data-colour="gold"]     { border-left-color: var(--ref-gold); }
.msg-bot .bubble[data-colour="platinum"] { border-left-color: var(--ref-platinum); }

/* Markdown in bot bubble */
.msg-bot .bubble h1, .msg-bot .bubble h2, .msg-bot .bubble h3 {
  font-size: 1em;
  font-weight: 600;
  margin: 10px 0 4px;
  color: var(--text-primary);
}

.msg-bot .bubble ul, .msg-bot .bubble ol {
  padding-left: 18px;
  margin: 6px 0;
}

.msg-bot .bubble li { margin: 3px 0; }

.msg-bot .bubble p { margin: 6px 0; }

.msg-bot .bubble code {
  background: #F1F5F9;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 0.85em;
}

.msg-bot .bubble a {
  color: #5B3FCE;
  text-decoration: underline;
}

/* Inline citations — superscript hyperlinks, identical style for 1 or many */
.msg-bot .bubble sup {
  line-height: 0;           /* prevent superscripts from stretching line-height */
}

.msg-bot .bubble .cite-link {
  color: #5B3FCE;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s, text-decoration-style 0.15s;
}

.msg-bot .bubble .cite-link:hover {
  color: #7C3AED;
  text-decoration-style: solid;
}

/* Meta below bot bubble */
.msg-bot .bubble-meta {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.country-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.confidence-summary {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Follow-up chips */
.follow-up-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.follow-up-chip {
  background: #EDE9FB;
  border: 1px solid rgba(91, 63, 206, 0.3);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.75rem;
  color: #5B3FCE;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.follow-up-chip:hover {
  background: #DDD6FE;
  transform: translateY(-1px);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 4px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Input area ──────────────────────────────────────────────────────────────── */
#input-area {
  padding: 14px 20px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: #FFFFFF;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

#input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color 0.2s;
}

#input-wrapper:focus-within {
  border-color: rgba(91, 63, 206, 0.5);
}

#query-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  min-height: 24px;
}

#query-input::placeholder { color: var(--text-muted); }

#send-btn {
  min-width: 70px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--user-bubble-start), var(--user-bubble-end));
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: white;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s;
}

#send-btn:hover { opacity: 0.85; transform: scale(1.04); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#send-btn.stop-mode {
  background: linear-gradient(135deg, #B91C1C, #EF4444);
}

/* ── Clear button ───────────────────────────────────────────────────────────── */
#clear-btn {
  background: linear-gradient(135deg, var(--user-bubble-start), var(--user-bubble-end));
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  padding: 4px 14px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.2s, transform 0.15s;
}
#clear-btn:hover {
  opacity: 0.85;
  transform: scale(1.04);
}

/* ── References Pane ─────────────────────────────────────────────────────────── */
#refs-pane {
  width: var(--refs-pane-width);
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: var(--glass-bg);
  border-left: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  transition: width var(--transition);
  overflow: hidden;
  position: relative;
}

#refs-pane.has-refs {
  display: flex;
}

#refs-pane.collapsed {
  width: var(--refs-pane-collapsed);
}

#refs-toggle-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 48px;
  background: #EDE9FB;
  border: 1px solid rgba(91, 63, 206, 0.25);
  border-left: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5B3FCE;
  z-index: 10;
  transition: background 0.2s;
}

#refs-toggle-btn:hover { background: #DDD6FE; }

#refs-toggle-btn svg {
  transition: transform var(--transition);
  flex-shrink: 0;
}

#refs-pane.collapsed #refs-toggle-btn svg {
  transform: rotate(180deg);
}

/* Collapsed state — show count badge */
#refs-count-badge {
  display: none;
  position: absolute;
  top: 12px;
  right: 6px;
  background: #5B3FCE;
  border-radius: 20px;
  padding: 2px 6px;
  font-size: 0.7rem;
  color: white;
  font-weight: 600;
}

#refs-pane.collapsed #refs-count-badge { display: block; }

/* Refs header */
#refs-header {
  padding: 14px 16px 10px 28px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}

#refs-pane.collapsed #refs-header { display: none; }

/* Refs scroll area */
#refs-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 10px 26px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#refs-pane.collapsed #refs-list { display: none; }

#refs-list::-webkit-scrollbar { width: 3px; }
#refs-list::-webkit-scrollbar-track { background: transparent; }
#refs-list::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 2px; }

/* Reference card */
.ref-card {
  background: #F8F9FC;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 10px 10px 8px;
  transition: background 0.2s;
}

.ref-card:hover { background: #F1F4F9; }

.ref-card.highlight {
  border-color: rgba(91, 63, 206, 0.5);
  background: #EDE9FB;
  animation: highlight-pulse 2s forwards;
}

@keyframes highlight-pulse {
  0% { box-shadow: 0 0 0 0 rgba(123, 82, 193, 0.5); }
  50% { box-shadow: 0 0 0 4px rgba(123, 82, 193, 0); }
  100% { box-shadow: none; }
}

.ref-card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.ref-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #5B3FCE;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  margin-top: 1px;
}

.ref-title {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
  flex: 1;
}

/* Source type badge */
.source-badge {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.source-badge.formal_doc  { background: var(--badge-document); color: white; }
.source-badge.research_agent { background: var(--badge-research); color: white; }
.source-badge.telegram    { background: var(--badge-community); color: white; }
.source-badge.synthesis   { background: var(--badge-synthesis); color: white; }
.source-badge.manual      { background: var(--badge-manual); color: white; }

/* Ref tags */
.ref-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.ref-tag {
  font-size: 0.65rem;
  background: #E2E8F0;
  border-radius: 10px;
  padding: 1px 7px;
  color: var(--text-muted);
}

/* Confidence dots */
.ref-confidence {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.67rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.conf-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  background: #CBD5E1;
}

.conf-dot.filled { background: #5B3FCE; }

/* Display reference link — same style for all refs (URL or not) */
.ref-link {
  display: inline-block;
  font-size: 0.72rem;
  color: #5B3FCE;
  text-decoration: underline;
  word-break: break-word;
  cursor: pointer;
  transition: color 0.15s;
}

.ref-link:hover {
  color: #7C3AED;
}

/* Expandable section */
.ref-expand-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  cursor: pointer;
  padding: 2px 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.ref-expand-toggle:hover { color: var(--text-secondary); }

.ref-expand-content {
  display: none;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--glass-border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.ref-expand-content.open { display: block; }

/* ── Welcome screen ──────────────────────────────────────────────────────────── */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  flex: 1;
  gap: 0;
  padding: 1.75rem 1.5rem 0;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  text-align: center;
  position: relative;
  overflow: visible;
}

.welcome-hero {
  text-align: center;
  margin-bottom: 1.5rem;
}

.hero-heading {
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 0.5rem;
}

.hero-heading-plain  { color: #1A1A2E; }
.hero-heading-accent { color: #5B3FCE; display: block; }

.hero-sub {
  font-size: 0.95rem;
  color: #4A5568;
  max-width: 560px;
  margin: 0 auto 1.5rem;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.welcome-chip {
  background: #EDE9FB;
  border: 1px solid rgba(91, 63, 206, 0.3);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: #5B3FCE;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.welcome-chip:hover {
  background: #DDD6FE;
  transform: translateY(-2px);
}

/* ── Filter bar ──────────────────────────────────────────────────────────────── */
.aha-filter-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  text-align: left;
}

.aha-filter-label {
  font-size: 1rem;
  font-weight: 700;
  color: #1A1A2E;
  white-space: nowrap;
}

.aha-filter-selects {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.aha-filter-select {
  background: #2A4858;
  color: #e2e8f0;
  border: 1px solid #3A6078;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
  transition: border-color 0.2s, background-color 0.2s;
}

.aha-filter-select:hover  { border-color: #5B3FCE; }
.aha-filter-select:focus  { outline: none; border-color: #5B3FCE; box-shadow: 0 0 0 2px rgba(91,63,206,0.25); }

/* ── Custom colour dropdown ──────────────────────────────────────────────────── */
.aha-colour-dropdown {
  position: relative;
  display: inline-block;
}

.aha-colour-trigger {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: #2A4858;
  color: #e2e8f0;
  border: 1px solid #3A6078;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  min-width: 11rem;
}
.aha-colour-trigger:hover { border-color: #5B3FCE; }
.aha-colour-trigger:focus { outline: none; border-color: #5B3FCE; box-shadow: 0 0 0 2px rgba(91,63,206,0.25); }

.aha-colour-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: none;
  border: 1px solid rgba(255,255,255,0.4);
}

.aha-colour-chevron {
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0.7;
}

.aha-colour-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  background: #1e293b;
  border: 1px solid #3A6078;
  border-radius: 8px;
  overflow: hidden;
  z-index: 200;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.aha-colour-option {
  display: flex;
  align-items: center;
  padding: 0.45rem 0.85rem 0.45rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: #e2e8f0;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
  border-left: 8px solid transparent;
}
.aha-colour-option:hover  { background: rgba(255,255,255,0.08); }
.aha-colour-option.active { background: rgba(255,255,255,0.13); }

/* ── Bento grid ──────────────────────────────────────────────────────────────── */
.aha-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  width: 100%;
  padding-bottom: 3.5rem;
}

/* ── Flip card ───────────────────────────────────────────────────────────────── */
.aha-flip-card {
  height: 190px;
  cursor: pointer;
  perspective: 900px;
  min-width: 0;
}

.aha-flip-card.aha-hero {
  grid-row: span 2;
  height: auto;
  min-height: 390px;
}

.aha-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 12px;
}

.aha-flip-card:hover .aha-card-inner {
  transform: rotateY(180deg);
}

/* Both faces */
.aha-card-front,
.aha-card-back {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px;
}

/* ── Front face ──────────────────────────────────────────────────────────────── */
.aha-card-front {
  color: #1A1A2E;
  justify-content: flex-end;
  gap: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.aha-card-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  width: 80px;
  height: 80px;
  color: rgba(255,255,255,0.6);
  flex-shrink: 0;
}

/* Back face: small watermark icon in top-right corner */
.aha-card-back .aha-card-icon {
  top: 8px;
  right: 10px;
  left: auto;
  transform: none;
  width: 28px;
  height: 28px;
  opacity: 0.35;
}

.aha-card-cc {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 1rem;
  line-height: 1;
  color: rgba(0,0,0,0.65);
  background: rgba(255,255,255,0.45);
  padding: 2px 5px;
  border-radius: 4px;
}
.aha-card-cc img.emoji { width: 1.2em; height: 1.2em; vertical-align: -0.15em; display: inline; }
.aha-tab img.emoji     { width: 1.1em; height: 1.1em; vertical-align: -0.1em;  display: inline; }


.aha-card-ftitle {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
  color: #1A1A2E;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Back face ───────────────────────────────────────────────────────────────── */
.aha-card-back {
  transform: rotateY(180deg);
  justify-content: space-between;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding-top: 42px;  /* clear flag badge (top-left) + icon watermark (top-right) */
}

.aha-card-btitle {
  font-size: 0.71rem;
  font-weight: 400;
  color: #1A1A2E;
  line-height: 1.5;
  flex: 1;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.aha-card-hint {
  font-size: 0.66rem;
  color: rgba(0,0,0,0.5);
  font-weight: 600;
  text-align: right;
  margin: 8px 0 0;
}

/* ── Loading ─────────────────────────────────────────────────────────────────── */
.aha-loading {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 40px 0;
}


/* ── Turn selection — click bot bubble to switch references pane ─────────────── */
.msg-bot[data-turn-index] {
  cursor: pointer;
}

/* Subtle hover ring — shows the bubble is clickable */
.msg-bot[data-turn-index]:not(.active-turn):hover .bubble {
  box-shadow: 0 0 0 1px rgba(91, 63, 206, 0.2);
  transition: box-shadow 0.15s ease;
}

/* Active turn — bright ring to show which answer's refs are displayed */
.msg-bot.active-turn .bubble {
  box-shadow: 0 0 0 2px rgba(91, 63, 206, 0.45);
  transition: box-shadow 0.2s ease;
}

/* ── Visualise button ────────────────────────────────────────────────────────── */
.btn-visualise {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid rgba(91,63,206,0.30);
  background: rgba(91,63,206,0.09);
  color: #5B3FCE;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(91,63,206,0.10);
}
.btn-visualise:hover { background: rgba(91,63,206,0.18); transform: scale(1.08); box-shadow: 0 3px 10px rgba(91,63,206,0.22); }
.btn-visualise:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-visualise.loading { animation: spin 0.9s linear infinite; }

/* ── Visualise modal ─────────────────────────────────────────────────────────── */
#visualise-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.72);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#visualise-modal-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background: white;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
}
#visualise-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
}
#visualise-modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid #E2E8F0;
  background: #FAFAFA;
  gap: 8px;
}
.visualise-dl-btn {
  font-size: 0.82rem;
  font-weight: 600;
  color: #5B3FCE;
  text-decoration: none;
  padding: 6px 14px;
  border: 1.5px solid rgba(91,63,206,0.35);
  border-radius: 6px;
  transition: background 0.15s;
}
.visualise-dl-btn:hover { background: #EDE9FB; }
.visualise-close-btn {
  font-size: 0.82rem;
  color: #64748B;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Country flags inline with coloured labels */
.flag-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Reference title with no URL — non-clickable, visually distinct */
.ref-link-nourl {
  cursor: default;
  opacity: 0.6;
}

/* General-knowledge badge shown when response has no ARC data citations */
.no-data-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid #e2e8f0;
  padding: 5px 8px 2px;
  margin-top: 8px;
  font-style: italic;
  opacity: 0.8;
}

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

/* Tablet: refs pane becomes a floating overlay */
@media (max-width: 1024px) {
  #refs-pane {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  }
}

/* Tablet: 2-column grid */
@media (max-width: 900px) {
  .aha-grid { grid-template-columns: repeat(2, 1fr); }
  .aha-flip-card.aha-hero { grid-row: span 1; height: 190px; min-height: unset; }
}

/* Mobile */
@media (max-width: 640px) {
  #left-strip { display: none; }

  /*
   * Mobile header: 2-column grid
   *   Col 1: logos (spans both rows)
   *   Col 2 row 1: "Career Guidance Intelligence"
   *   Col 2 row 2: lang selector + clear button
   */
  #arc-header {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    padding: 8px 12px;
    gap: 0 10px;
  }

  /* Logos — left column, spans both rows */
  #arc-logo {
    grid-column: 1;
    grid-row: 1 / 3;
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: center;
  }
  .header-logo-hsrc, .header-logo-yf { height: 36px; }
  .header-logo-divider { height: 36px; }

  /* Brand title — top of right column */
  #header-brand {
    grid-column: 2;
    grid-row: 1;
    padding: 0 0 3px;
    align-items: flex-start;
    text-align: left;
    min-width: 0;
  }
  .header-brand-title {
    font-size: 0.9rem;
    white-space: normal;   /* allow word wrap */
    line-height: 1.25;
  }
  .header-brand-sub { display: none; }

  /* Controls — below title in right column */
  #arc-header > div:last-child {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 3px;
  }
  #config-link { display: none; }
  #about-link  { display: none; }
  #chanua-logo-about-link { display: inline-block; cursor: pointer; }
  #mobile-about-link {
    display: block;
    text-align: center;
    padding: 1.2rem 0 0.4rem;
  }
  #mobile-about-link a {
    color: #5B3FCE;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    letter-spacing: 0.01em;
  }
  #mobile-about-link a:hover { text-decoration: underline; }
  #input-area { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  #clear-btn span[data-i18n] { display: none; }
  #clear-btn { padding: 5px 8px; min-width: unset; }
  .lang-selector select {
    padding: 4px 6px;
    font-size: 0.72rem;
    max-width: 140px;
    width: 100%;
  }

  /* Hide avatars on mobile */
  .avatar { display: none; }
  .msg-bot { gap: 0; }
  .msg-user { gap: 0; }
  #welcome-screen { padding: 1rem 1rem 0; }
  .hero-heading { font-size: 1.6rem; }
  .aha-filter-bar { gap: 0.4rem; margin-bottom: 1rem; flex-direction: column; align-items: flex-start; }
  .aha-filter-label { display: none; }
  .aha-filter-selects { width: 100%; flex-direction: column; gap: 0.4rem; }
  .aha-filter-select { flex: 1; min-width: 0; width: 100%; box-sizing: border-box; }
  .aha-colour-dropdown { width: 100%; }
  .aha-colour-trigger { min-width: 0; width: 100%; box-sizing: border-box; }
  .aha-colour-list { min-width: 200px; }
  .aha-grid { grid-template-columns: 1fr; }
  .aha-flip-card.aha-hero { grid-row: span 1; height: 190px; min-height: unset; }
  #refs-pane {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  }
  #refs-pane.collapsed { width: 24px; }
  #refs-pane.collapsed #refs-toggle-btn { width: 24px; }
  #refs-pane:not(.collapsed) { width: min(320px, 90vw); }
  .msg-bot { max-width: 98%; }
  .msg-user { max-width: 90%; }
  .btn-visualise { width: 32px; height: 32px; top: 8px; right: 8px; }
  .msg-bot .bubble { padding-right: 46px; }
}

/* Touch devices — always show back (text) face; no hover flip needed */
@media (hover: none) {
  .aha-card-inner {
    transform: rotateY(180deg) !important;
    transition: none !important;
  }
}

/* ── Floating feedback character ─────────────────────────────────────────── */
#assistant-char {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 72px;
  z-index: 1500;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#assistant-char:active { cursor: grabbing; }
#assistant-img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.25));
  transition: transform 0.15s;
  pointer-events: none;
}
#assistant-char:hover #assistant-img { transform: scale(1.06); }

/* Action buttons — radiate above the character */
#assistant-actions {
  position: absolute;
  bottom: 80%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  display: none;
}
#assistant-actions.open { display: block; pointer-events: none; }
.asst-btn {
  position: fixed;
  z-index: 1502;
  pointer-events: all;
  background: rgba(255,255,255,0.96);
  border: 1.5px solid rgba(91,63,206,0.22);
  border-radius: 20px;
  padding: 5px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: #1A1A2E;
  white-space: nowrap;
  box-shadow: 0 3px 14px rgba(0,0,0,0.18);
  transition: box-shadow 0.15s, filter 0.15s;
}
.asst-btn:hover { box-shadow: 0 5px 20px rgba(91,63,206,0.3); filter: brightness(1.03); }
.asst-btn-icon { font-size: 1rem; line-height: 1; }

/* Thought bubble */
#asst-bubble {
  display: none;
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  width: 260px;
  background: #fff;
  border: 1.5px solid #E2E8F0;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.14);
  z-index: 1600;
}
#asst-bubble::after {
  content: '';
  position: absolute;
  bottom: -11px;
  right: 24px;
  border: 10px solid transparent;
  border-top-color: #E2E8F0;
  border-bottom: 0;
}
#asst-bubble::before {
  content: '';
  position: absolute;
  bottom: -9px;
  right: 25px;
  border: 9px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
  z-index: 1;
}
#asst-bubble-input {
  width: 100%;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  resize: none;
  outline: none;
  color: #1A1A2E;
  background: #F8F9FC;
  margin-bottom: 8px;
  display: block;
}
#asst-bubble-input:focus { border-color: #5B3FCE; background: #fff; }
.asst-bubble-row { display: flex; justify-content: space-between; align-items: center; }
.asst-bubble-send {
  padding: 5px 16px;
  background: linear-gradient(135deg,#5B3FCE,#7B52C1);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.asst-bubble-send:hover { opacity: 0.9; }
.asst-bubble-close {
  background: none;
  border: none;
  color: #94A3B8;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.asst-bubble-close:hover { color: #1A1A2E; }

/* Thank-you flash */
#asst-thanks {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #6EE7B7;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 1600;
}

/* Mobile — smaller character */
@media (max-width: 640px) {
  #assistant-char  { width: 56px; bottom: 16px; right: 12px; }
  .asst-btn        { font-size: 0.67rem; padding: 5px 9px; }
  #asst-bubble     { width: 230px; right: -8px; bottom: calc(100% + 10px); }
}

/* ── Mobile bottom sheet ──────────────────────────────────────────────────── */
#asst-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1800;
  -webkit-tap-highlight-color: transparent;
}
#asst-backdrop.open { display: block; }

#asst-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 1900;
  box-shadow: 0 -6px 32px rgba(0,0,0,0.18);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
  -webkit-tap-highlight-color: transparent;
}
#asst-sheet.open { transform: translateY(0); }

.asst-sheet-handle {
  width: 40px;
  height: 4px;
  background: #CBD5E1;
  border-radius: 2px;
  margin: 0 auto 16px;
}

.asst-sheet-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.asst-sheet-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  background: #F8F9FC;
  border: 1.5px solid #E2E8F0;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #1A1A2E;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.asst-sheet-btn:active { background: #EDE9FE; border-color: #5B3FCE; }
.asst-sheet-icon { font-size: 1.5rem; line-height: 1; }
