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

body {
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    background: #f0f2f5;
}



/* ===== NAVBAR ===== */
.top-navbar {
    position: static;
    z-index: 1000;
    height: 56px;
    background: rgba(2, 24, 69, 0.92);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.3);
}
.navbar-brand-pro {
    display: flex; align-items: center; gap: 10px;
    color: #fff; font-size: 1rem; font-weight: 600;
    text-decoration: none; letter-spacing: 0.3px;
}
.navbar-brand-pro img { width: 26px; height: 26px; border-radius: 4px; }
.navbar-right a {
    color: rgba(255,255,255,0.75); font-size: 0.875rem;
    text-decoration: none; padding: 6px 14px;
    border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
    transition: all 0.2s ease;
}
.navbar-right a:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* ===== HERO VIDEO ===== */
.hero-section {
    position: relative; width: 100%; height: 400px;
    overflow: hidden; margin-top: 56px;
}
.hero-section video { width: 100%; height: 100%; object-fit: cover; }
.hero-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(2,24,69,0.80) 0%, rgba(160,35,55,0.55) 60%, rgba(0,0,0,0.25) 100%);
    display: flex; flex-direction: column;
    justify-content: center; align-items: flex-start;
    padding: 0 60px;
}
.hero-badge {
    display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
    backdrop-filter: blur(8px); color: #fff;
    font-size: 0.73rem; font-weight: 600; letter-spacing: 1.5px;
    text-transform: uppercase; padding: 6px 16px; border-radius: 100px;
    margin-bottom: 18px; animation: fadeInDown 0.8s ease-out;
}
.hero-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 8px #4ade80; animation: pulse 2s infinite; }
.hero-title { font-size: 2.8rem; font-weight: 700; color: #fff; line-height: 1.15; margin-bottom: 14px; text-shadow: 0 2px 12px rgba(0,0,0,0.4); animation: fadeInUp 0.9s ease-out 0.1s backwards; }
.hero-subtitle { font-size: 1.05rem; color: rgba(255,255,255,0.82); max-width: 460px; line-height: 1.6; margin-bottom: 24px; animation: fadeInUp 0.9s ease-out 0.25s backwards; }
.hero-cta {
    display: inline-flex; align-items: center; gap: 10px;
    background: linear-gradient(135deg, #A02337, #8a1d30); color: #fff;
    font-size: 0.93rem; font-weight: 600; padding: 11px 26px;
    border-radius: 12px; border: none; cursor: pointer;
    box-shadow: 0 6px 20px rgba(160,35,55,0.45);
    text-decoration: none; transition: all 0.3s ease;
    animation: fadeInUp 0.9s ease-out 0.4s backwards;
}
.hero-cta:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(160,35,55,0.55); color: #fff; text-decoration: none; }

@keyframes fadeInDown { from { opacity:0; transform:translateY(-20px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeInUp   { from { opacity:0; transform:translateY(24px); }  to { opacity:1; transform:translateY(0); } }
@keyframes pulse      { 0%,100% { opacity:1; transform:scale(1); } 50% { opacity:0.6; transform:scale(1.3); } }

/* ===== LAYOUT ===== */
.main-layout { display: flex; position: relative; width: 100%; }

/* ===== SIDEBAR ===== */

.sidebar-label {
    font-size: 0.68rem; font-weight: 700; letter-spacing: 1.2px;
    text-transform: uppercase; color: #9aa0a6;
    padding: 0 10px; margin: 18px 0 6px;
}
.sidebar-label:first-child { margin-top: 0; }
.sidebar-pro .nav-link {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 12px; border-radius: 10px; color: #3c4043;
    font-size: 0.88rem; font-weight: 500; text-decoration: none;
    transition: all 0.2s ease; margin-bottom: 2px;
}
.sidebar-pro .nav-link svg { color: #80868b; flex-shrink: 0; }
.sidebar-pro .nav-link:hover { background: #f1f3f4; color: #021845; }
.sidebar-pro .nav-link:hover svg { color: #021845; }
.sidebar-pro .nav-link.active { background: linear-gradient(135deg, #A02337, #8a1d30); color: #fff; box-shadow: 0 4px 14px rgba(160,35,55,0.3); }
.sidebar-pro .nav-link.active svg { color: #fff; }

/* ===== CONTENT ===== */
.content-area { flex: 1; padding: 40px 32px; min-width: 0; min-height: 0; position: relative; }
.content-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.content-header h1 { font-size: 1.4rem; font-weight: 700; color: #1a1a2e; }
.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.76rem; font-weight: 600; color: #137333;
    background: #e6f4ea; border-radius: 100px; padding: 5px 12px;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #34a853; animation: pulse 2s infinite; }

/* ===== CHAT CARD ===== */
.chat-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
    border: 1px solid #e8eaed;
    display: flex;
    flex-direction: column;
    /* overflow: hidden; */
    height: 90vh; max-height: 90vh;
    width: 150px;
    /* min-height: 800px; */
}

/* Card Header */
.chat-card-header {
    /* background: linear-gradient(135deg, #021845 0%, #A02337 100%); */
    background: #c2d75a;
    padding: 8px 10px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between;
}
.chat-card-header-left { display: flex; align-items: center; gap: 12px; }
.chat-card-header-right { display: flex; align-items: center; }

.bot-avatar-wrap { position: relative; }
.bot-avatar-wrap img { width: 40px; height: 40px; border-radius: 8px; border: none; box-shadow: none; display: block; }
.bot-avatar-wrap .online-dot { position: absolute; bottom: 2px; right: 2px; width: 10px; height: 10px; background: #4ade80; border-radius: 50%; border: 2px solid #021845; box-shadow: 0 0 6px #4ade80; }
.chat-card-header h5 { color: #18244e; font-size: 24px; font-family: "Times New Roman", Times, serif; font-weight: 600; margin: 0; }
.chat-card-header p  { color: rgba(255,255,255,0.6); font-size: 0.76rem; margin: 2px 0; }

/* Version badge — the label is hardcoded per deployment in
   templates/components/chat_card_header.html. Kept as a sibling of #chatTitle,
   NOT inside it, because switchMode() rewrites that element's textContent. */
.chat-card-header-left > div { display: flex; align-items: center; gap: 8px; }
.version-badge {
    display: inline-block;
    padding: 2px 9px;
    border: 1px solid rgba(24, 36, 78, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.45);
    color: #18244e;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

/* Disclaimer Button */
.disclaimer-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
}
.disclaimer-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}
.disclaimer-btn:active {
    transform: scale(0.95);
}

/* ===== CHAT BODY ===== */
.chat-body {
    flex: 1; overflow-y: auto; padding: 16px; box-sizing: border-box;
    background: #fafbfc; min-height: 600px; max-height: auto;
}
.chat-body::-webkit-scrollbar { 
    width: 16px;
    height: 16px;
}
.chat-body::-webkit-scrollbar-thumb { 
    background: #a7abb3;
    border-radius: 10px; 
    border: 3px solid #fafbfc;
}

/* ===== MESSAGE ROWS ===== */
.message-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; animation: msgIn 0.3s ease-out; }
.message-row.user { flex-direction: row-reverse; }
@keyframes msgIn { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }

.msg-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.12);}
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg,#021845,#0a2d6b); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 0.78rem; font-weight: 600; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.12); }

.msg-group { flex: 1; min-width: 0; }
.message-row.user .msg-group { flex: 0 1 auto; max-width: 80%; }
/* Line replies up with the right edge of user queries: a user row reserves the
   avatar icon (2.2rem, set in appendUserMessage) plus the 10px row gap on the
   right, so bot rows reserve the same. Keep this in sync if the icon size
   changes. The greeting/T&C row is excluded so it can stay edge to edge. */
.message-row:not(.user):not(.greeting-row) .msg-group {
    padding-right: calc(2.2rem + 10px);
}

/* word-wrap: break-word; */
.msg-bubble {padding: 12px 16px; border-radius: 18px; font-size: 0.92rem; line-height: 1.6; line-break: loose;} 
.msg-bubble.bot  { background: #fff; color: #2d2d2d; border-radius: 0px 18px 18px 18px; box-shadow: 0 2px 12px rgba(0,0,0,0.07); border: 1px solid #e8eaed; }
.msg-bubble.user { background: linear-gradient(135deg,#021845,#0a2d6b); color: #fff; border-radius: 18px 0px 18px 18px; box-shadow: 0 4px 16px rgba(2,24,69,0.25); max-width: 100%; }
.msg-bubble.bot p { margin: 0 0 8px; }
.msg-bubble.bot p:last-child { margin-bottom: 0; }
.msg-bubble.bot h1, .msg-bubble.bot h2, .msg-bubble.bot h3, .msg-bubble.bot h4, .msg-bubble.bot h5, .msg-bubble.bot h6 { color: #021845; line-height: 1.3; margin: 12px 0 6px; font-weight: 600; }
.msg-bubble.bot h1 { font-size: 1.1rem; }
.msg-bubble.bot h2 { font-size: 1.05rem; }
.msg-bubble.bot h3 { font-size: 1rem; }
.msg-bubble.bot h4, .msg-bubble.bot h5, .msg-bubble.bot h6 { font-size: 0.95rem; }
.msg-bubble.bot h1:first-child, .msg-bubble.bot h2:first-child, .msg-bubble.bot h3:first-child, .msg-bubble.bot h4:first-child, .msg-bubble.bot h5:first-child, .msg-bubble.bot h6:first-child { margin-top: 0; }
.msg-bubble.bot ul, .msg-bubble.bot ol { margin: 6px 0 10px; padding-left: 20px; }
.msg-bubble.bot li { margin: 3px 0; white-space: pre-wrap; }
.msg-bubble.bot .table-responsive { overflow-x: auto; margin: 12px 0; }
.msg-bubble.bot table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.msg-bubble.bot th, .msg-bubble.bot td { border: 1px solid #dfe3e8; padding: 8px 10px; text-align: left; vertical-align: top; }
.msg-bubble.bot th { background: #f1f4f8; color: #021845; font-weight: 600; }
.msg-bubble.bot tr:nth-child(even) { background: #fafbfc; }
.msg-bubble.bot { 
    /* was min(100%, 36rem) - 36rem capped replies at 576px, which looked like
       half-width inside the 1226px card. Let the bubble fill its msg-group. */
    width: 100%;
    box-sizing: border-box;
}
/* T&C welcome bubble - kept full width explicitly (bot replies are full width
   by default now, so this is only a safety net for the greeting row). */
.chat-body > .message-row:first-of-type .msg-bubble.bot.greeting,
.msg-bubble.bot.greeting {
    display: block;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
    background: #fff;
}
.message-row.greeting-row {
    align-items: stretch;
}
.message-row.greeting-row .msg-group {
    flex: 1 1 auto;
    max-width: none;
    width: 100%;
}

.msg-meta { font-size: 0.7rem; color: #9aa0a6; margin-top: 5px; padding: 0 4px; }
.message-row.user .msg-meta { text-align: right; }

/* ===== PERPLEXITY-STYLE ACTION TOOLBAR ===== */
.action-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 6px; padding: 0 2px;
}
.toolbar-left  { display: flex; align-items: center; gap: 2px; }
.toolbar-right { display: flex; align-items: center; gap: 2px; }

.toolbar-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 50%; font-size: 1rem;
    border: none; background: transparent; cursor: pointer;
    color: #9aa0a6; font-size: 0.82rem;
    transition: all 0.2s ease;
}
.toolbar-btn:hover { background: #f1f3f4; color: #3c4043; }
.toolbar-btn.active-like   { color: #137333; background: #e6f4ea; }
.toolbar-btn.active-dislike{ color: #c5221f; background: #fce8e6; }

/* Draw the X and keep the heading from collapsing around a floated control. */
.popover .popover-heading {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.35rem;
}
.popover .btn-close:hover {
    opacity: 1;
}

.sources-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 0 10px; height: 32px; border-radius: 100px;
    border: none; background: transparent; cursor: pointer;
    color: #9aa0a6; font-size: 0.78rem; font-weight: 500;
    transition: all 0.2s ease;
}
.sources-btn:hover { background: #f1f3f4; color: #3c4043; }
.sources-favicons { display: flex; align-items: center; }
.sources-favicons img {
    width: 14px; height: 14px; border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.08);
    margin-left: -4px; background: #fff;
}
.sources-favicons img:first-child { margin-left: 0; }

/* === custom dropdown === */ 
.voice-language-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1.5px solid #e0e4ea;
  background: #f8f9fa;
  font-size: 0.85rem;
  color: #3c4043;
  cursor: pointer;
  transition: all 0.2s ease;
}
.voice-language-select:hover {
  border-color: #A02337;
  background: #fff;
}

/* ===== GEMINI-STYLE INLINE FOLLOW-UPS ===== */
.followups-panel {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.followup-chip {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 16px 9px 12px;
    border-radius: 100px;
    border: 1.5px solid #e0e4ea;
    background: #fff;
    cursor: pointer;
    text-align: left;
    width: fit-content;
    max-width: 100%;
    transition: all 0.2s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    font-family: 'Inter', sans-serif;
}
.followup-chip:hover {
    border-color: #A02337;
    background: rgba(160,35,55,0.04);
    box-shadow: 0 3px 10px rgba(160,35,55,0.1);
    transform: translateX(3px);
}
.followup-chip:hover .followup-chip-icon { color: #A02337; }
.followup-chip:hover .followup-chip-text { color: #A02337; }

.followup-chip-icon {
    color: #9aa0a6;
    flex-shrink: 0;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
}

.followup-chip-text {
    font-size: 0.87rem;
    color: #3c4043;
    line-height: 0.8;
    font-weight: 400;
    transition: color 0.2s ease;
    max-width: 100%;
}
.followup-chip-text strong {
    font-weight: 600;
    color: #1a1a2e;
}
.followup-chip:hover .followup-chip-text strong {
    color: #A02337;
}

/* ===== SOURCE LINKS ===== */
.source-links {
    margin-top: 12px;
    padding: 8px 0;
}
.source-links strong {
    font-size: 0.85rem;
    display: block;
    margin-bottom: 6px;
}
.source-links ul {
    margin: 0;
    padding-left: 20px;
    list-style-type: disc;
}
.source-links li {
    margin: 4px 0;
    font-size: 0.82rem;
}
.source-links a {
    color: #1967d2;
    text-decoration: none;
}
.source-links a:hover {
    text-decoration: underline;
}

/* ===== QUICK REPLIES ===== */
.quick-replies {
    padding: 12px 20px; display: flex; flex-wrap: wrap; gap: 8px;
    background: #fff; border-top: 1px solid #f1f3f4;
}
.quick-reply-btn {
    padding: 7px 16px; border-radius: 100px;
    background: #f1f3f4; border: 1px solid #e0e0e0;
    color: #3c4043; font-size: 0.82rem; font-weight: 500;
    cursor: pointer; text-decoration: none; display: inline-block;
    transition: all 0.2s ease;
}
.quick-reply-btn:hover { background: linear-gradient(135deg,#A02337,#8f2436); color: #fff; border-color: transparent; transform: translateY(-1px); text-decoration: none; }

/* ===== INPUT ===== */
.chat-input-area { padding: 14px 18px; flex-shrink: 0; background: #fff; border-top: 1px solid #e8eaed; margin-top: auto; }
.input-wrapper {
    display: flex; align-items: center; gap: 10px;
    background: #f1f3f4; border: 2px solid transparent;
    border-radius: 14px; padding: 8px 8px 8px 16px;
    transition: all 0.25s ease;
}
.input-wrapper:focus-within { background: #f1f3f4; border-color: transparent; box-shadow: none; }
.input-wrapper input { flex: 1; border: none; background: transparent; font-size: 0.93rem; color: #202124; outline: none; }
.input-wrapper input::placeholder { color: #9aa0a6; }
.send-btn {
    width: 38px; height: 38px; border-radius: 10px;
    background: #f1f3f4; border: 1.5px solid #e0e0e0;
    color: #5f6368; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.25s ease; flex-shrink: 0;
}
.send-btn:hover { background: #e8eaed; border-color: #d0d0d0; color: #3c4043; }

.voice-btn {
    width: 38px; height: 38px; border-radius: 10px;
    background: #f1f3f4; border: 1.5px solid #e0e0e0;
    color: #5f6368; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.25s ease; flex-shrink: 0;
}
.voice-btn:hover { background: #e8eaed; border-color: #d0d0d0; color: #3c4043; }
.voice-btn.recording { background: #fce8e6; }

.refresh-input-btn {
    width: 38px; height: 38px; border-radius: 10px;
    background: #f1f3f4; border: 1.5px solid #e0e0e0;
    color: #5f6368; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.25s ease; flex-shrink: 0;
}
.refresh-input-btn:hover {
    background: #e8eaed;
    border-color: #d0d0d0;
    color: #3c4043;
}

.voice-status {
    font-size: 0.85rem; color: #A02337; margin-top: 8px; padding-left: 4px;
    min-height: 20px; font-weight: 500;
}

.debug-voice-btn {
    margin-top: 8px;
    padding: 6px 12px;
    font-size: 0.75rem;
    background: #f1f3f4;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    color: #666;
}
.debug-voice-btn:hover {
    background: #e8eaed;
}

.tooltip-inner {
    max-width: min(320px, calc(100vw - 32px));
    white-space: normal;
    text-align: left;
}

.tooltip-inner {
    max-width: min(320px, calc(100vw - 32px));
    white-space: normal;
    text-align: left;
}

@media (max-width: 768px) {
    .toolbar-btn {
        width: 44px;
        height: 44px;
    }
    .tooltip-inner {
        font-size: 0.85rem;
        padding: 8px 10px;
    }
}

#holdToSpeak {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* ===== MODE SWITCHER ===== */
.mode-switcher { margin-top: 4px; }

.mode-btn {
    display: flex; align-items: flex-start; gap: 10px;
    width: 100%; padding: 10px 12px; border-radius: 12px;
    border: 1.5px solid transparent; background: transparent;
    cursor: pointer; text-align: left; font-family: 'Inter', sans-serif;
    transition: all 0.2s ease; margin-bottom: 4px;
}
.mode-btn:hover { background: #f1f3f4; border-color: #e0e4ea; }
.mode-btn.active {
    background: linear-gradient(135deg, rgba(2,24,69,0.06), rgba(160,35,55,0.04));
    border-color: rgba(2,24,69,0.2);
}

.mode-icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    border: 1px solid #e0e4ea;
    background: #f8f9fa;
    color: #80868b;
    transition: all 0.2s ease;
}
.mode-btn.active .mode-icon {
    background: linear-gradient(135deg, #a50d0d, #a50d0d);
    color: #fff; border-color: transparent;
    box-shadow: 0 3px 8px rgba(2,24,69,0.3);
}
/* .mode-btn.active[data-mode="oer"] .mode-icon {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 3px 8px rgba(217,119,6,0.3);
} */
.mode-btn.active[data-mode="research"] .mode-icon {
    background: linear-gradient(135deg, #5d60e9, #7165f3);
    box-shadow: 0 3px 8px rgba(99,102,241,0.3);
}
/* .mode-btn.active[data-mode="greendeck"] .mode-icon {
    background: linear-gradient(135deg, #1a7f4b, #25a165);
    box-shadow: 0 3px 8px rgba(26,127,75,0.3);
} */

.mode-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mode-name {
    font-size: 0.83rem; font-weight: 600; color: #3c4043;
    transition: color 0.2s ease;
}
.mode-btn.active .mode-name { color: #1a1a2e; }
.mode-desc {
    font-size: 0.71rem; color: #9aa0a6; line-height: 0.8;
    white-space: normal;
}

.mode-badge {
    display: inline-block; font-size: 0.62rem; font-weight: 700;
    letter-spacing: 0.5px; text-transform: uppercase;
    padding: 2px 7px; border-radius: 100px; margin-left: 6px;
    vertical-align: middle;
}
.badge-active { background: rgba(2,24,69,0.1); color: #021845; }
.mode-btn.active[data-mode="oer"]        .badge-active { background: rgba(217,119,6,0.1); color: #d97706; }
.mode-btn.active[data-mode="research"]    .badge-active { background: rgba(99,102,241,0.1); color: #6366f1; }
.mode-btn.active[data-mode="greendeck"]   .badge-active { background: rgba(26,127,75,0.1); color: #1a7f4b; }

/* mode-specific header tint */
.chat-card-header.mode-oer       { background: linear-gradient(135deg, #d97706 0%, #7c2d12 100%); }
.chat-card-header.mode-research  { background: linear-gradient(135deg, #6366f1 0%, #1e1b4b 100%); }
.chat-card-header.mode-greendeck { background: linear-gradient(135deg, #1a7f4b 0%, #0d4a2b 100%); }

/* ===== RESPONSIVE PAGE CONTAINER ===== */
.page-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    margin-top: 24px; /* after the shorthand, which would otherwise reset it */
}

.navbar-toggler {
    display: none;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1rem;
    margin-right: 10px;
    transition: all 0.2s ease;
}
.navbar-toggler:hover { background: rgba(255,255,255,0.1); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* ===== DESKTOP (>=1025px) ===== */
@media (min-width: 1025px) {
    .page-container {
        padding: 0 48px;
    }
    .main-layout {
        max-width: 1280px;
        margin: 0 auto;
    }
    .sidebar-pro {
        display: block;
        width: 230px;
    }
}

/* ===== iPAD / TABLET (769px - 1024px) ===== */
@media (max-width: 1024px) and (min-width: 769px) {
    .page-container {
        padding: 0 32px;
    }
    .main-layout {
        gap: 20px;
    }
    .sidebar-pro {
        display: block;
        width: 200px;
        flex-shrink: 0;
    }
    .content-area {
        padding: 22px 0;
    }
    .hero-section {
        height: 340px;
    }
    .hero-title {
        font-size: 2.4rem;
    }
    .chat-body {
        min-height: 320px;
        max-height: 520px;
    }
}

/* ===== MOBILE (<=768px) ===== */
@media (max-width: 768px) {
    .navbar-toggler {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .sidebar-overlay.active {
        display: block;
    }
    .sidebar-pro {
        display: none;
        position: fixed;
        /* Fixed to the viewport and above both stacked headers (site header +
           chatbot navbar), instead of assuming a single 56px fixed navbar. */
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        z-index: 1002;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar-pro.mobile-open {
        display: block;
        transform: translateX(0);
    }
    .hero-section {
        display: none;
    }
    .main-layout {
        /* the site header now occupies part of the viewport */
        min-height: calc(100vh - var(--site-header-h, 82px) - 56px);
    }
    .page-container {
        padding: 0 12px;
    }
    .content-area {
        padding: 16px 0;
    }
    .chat-body {
        min-height: 260px;
        max-height: 420px;
        padding: 16px;
    }
    .message-row.user .msg-group {
        max-width: 100%;
    }
    .chat-card-header {
        padding: 14px 18px;
    }
    .quick-replies {
        padding: 10px 14px;
    }
    .action-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: space-between;
    }
    .toolbar-left,
    .toolbar-right {
        flex-wrap: wrap;
        gap: 4px;
    }
}

/* -- Primo result cards ---------------------------------------------- */
.primo-cards {
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    gap: 16px;
    margin: 8px 0 16px;
}

.primo-cards .primo-card {
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid #e8eaed;
    border-top: 4px solid #A02337;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

.primo-cards .card-body {
    padding: 20px 18px 20px 18px;
}

.primo-cards .card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #a50d0d;
    margin: 0 0 4px;
    line-height: 1.35;
}

.primo-cards .card-subtitle {
    font-size: 0.78rem;
    color: #6c757d;
    margin-bottom: 8px;
}

.primo-cards .card-text {
    width: 100%;
    font-size: 0.82rem;
    color: #4a4a4a;
    max-width: 100%;
    max-height: 7.5em;
    overflow: hidden;
    margin-bottom: 8px;
}

.primo-cards .card-link {
    font-size: 0.82rem;
    color: #1967d2;
}

.primo-cards .card-link:hover {
    color: #1967d2;
}

/* Feedback toast - shown for 3s after a thumb vote is recorded.
   Markup is created on demand by showFeedbackToast() in demo_new_ui.js. */
.feedback-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%) translateY(12px);
    z-index: 2100;
    padding: 10px 20px;
    border-radius: 999px;
    background: #2e7d32;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.feedback-toast--show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.feedback-toast--error {
    background: #A02337;
}

/* Edit a user query in place (Google AI Mode style) */
.edit-query-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 6px;
    opacity: 0.55;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.edit-query-btn:hover,
.edit-query-btn:focus-visible {
    opacity: 1;
    background: rgba(0, 0, 0, 0.08);
}

.edit-query-textarea {
    width: 100%;
    min-height: 64px;
    resize: vertical;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    color: #202124;
    background: #fff;
    box-sizing: border-box;
}

.edit-query-textarea:focus {
    outline: none;
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.edit-query-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.edit-query-actions button {
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: transparent;
    color: #fff;
    border-radius: 999px;
    padding: 4px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.edit-query-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.edit-query-actions .edit-query-submit {
    background: #fff;
    border-color: #fff;
    color: #0a2d6b;
    font-weight: 600;
}

.edit-query-actions .edit-query-submit:hover {
    background: rgba(255, 255, 255, 0.85);
}

/* Chat area content width - cap the conversation card and center it */
.chat-card {
    width: 100%;
    max-width: 1226px;
    margin: 0 auto;
}

/* Header close button - rightmost, returns to the Library website */
.chat-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #18244e;
    font-size: 16px;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

.chat-close-btn:hover,
.chat-close-btn:focus-visible {
    background: rgba(24, 36, 78, 0.14);
    color: #18244e;
    transform: scale(1.06);
}

/* ===== Library site header (replica of www.lib.polyu.edu.hk) =====
   Values measured from the live site: 1226px centered container, one 82px
   row, library logo left, utility links right, and the PolyU logo as WHITE
   artwork on maroon #A02337.

   The maroon shape is the live site's own technique: a full-viewport-width
   ::before painted behind the logo and skewed -45deg (computed transform
   matrix(1, 0, -1, 1, 0, 0)), which yields the 45-degree diagonal edge at the
   logo's left and a solid band to the right edge of the page. No clip-path.

   The 7-item menu bar is intentionally omitted.
   Markup: templates/components/site_header.html */
.site-header {
    position: relative;
    z-index: 900;
    /* Published height of the header row; the mobile layout uses it to size
       itself, and it changes in the media query below. */
    --site-header-h: 82px;
    /* chatbot-main.css makes <body> a column flex container, so this header is
       a flex item - without flex-shrink: 0 the chat card squeezed it to 0px
       and the whole header disappeared. */
    flex: 0 0 auto;
    background: #fff;
    overflow: hidden; /* clips the full-bleed skewed band, no scrollbar */
    font-family: Roboto, Arial, "Microsoft JhengHei", Helvetica, sans-serif;
}

.site-header__container {
    width: 100%;
    max-width: 1226px;
    margin: 0 auto;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-header__top .site-header__container { height: 82px; gap: 24px; }

.site-header__brand { display: flex; align-items: center; text-decoration: none; flex-shrink: 0; }
.site-header__logo { height: 45px; width: auto; display: block; }

/* PolyU logo block - white logo needs the maroon behind it.
   The band's diagonal runs from +HALF_ROW at the top to -HALF_ROW at the
   bottom, so padding-left of HALF_ROW (41px of the 82px row) puts the logo's
   left edge exactly on the diagonal's top vertex - clear of the slanted edge.
   Width = 246px logo + 41px offset, so the logo still ends flush right. */
.site-header__brand--polyu {
    position: relative;
    box-sizing: border-box;
    width: 287px;            /* 246px logo + 41px diagonal offset */
    height: 82px;
    padding-left: 41px;      /* half the row height = the 45deg skew offset */
    margin-right: -10px;     /* flush with the container's right edge */
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Same construction as the live site: full-width band, skewed -45deg.
   The skew pivots on the band's vertical centre, so the visible edge runs
   from +41px at the top to -41px at the bottom of the 82px row. */
.site-header__brand--polyu::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    background: #A02337;
    transform: skewX(-45deg);
    z-index: 0;
}

.site-header__polylogo { position: relative; z-index: 1; height: 48px; width: auto; display: block; }

@media (max-width: 1024px) {
    .site-header { --site-header-h: 64px; }
    .site-header__top .site-header__container { height: 64px; }
    .site-header__logo { height: 34px; }
    /* 174px logo (34px tall) + 32px = half the 64px row */
    .site-header__brand--polyu { width: 206px; height: 64px; padding-left: 32px; }
    .site-header__polylogo { height: 34px; }
}

/* ===== MOBILE: the chatbot IS the screen (<=768px) =====

   On a phone the conversation takes the whole viewport: no library header, no
   chatbot navbar, no page padding, no card radius/border/shadow. The card's
   own header sits on the top edge and the input bar on the bottom edge.

   Every selector is prefixed with `body` for one reason: the deployed view
   (templates/chatbot-main.html) links chatbot-main.css AFTER this file, and
   that file re-applies its own centering box at equal specificity
   (`.content-area { padding: 2rem 1rem }`, `.content-area > * { max-width:
   960px }`). The extra body step makes these rules win regardless of order,
   so the full-bleed layout does not depend on <link> order.

   The inline height that demo_new_ui.js used to write on .chat-card is cleared
   there for this same breakpoint - an inline style would beat all of this. */
@media (max-width: 768px) {
    /* viewport chrome handed back to the conversation */
    body .site-header,
    body .top-navbar { display: none; }

    /* strip the wrapper boxes that padded the card away from the edges */
    body .page-container { margin: 0; padding: 0; max-width: none; }
    body .main-layout   { min-height: 0; max-width: none; gap: 0; }

    body .content-area {
        padding: 0;
        align-items: stretch;
        justify-content: flex-start;
    }
    body .content-area > * { max-width: none; }

    body .chat-card {
        width: 100%;
        max-width: none;
        /* chatbot-main.css makes .chat-card a `flex: 1` item of a column
           .content-area. A 0 flex-basis wins over `height` on the main axis, so
           the card collapsed to its content height (427px on a 390x844 phone)
           and left a 416px hole at the bottom. `flex: none` lets the height
           below actually govern. */
        flex: 0 0 auto;
        height: 100vh;      /* fallback for browsers without dvh */
        height: 100dvh;     /* the height that is actually visible with the
                               mobile URL bar shown/hidden */
        max-height: none;
        min-height: 0;
        margin: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    /* the card is one viewport tall, so the transcript is the part that has to
       flex; the old 260px/420px mobile caps would leave a gap above the input */
    body .chat-body {
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
        padding: 16px 12px;
        overscroll-behavior: contain;
    }

    /* The coloured bars still reach the physical edge; only their CONTENT is
       inset, by the notch / home-indicator area. head.html sets
       viewport-fit=cover, so this is required or the title sits under the
       notch and the send button under the home bar. Resolves to 0 on devices
       without an inset. */
    body .chat-card-header {
        padding: calc(12px + env(safe-area-inset-top, 0px))
                 calc(14px + env(safe-area-inset-right, 0px))
                 12px
                 calc(14px + env(safe-area-inset-left, 0px));
    }
    body .chat-input-area {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* ===== EMBEDDED CHROME =====

   app-sso.py reads ?hidehead=true / ?hidemic=true off the query string, keeps it
   alive across its own self-redirects (/reset, the mode toggles) and renders the
   body classes below. Nothing is remembered, so a plain "/" visit always shows the
   full UI. When the green bar is not rendered at all, the transcript owns the top
   edge - which on a phone means it also has to carry the notch inset the bar used
   to absorb. */
body.no-head .chat-body {
    padding-top: 16px;
}

@media (max-width: 768px) {
    body.no-head .chat-body {
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }
}
