/* HKBU official style: deep blue #00487d, accent blue #0f62fe,
   Poppins / Microsoft JhengHei typography (per hkbu.edu.hk). */
:root {
  --hkbu-blue: #00487d;
  --hkbu-blue-dark: #003557;
  --hkbu-accent: #0f62fe;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #252525;
  --muted: #6c757d;
  --line: #dee2e6;
  --bubble-user: #e3edfa;
  --bubble-bot: #f1f3f5;
  --warn: #8a5f00;
  --warn-bg: #fff7e0;
  --warn-line: #eed98f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Poppins", -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
}

/* Masthead — white bar, official logo, blue underline like hkbu.edu.hk */
header {
  background: var(--card);
  border-bottom: 3px solid var(--hkbu-blue);
  padding: 14px 24px;
  display: flex; align-items: center; gap: 18px;
}
header img.logo { height: 34px; width: auto; }
header .titles { border-left: 1px solid var(--line); padding-left: 18px; }
header h1 {
  margin: 0; font-size: 1.05rem; font-weight: 600;
  color: var(--hkbu-blue); letter-spacing: .2px;
}
.subtitle { margin: 2px 0 0; font-size: .76rem; color: var(--muted); font-weight: 300; }
.sidebar-toggle {
  display: none; border: 1px solid var(--line); background: #fff; border-radius: 4px;
  font-size: 1.1rem; min-width: 44px; min-height: 44px; cursor: pointer; color: var(--hkbu-blue);
}

/* Visible keyboard focus everywhere (browser default outline is too thin). */
button:focus-visible, a:focus-visible, summary:focus-visible, .room-item:focus-visible {
  outline: 2px solid var(--hkbu-accent); outline-offset: 1px;
}

/* Layout: sidebar + chat; the page itself never scrolls — the chat window
   scrolls internally, so Send/chips are always visible (Grok-style). */
.layout { flex: 1; display: flex; min-height: 0; width: 100%; }

#sidebar {
  width: 300px; flex-shrink: 0; background: var(--card);
  border-right: 1px solid var(--line); padding: 14px;
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
}
.new-chat-btn {
  background: var(--hkbu-blue); color: #fff; border: none; border-radius: 4px;
  padding: 10px 14px; min-height: 44px; cursor: pointer; font-size: .88rem; font-family: inherit;
  text-align: left;
}
.new-chat-btn:hover { background: var(--hkbu-blue-dark); }
.room-list { list-style: none; margin: 0; padding: 0; }
.room-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  font-family: inherit; min-height: 44px;
  padding: 8px 10px; border-radius: 4px; font-size: .84rem; font-weight: 300;
  cursor: pointer; color: var(--ink); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; border-left: 3px solid transparent;
}
.room-item:hover { background: var(--bubble-bot); }
.room-item.active {
  background: var(--bubble-user); border-left-color: var(--hkbu-accent);
  color: var(--hkbu-blue); font-weight: 600;
}

/* Recommendation drawer (collapsible form in the sidebar) */
.rec-drawer { border-top: 1px solid var(--line); padding-top: 10px; margin-top: auto; }
.rec-drawer summary {
  cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--hkbu-blue);
  padding: 10px 0; min-height: 44px;
}
/* Smooth open/close: modern ::details-content animation (older browsers
   degrade to instant toggle — acceptable). */
:root { interpolate-size: allow-keywords; }
.rec-drawer::details-content {
  block-size: 0; overflow: hidden; transition: block-size .25s ease;
}
.rec-drawer[open]::details-content { block-size: auto; }
@media (prefers-reduced-motion: reduce) {
  .rec-drawer::details-content { transition: none; }
}
.rec-drawer .card-form {
  border: none; border-top: none; padding: 12px 0 0; max-width: none; gap: 12px;
}
.rec-drawer .privacy-hint { margin-top: 4px; }

main {
  flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 18px 24px;
  display: flex; flex-direction: column; min-height: 0;
}

/* Chat */
.chat-window {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  flex: 1; min-height: 0; overflow-y: auto; padding: 16px;
}
.msg {
  margin: 0 0 12px; padding: 11px 14px; border-radius: 6px;
  line-height: 1.55; font-size: .9rem; font-weight: 300; white-space: pre-wrap;
}
.msg strong { font-weight: 600; }
.msg.user { background: var(--bubble-user); margin-left: 15%; border-left: 3px solid var(--hkbu-accent); }
.msg.bot { background: var(--bubble-bot); margin-right: 15%; border-left: 3px solid var(--hkbu-blue); }
.msg.disclaimer {
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-left: 3px solid var(--warn); margin-right: 0; font-size: .83rem;
}
.msg .citations { margin-top: 8px; padding-top: 7px; border-top: 1px dashed var(--line); font-size: .78rem; }
.msg .citations ul, .msg .citations ol { margin: 4px 0 0; padding-left: 18px; }
.msg .citations a { color: var(--hkbu-accent); text-decoration: none; }
.msg .citations a:hover { text-decoration: underline; }
.msg .md-h { font-weight: 600; margin: 8px 0 2px; color: var(--hkbu-blue-dark); }
.msg .md-hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.msg ul { margin: 4px 0; padding-left: 20px; }
.feedback-row { margin-top: 7px; font-size: .78rem; color: var(--muted); }
.feedback-row button {
  border: 1px solid var(--line); background: #fff; border-radius: 4px;
  cursor: pointer; padding: 2px 8px; margin-right: 4px;
}
.feedback-row button:hover { background: var(--bubble-user); border-color: var(--hkbu-accent); }
.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input {
  flex: 1; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 4px; font-size: .92rem; font-family: inherit;
}
.chat-form input:focus, .card-form select:focus, .card-form input:focus {
  outline: 2px solid var(--hkbu-accent); outline-offset: -1px; border-color: var(--hkbu-accent);
}

/* Buttons — HKBU blue */
button[type="submit"], .card-form button, .course-widget button {
  background: var(--hkbu-blue); color: #fff; border: none; border-radius: 4px;
  padding: 11px 20px; cursor: pointer; font-size: .9rem; font-family: inherit; font-weight: 400;
}
button[type="submit"]:hover, .card-form button:hover, .course-widget button:hover {
  background: var(--hkbu-blue-dark);
}
.privacy-hint { color: var(--warn); font-size: .78rem; margin-top: 8px; font-weight: 300; }
.field-hint { color: var(--muted); font-size: .78rem; font-weight: 300; margin: 0; }

/* Assumed-courses block: flex column with real spacing (the form's gap only
   applies between its direct children). The .hidden overrides are required —
   an ID selector would otherwise beat .hidden and break the hide/show toggle. */
#assumed-box { display: flex; flex-direction: column; gap: 12px; }
#assumed-box.hidden { display: none; }
#assumed-box p { margin: 0; }
#course-options-box { display: flex; flex-direction: column; gap: 6px; }
#course-options-box.hidden { display: none; }

/* Quick-start question chips */
.quick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.quick-chips.hidden { display: none; }
.qc-label { font-size: .78rem; color: var(--muted); font-weight: 300; }
.quick-chips button {
  border: 1px solid var(--hkbu-blue); color: var(--hkbu-blue); background: #fff;
  border-radius: 14px; padding: 8px 14px; min-height: 44px; font-size: .8rem; cursor: pointer; font-family: inherit;
}
.quick-chips button:hover { background: var(--bubble-user); }

/* Reduced motion: no drawer slide animation for users who opt out */
@media (prefers-reduced-motion: reduce) {
  #sidebar { transition: none; }
}

/* Forms */
.card-form {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  border-top: 3px solid var(--hkbu-blue);
  padding: 20px; display: flex; flex-direction: column; gap: 15px; max-width: 580px;
}
.card-form label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; }
.card-form select, .card-form input {
  padding: 10px 11px; border: 1px solid var(--line); border-radius: 4px;
  font-size: .9rem; font-weight: 300; font-family: inherit; background: #fff;
}
.course-widget { display: flex; gap: 8px; }
.course-widget input { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bubble-user); color: var(--hkbu-blue); border-radius: 4px;
  border: 1px solid #c3d6ee;
  padding: 3px 10px; font-size: .8rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip button {
  border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: .95rem;
  /* Expand the tap area beyond the small × glyph without changing the look */
  padding: 10px; margin: -7px -8px -7px 0;
}
#course-options { width: 100%; }

.hidden { display: none; }

/* Recommendation cards (rendered inside a bot message) */
.msg .rec-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  border-left: 3px solid var(--hkbu-blue);
  padding: 15px 17px; margin-bottom: 12px; white-space: normal;
}
.msg .rec-card h3 { margin: 0 0 7px; color: var(--hkbu-blue); font-size: .98rem; font-weight: 600; }
.msg .rec-card p { font-weight: 300; font-size: .88rem; }
.msg .kv { font-size: .84rem; margin: 4px 0; }
.msg .kv strong { color: var(--ink); font-weight: 600; }
.msg .unrec-notice {
  background: #fdf6e3; border: 1px solid #e8d9a0; border-radius: 6px;
  padding: 10px 14px; margin-bottom: 12px; font-size: .84rem; font-weight: 300;
  white-space: normal;
}
.loading { color: var(--muted); font-style: italic; font-weight: 300; }
.error { color: #b3261e; }

/* Footer — HKBU deep blue band */
footer {
  background: var(--hkbu-blue); color: rgba(255,255,255,.85);
  font-size: .76rem; font-weight: 300; text-align: center; padding: 12px 18px;
}

/* Backdrop: hidden by default; only shown behind the open mobile drawer. */
#sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar-toggle { display: block; }
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.15); width: 280px;
  }
  #sidebar.open { transform: translateX(0); }
  /* Backdrop: tap anywhere outside the drawer to close it */
  #sidebar-backdrop {
    position: fixed; inset: 0; z-index: 15;
    background: rgba(0,0,0,.35);
  }
  #sidebar.open + #sidebar-backdrop { display: block; }
  main { padding: 12px 14px; }
}

@media (max-width: 640px) {
  /* Compact Grok-style mobile header: hamburger + small logo only */
  header { padding: 8px 12px; gap: 10px; }
  header .titles { display: none; }
  header img.logo { height: 22px; }
  main { padding: 10px 12px; }
  .msg.user { margin-left: 6%; }
  .msg.bot { margin-right: 6%; }
  /* Chips scroll sideways in one row instead of wrapping into a tall block */
  .quick-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .quick-chips button { white-space: nowrap; flex-shrink: 0; }
  .qc-label { flex-shrink: 0; }
  footer { padding: 8px 12px; font-size: .68rem; }
}
