/* ==========================================================================
   CAF Policy AI — design system
   Navy from the source cards, sky blue from the logo, Inter for UI text.
   ========================================================================== */

:root {
    --brand: #004280;
    --brand-hover: #00366a;
    --brand-soft: #e8f0fa;
    --brand-softer: #f3f7fc;
    --accent: #2fb4e6;
    --accent-ring: rgba(47, 180, 230, 0.28);

    --ink: #0f1b2d;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --bg: #f6f8fb;
    --surface: #ffffff;

    --warn-bg: #fff7ed;
    --warn-line: #fdba74;
    --warn-ink: #7c2d12;
    --danger-bg: #fef2f2;
    --danger-ink: #991b1b;

    --radius-lg: 12px;
    --radius: 9px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.05), 0 1px 3px rgba(15, 27, 45, 0.07);
    --shadow-md: 0 10px 30px -12px rgba(15, 27, 45, 0.18), 0 2px 6px rgba(15, 27, 45, 0.05);
    --shadow-lg: 0 24px 60px -20px rgba(15, 27, 45, 0.35);

    --app-bar-height: 64px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Bootstrap hooks */
    --bs-body-font-family: var(--font);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--bg);
    --bs-border-color: var(--line);
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 0, 66, 128;
    --bs-link-hover-color: var(--brand-hover);
    --bs-link-hover-color-rgb: 0, 54, 106;
    --bs-primary: var(--brand);
    --bs-primary-rgb: 0, 66, 128;
    --bs-border-radius: var(--radius-sm);
}

html {
    scroll-behavior: smooth;
    overflow-y: scroll;
    scrollbar-width: thin;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15.5px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: rgba(47, 180, 230, 0.25);
}

a {
    color: var(--brand);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -48px;
    z-index: 1000;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: var(--brand);
    color: white;
    font-weight: 600;
    text-decoration: none;
}
.skip-link:focus {
    top: 12px;
}

/* --------------------------------------------------------------------------
   App bar
   -------------------------------------------------------------------------- */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 90;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.app-bar-inner {
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: 1200px;
    height: var(--app-bar-height);
    margin: 0 auto;
    padding: 0 24px;
}
.brand {
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    text-decoration: none;
}
.brand img {
    width: 46px;
    height: 46px;
}
.brand-name {
    font-size: 1.4rem;
    font-weight: 750;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand-badge {
    margin-left: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--brand);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    vertical-align: 3px;
}
.brand:hover {
    color: var(--ink);
}
.app-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.app-nav a {
    padding: 7px 12px;
    border-radius: 7px;
    color: var(--ink-2);
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}
.app-nav a:hover {
    background: var(--bg);
    color: var(--ink);
}
.app-nav a.activepage {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}
.app-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
    color: var(--ink-2);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
}
.icon-btn:hover {
    border-color: var(--line-strong);
    background: var(--bg);
    color: var(--ink);
}
.icon-btn.icon-only {
    width: 36px;
    height: 36px;
    justify-content: center;
    padding: 0;
}

/* --------------------------------------------------------------------------
   About drawer (was the fixed sidebar)
   -------------------------------------------------------------------------- */
#mySidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    width: min(400px, 92vw);
    border-left: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.28s;
}
.drawer-open #mySidebar {
    transform: none;
    visibility: visible;
}
.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(15, 27, 45, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s;
}
.drawer-open .drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
}
.drawer-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.drawer-head img {
    width: 40px;
    height: 40px;
}
.drawer-title {
    font-weight: 700;
    line-height: 1.25;
}
.drawer-subtitle {
    color: var(--muted);
    font-size: 0.82rem;
}
.drawer-head .icon-btn {
    margin-left: auto;
}
.sidebarcontent {
    flex: 1;
    padding: 8px 20px 24px;
    overflow-y: auto;
}
#mySidebar h4,
#mySidebar h5 {
    margin: 22px 0 10px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.textchunk {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--brand-softer);
    color: var(--ink-2);
    font-size: 0.92rem;
}
.textchunk ol,
.textchunk ul {
    margin: 0;
    padding-left: 1.1rem;
}
.textchunk li + li {
    margin-top: 6px;
}
.footnote {
    color: var(--muted);
    font-size: 0.82rem;
}
.legal a {
    color: var(--ink-2);
    font-size: 0.88rem;
}

/* --------------------------------------------------------------------------
   Page layout and header
   -------------------------------------------------------------------------- */
.page {
    flex: 1;
    width: 100%;
}
.main {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 24px;
}
.titleblock {
    padding: 40px 0 8px;
}
.titleblock h1,
.titleblock #pagename {
    margin: 0 0 8px;
    color: var(--ink);
    font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.3rem);
    font-weight: 750;
    letter-spacing: -0.025em;
    line-height: 1.15;
}
.titleblock #pagedesc {
    max-width: 72ch;
    margin: 0 0 16px;
    color: var(--ink-2);
    font-size: 1.02rem;
}
.titleblock .tip,
.main .tip {
    display: flex;
    gap: 10px;
    max-width: 72ch;
    margin: 0 0 8px;
    padding: 12px 16px;
    border: 1px solid #cfe3f7;
    border-radius: var(--radius);
    background: var(--brand-softer);
    color: var(--brand);
    font-size: 0.92rem;
}
.main .warning {
    margin: 16px 0;
    padding: 12px 16px;
    border: 1px solid #fed7aa;
    border-left: 4px solid var(--warn-line);
    border-radius: var(--radius);
    background: var(--warn-bg);
    color: var(--warn-ink);
    font-size: 0.92rem;
}

.main h2,
.main h3 {
    color: var(--ink);
    font-weight: 700;
    letter-spacing: -0.015em;
}
.main h3 {
    font-size: 1.3rem;
}
.main h4 {
    font-size: 1.08rem;
    font-weight: 650;
}

/* Long-form documents (privacy policy, terms) */
.prose {
    max-width: 760px;
    padding-bottom: 48px;
}
.prose h3 {
    margin: 36px 0 12px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}
.prose h4 {
    margin: 24px 0 8px;
}
.prose h5 {
    margin: 18px 0 6px;
    font-size: 1rem;
    font-weight: 650;
}
.prose p,
.prose li {
    color: var(--ink-2);
}

/* --------------------------------------------------------------------------
   Forms, buttons, tabs, tables (shared by every tool)
   -------------------------------------------------------------------------- */
.main form label:not(.form-check-label):not(.visually-hidden) {
    margin-bottom: 6px;
    color: var(--ink-2);
    font-size: 0.86rem;
    font-weight: 600;
}
.form-control,
.form-select {
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background-color: var(--surface);
    color: var(--ink);
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-select {
    padding-right: 2.25rem;
}
.form-control::placeholder {
    color: #94a3b8;
}
.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
}
.form-control:disabled,
.form-select:disabled {
    background-color: var(--bg);
    color: var(--muted);
}
.form-check-input:checked {
    border-color: var(--brand);
    background-color: var(--brand);
}
.form-check-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
}
.input-group > .btn {
    border-radius: 7px;
}

.btn {
    border-radius: 7px;
    font-weight: 600;
}
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-hover);
    --bs-btn-hover-border-color: var(--brand-hover);
    --bs-btn-active-bg: var(--brand-hover);
    --bs-btn-active-border-color: var(--brand-hover);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: 47, 180, 230;
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--line-strong);
    --bs-btn-hover-bg: var(--brand-soft);
    --bs-btn-hover-color: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-soft);
    --bs-btn-active-color: var(--brand);
    --bs-btn-active-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: 47, 180, 230;
}

/* Tool forms become cards */
#memoData,
#briefData,
#fbnoteData,
#statusForm {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
#fbnoteData > h3 {
    margin-bottom: 4px;
}

.nav-tabs {
    gap: 4px;
    border-bottom: 1px solid var(--line);
}
.nav-tabs .nav-link {
    margin-bottom: -1px;
    padding: 10px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
}
.nav-tabs .nav-link:hover {
    border-bottom-color: var(--line-strong);
    color: var(--ink);
}
.nav-tabs .nav-link.active {
    border-bottom-color: var(--brand);
    background: none;
    color: var(--brand);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink-2);
    margin: 0;
    font-size: 0.9rem;
}
.table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--brand-softer);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.table > tbody > tr > * {
    padding: 10px 14px;
    border-color: var(--line);
    vertical-align: top;
}
.table > tbody > tr:hover > * {
    background: var(--brand-softer);
}

/* --------------------------------------------------------------------------
   Footer and notice banner
   -------------------------------------------------------------------------- */
.site-footer {
    margin-top: 48px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}
.site-footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 24px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 18px 24px;
    color: var(--muted);
    font-size: 0.85rem;
}
.site-footer a {
    color: var(--ink-2);
    text-decoration: none;
}
.site-footer a:hover {
    text-decoration: underline;
}
.footer-links {
    display: flex;
    gap: 16px;
}

#noticebanner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 101;
    align-items: center;
    height: 2.2em;
    background: #fde68a;
    color: #713f12;
    font-size: 0.9em;
    font-weight: 600;
    display: none; /* toggle to turn on/off */
}
#noticebanner .noticetext {
    margin-left: auto;
}
#noticebanner .noticetext p {
    margin: 2px 0;
}
#noticebanner .noticetext2 {
    display: none;
}
#noticebanner #noticeclosebtn {
    display: inline-block;
    margin-left: auto;
    cursor: pointer;
}
#noticebanner #noticeclosebtn i {
    padding: 0 10px;
}
@keyframes hscroll {
    from { transform: translate(0, 0); }
    to { transform: translate(-100%, 0); }
}

/* --------------------------------------------------------------------------
   Policy Chat
   -------------------------------------------------------------------------- */
.page-chat .main {
    max-width: 880px;
}
.page-chat .titleblock {
    padding-top: 32px;
}
.chat-page {
    display: flex;
    flex-direction: column;
}
#chatArea {
    flex: 1;
    padding: 12px 0 24px;
}

/* Empty state */
.chat-empty {
    padding: 28px 0 8px;
}
.chat-empty-card {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(47, 180, 230, 0.10) 0%, transparent 55%),
        var(--surface);
    box-shadow: var(--shadow-sm);
}
.chat-empty h2 {
    margin: 0 0 6px;
    font-size: 1.25rem;
    font-weight: 700;
}
.chat-empty p {
    margin: 0 0 18px;
    color: var(--muted);
}
.suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.suggestion {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 0.92rem;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.suggestion i {
    margin-top: 3px;
    color: var(--accent);
}
.suggestion:hover {
    border-color: #bcd5ee;
    box-shadow: var(--shadow-sm);
    color: var(--ink);
    transform: translateY(-1px);
}

/* Messages */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 22px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.messages-list > li {
    /* Keep scrolled-to messages clear of the sticky app bar and the composer. */
    scroll-margin: calc(var(--app-bar-height) + 16px) 0 170px;
}
.chatBubble {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.chatBubble.user {
    justify-content: flex-end;
}
.chatBubble .avatar {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-top: 2px;
    border-radius: 50%;
    background: var(--brand-soft);
}
.chatBubble .avatar img {
    width: 20px;
    height: 20px;
}
.chatBubble .msg_container {
    position: relative;
    min-width: 0;
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 13px;
    overflow-wrap: anywhere;
}
.chatBubble.user .msg_container {
    border-bottom-right-radius: 4px;
    background: var(--brand);
    color: white;
}
.chatBubble.bot .msg_container {
    border: 1px solid var(--line);
    border-top-left-radius: 4px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.chatBubble.bot.error .msg_container {
    border-color: #fecaca;
    background: var(--danger-bg);
    color: var(--danger-ink);
}
.chatBubble .msg_time,
.chatBubble .msg_time_send {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1;
}
.chatBubble.user .msg_time_send {
    color: rgba(255, 255, 255, 0.72);
    text-align: right;
}
.chatBubble .msg_text {
    white-space: pre-line;
}

.chatBubble .more-detail {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 5px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background: var(--surface);
    color: var(--brand);
    font-size: 0.84rem;
    font-weight: 600;
}
.chatBubble .more-detail i {
    font-size: 0.75em;
}
.chatBubble .more-detail:hover:not(:disabled) {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.chatBubble .more-detail:disabled {
    color: var(--muted);
    cursor: default;
    opacity: 0.7;
}

/* Thinking indicator */
.typing {
    display: inline-flex;
    gap: 5px;
    padding: 6px 2px;
}
.typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    opacity: 0.35;
    animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
    0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Composer, pinned to the bottom of the viewport */
.composer-dock {
    position: sticky;
    bottom: 0;
    z-index: 20;
    padding: 12px 0 16px;
    background: linear-gradient(to bottom, rgba(246, 248, 251, 0) 0%, var(--bg) 28%);
}
#messageForm {
    padding: 10px 10px 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
}
#messageForm:focus-within {
    border-color: #a9d8f0;
    box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-ring);
}
.scope-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 2px 4px 8px;
}
.scope-label {
    flex: none;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}
.scope-row .form-select {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    max-width: 100%;
    padding: 4px 30px 4px 12px;
    border-color: var(--line);
    border-radius: 7px;
    background-color: var(--bg);
    background-position: right 10px center;
    color: var(--ink-2);
    font-size: 0.84rem;
    font-weight: 500;
}
#subpolicy:disabled {
    display: none;
}
.composer-input {
    display: flex;
    align-items: center;
    gap: 8px;
}
#messageInput {
    flex: 1;
    min-width: 0;
    padding: 10px 8px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 1rem;
    outline: none;
}
#messageInput::placeholder {
    color: #94a3b8;
}
#messageInput:disabled {
    background: transparent;
}
.send_btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: white;
    transition: background 0.15s, transform 0.15s;
}
.send_btn:hover {
    background: var(--brand-hover);
}
.send_btn:active {
    transform: scale(0.95);
}
.send_btn:disabled {
    background: var(--line-strong);
    cursor: progress;
}
.composer-note {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.75rem;
    text-align: center;
}

/* --------------------------------------------------------------------------
   Policy Chat: answers and sources
   -------------------------------------------------------------------------- */
.chatBubble .msg_container.has-sources {
    max-width: 88%;
    padding-bottom: 14px;
}
.chatBubble .answer-para {
    margin: 0 0 10px;
    white-space: pre-line;  /* keeps "- " list lines on their own lines */
}
.chatBubble .answer-para:last-of-type {
    margin-bottom: 0;
}
.chatBubble .cite-refs {
    white-space: nowrap;
}
.chatBubble .cite-ref {
    display: inline-block;
    min-width: 1.35em;
    margin-left: 3px;
    padding: 0 5px;
    border-radius: 0.7em;
    background-color: var(--brand-soft);
    color: var(--brand);
    font-size: 0.72em;
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
    text-decoration: none;
    vertical-align: 0.35em;
}
.chatBubble .cite-ref:hover,
.chatBubble .cite-ref:focus-visible {
    background-color: var(--brand);
    color: white;
}
.chatBubble .sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.chatBubble .sources-heading {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}
.chatBubble .source-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.chatBubble .source-card {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background-color: var(--brand-softer);
    scroll-margin: 90px 16px 120px;
    transition: border-color 0.15s;
}
.chatBubble .source-card:hover {
    border-color: #c7dbef;
}
.chatBubble .source-card.flash {
    animation: source-flash 1.4s ease-out;
}
@keyframes source-flash {
    from { box-shadow: 0 0 0 3px rgba(0, 66, 128, 0.35); }
    to { box-shadow: 0 0 0 3px rgba(0, 66, 128, 0); }
}
.chatBubble .source-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.chatBubble .source-num {
    flex: none;
    width: 1.6em;
    height: 1.6em;
    border-radius: 50%;
    background-color: var(--brand);
    color: white;
    font-size: 0.78em;
    font-weight: 700;
    line-height: 1.6em;
    text-align: center;
}
.chatBubble .source-meta {
    min-width: 0;
}
.chatBubble .source-title {
    color: var(--brand);
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
}
.chatBubble a.source-title::after {
    content: " ↗";
    font-weight: 400;
}
.chatBubble a.source-title:hover {
    text-decoration: underline;
}
.chatBubble .source-policy {
    color: var(--muted);
    font-size: 0.84em;
}
.chatBubble .source-excerpts {
    margin: 8px 0 0 calc(1.6em * 0.78 + 10px);
}
.chatBubble .source-excerpts summary {
    width: fit-content;
    color: var(--ink-2);
    font-size: 0.84em;
    font-weight: 500;
    cursor: pointer;
}
.chatBubble .excerpt {
    margin-top: 10px;
}
.chatBubble .excerpt + .excerpt {
    padding-top: 10px;
    border-top: 1px dashed var(--line-strong);
}
.chatBubble .excerpt-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.78em;
}
.chatBubble .excerpt-link {
    color: var(--brand);
    text-decoration: none;
    white-space: nowrap;
}
.chatBubble .excerpt-link:hover {
    text-decoration: underline;
}
.chatBubble .excerpt-text {
    max-height: 14em;
    overflow-y: auto;
    margin: 0;
    padding: 8px 12px;
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
    background-color: var(--surface);
    color: var(--ink-2);
    font-size: 0.88em;
    white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   Memo Gen / Brief Gen: file index picker and terms dialog
   -------------------------------------------------------------------------- */
#fileindex {
    position: fixed;
    top: 10%;
    left: 25%;
    z-index: 200;
    display: none;
    width: 50%;
    height: 80%;
    padding: 16px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}
#fileindex table tbody tr:last-child {
    border: transparent;
}
#fileindex .tableheader {
    position: relative;
}
#fileindex .tableheader h3 {
    display: block;
    margin: auto;
    font-weight: 700;
}
#fileindex .tableheader .buttoncorner {
    position: absolute;
    top: 2px;
    right: 5px;
    padding: 0.4rem;
}
#fileindex .tableheader .buttoncorner .collapse-btn,
#fileindex .tableheader .buttoncorner .btn-langtog {
    display: inline-block;
}
#fileindex table tbody tr th {
    width: 16ch;
    text-align: left;
}
#fileindex table tbody tr td {
    text-align: left;
}
#fileindex table thead th {
    position: static;
}
#fileindex .accordion-item {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
}
#fileindex .accordion-item:hover {
    border-color: var(--brand-soft);
}
#fileindex .accordion-button {
    padding: 0.3em 0.3em;
    font-size: 0.6em;
}
#fileindex table tbody tr {
    cursor: default;
}

#termsconditions {
    position: fixed;
    top: 10%;
    left: 25%;
    z-index: 300;
    display: none;
    width: 50%;
    height: 80%;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: 0 0 0 max(100vh, 100vw) rgba(15, 27, 45, 0.7);
}
#termsconditions #termscontent {
    height: 100%;
    overflow-y: scroll;
}
#termsconditions #termstxt {
    padding: 1em 1.25em;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.todisable {
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Tool pages (Feedback Notes): form on the left, results on the right
   -------------------------------------------------------------------------- */
.tool-layout {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: start;
    gap: 24px;
    margin-top: 8px;
}
.panel-title {
    margin: 0 0 18px;
    font-size: 1.05rem;
    font-weight: 700;
}
.field {
    margin: 0 0 22px;
    padding: 0;
    border: 0;
}
.field legend {
    margin-bottom: 6px;
    color: var(--ink-2);
    font-size: 0.86rem;
    font-weight: 600;
}
.field-hint {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.78rem;
}
.segmented {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
}
/* Must out-rank `.main form label:not(...)`, which adds a bottom margin to labels. */
.main form .segmented label:not(.form-check-label) {
    margin: 0;
    padding: 6px 16px;
    border-radius: 5px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}
.segmented .btn-check:checked + label {
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--brand);
}
.segmented .btn-check:focus-visible + label {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.form-error {
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger-ink);
    font-size: 0.88rem;
}
.results {
    min-width: 0;
}
.results-empty {
    padding: 48px 28px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--brand-softer);
    text-align: center;
}
.results-empty i {
    color: var(--accent);
    font-size: 1.8rem;
}
.results-empty h2 {
    margin: 12px 0 6px;
    font-size: 1.05rem;
    font-weight: 700;
}
.results-empty p {
    max-width: 40ch;
    margin: 0 auto;
    color: var(--muted);
    font-size: 0.9rem;
}
.results-loading {
    display: grid;
    gap: 12px;
}
.results-loading[hidden] {
    display: none;
}
.skeleton-card {
    height: 132px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: linear-gradient(90deg, var(--surface) 0%, var(--brand-softer) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}
#resultsNotes[hidden] {
    display: none;
}
.note-card {
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.note-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}
.note-label {
    color: var(--brand);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.note-text {
    margin: 0;
    color: var(--ink);
    white-space: pre-line;
}
#charLimit {
    max-width: 180px;
}
.optional {
    margin-left: 4px;
    color: var(--muted);
    font-weight: 400;
}
.note-actions {
    display: flex;
    gap: 6px;
}
.btn-outline-secondary {
    --bs-btn-color: var(--ink-2);
    --bs-btn-border-color: var(--line-strong);
    --bs-btn-hover-bg: var(--bg);
    --bs-btn-hover-color: var(--ink);
    --bs-btn-hover-border-color: var(--line-strong);
    --bs-btn-active-bg: var(--bg);
    --bs-btn-active-color: var(--ink);
    --bs-btn-disabled-color: var(--muted);
    --bs-btn-disabled-border-color: var(--line);
}
.rework-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--brand-softer);
}
.rework-panel[hidden] {
    display: none;
}
.rework-panel .form-control {
    flex: 1 1 240px;
    min-width: 0;
}
.rework-error {
    flex-basis: 100%;
    color: var(--danger-ink);
    font-size: 0.82rem;
}
.note-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 12px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.76rem;
}
.note-count.is-over {
    color: var(--danger-ink);
    font-weight: 600;
}
.note-card.is-working .note-text {
    opacity: 0.45;
    transition: opacity 0.2s;
}
.note-competencies.shared {
    margin-top: 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--brand-softer);
}
.copy-hint {
    display: flex;
    gap: 10px;
    margin: 0 0 12px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--brand-softer);
    color: var(--ink-2);
    font-size: 0.86rem;
}
.copy-hint i {
    margin-top: 3px;
    color: var(--accent);
}
#noteCards {
    display: grid;
    gap: 12px;
}
.note-competencies {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--line-strong);
}
.note-competencies-label {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}
.note-competencies ul {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.note-competencies li {
    padding-left: 10px;
    border-left: 3px solid var(--accent);
    color: var(--ink-2);
    font-size: 0.84rem;
}
.note-competencies li strong {
    display: block;
    color: var(--ink);
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Dashboard
   -------------------------------------------------------------------------- */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 8px 0 24px;
}
.stat-card {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.stat-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
}
.stat-value {
    color: var(--ink);
    font-size: 1.5rem;
    font-weight: 750;
    letter-spacing: -0.02em;
}
.dashboard-panel {
    margin-top: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.dashboard-panel .nav-tabs {
    padding: 0 12px;
}
.dashboard-panel .nav-link .count {
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    font-size: 0.74rem;
}
.dashboard-panel .nav-link.active .count {
    background: var(--brand-soft);
    color: var(--brand);
}
.dash-section {
    margin: 8px 0 28px;
}
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.section-head h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}
.muted {
    color: var(--muted);
}
.nowrap {
    white-space: nowrap;
}
.tab-intro {
    margin: 14px 16px 4px;
    color: var(--muted);
    font-size: 0.88rem;
}

.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}
.health-card {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    font-size: 0.88rem;
}
.health-card.is-ok { border-left-color: #16a34a; }
.health-card.is-warn { border-left-color: #f59e0b; }
.health-card.is-fail { border-left-color: #dc2626; background: var(--danger-bg); }
.health-card.is-loading { color: var(--muted); }
.health-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.health-card.is-ok .health-head i { color: #16a34a; }
.health-card.is-warn .health-head i { color: #d97706; }
.health-card.is-fail .health-head i { color: #dc2626; }
.health-ms {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.75rem;
}
.health-summary {
    margin-top: 4px;
    color: var(--ink-2);
    overflow-wrap: anywhere;
}

.stat-sub {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.76rem;
}
.stat-card.is-bad .stat-value {
    color: #b91c1c;
}
.metric-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
}
.metric-panel {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.metric-panel h3 {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}
.metric-panel .table {
    font-size: 0.85rem;
}
.metric-panel .table th,
.metric-panel .table td {
    padding: 5px 4px;
}
.bar-row {
    display: grid;
    grid-template-columns: 150px 1fr auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}
.bar {
    height: 8px;
    overflow: hidden;
    border-radius: 4px;
    background: var(--bg);
}
.bar span {
    display: block;
    height: 100%;
    border-radius: 4px;
    background: var(--brand);
}
.bar-value {
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.status-badge,
.level-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 5px;
    background: var(--bg);
    color: var(--ink-2);
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
}
.status-answered,
.status-reworked { background: #dcfce7; color: #166534; }
.status-conversational { background: var(--brand-soft); color: var(--brand); }
.status-needs_clarification { background: #e0f2fe; color: #075985; }
.status-insufficient_evidence { background: #fef3c7; color: #92400e; }
.status-error,
.status-retrieval_unavailable,
.status-generation_unavailable { background: #fee2e2; color: #991b1b; }
.level-warning { background: #fef3c7; color: #92400e; }
.level-error,
.level-critical { background: #fee2e2; color: #991b1b; }
.dashboard-panel .nav-link .count.is-bad {
    background: #fee2e2;
    color: #991b1b;
}

#bigbrother .table td.request-cell {
    min-width: 340px;
    max-width: 520px;
}
.trace-table td:first-child,
.trace-table td:nth-child(2) {
    white-space: nowrap;
}
.trace-query {
    color: var(--ink);
}
.trace-rewrite {
    margin-top: 2px;
    color: var(--brand);
    font-size: 0.82rem;
}
.trace-meta {
    color: var(--muted);
    font-size: 0.76rem;
}
.trace-details summary {
    color: var(--brand);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
}
.trace-details[open] {
    min-width: 320px;
}
.trace-details h4 {
    margin: 12px 0 6px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}
.trace-sources {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.84rem;
}
.trace-sources li + li {
    margin-top: 4px;
}
.trace-response {
    margin: 0;
    color: var(--ink-2);
    font-size: 0.84rem;
    white-space: pre-line;
}
.trace-error {
    max-width: 70ch;
    max-height: 18em;
    margin: 0;
    padding: 8px 10px;
    overflow: auto;
    border-radius: var(--radius-sm);
    background: #1e293b;
    color: #e2e8f0;
    font-size: 0.75rem;
    white-space: pre-wrap;
}
.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 3px 12px;
    margin: 0;
    font-size: 0.8rem;
}
.kv dt {
    color: var(--muted);
    font-weight: 500;
}
.kv dd {
    margin: 0;
    color: var(--ink-2);
    overflow-wrap: anywhere;
}
.health-card .kv {
    margin-top: 8px;
}

#bigbrother .table-responsive {
    max-height: 70vh;
    overflow: auto;
}
#bigbrother .table td {
    min-width: 12ch;
    max-width: 60ch;
}

/* --------------------------------------------------------------------------
   Dark theme (the dashboard sets data-bs-theme="dark" so it is easy to tell apart)
   -------------------------------------------------------------------------- */
html[data-bs-theme="dark"] {
    color-scheme: dark;
    --brand: #6cb6f2;            /* readable on dark surfaces */
    --brand-hover: #8fc7f5;
    --brand-soft: #1a2d4a;
    --brand-softer: #121f35;
    --accent-ring: rgba(47, 180, 230, 0.35);

    --ink: #e6edf7;
    --ink-2: #b9c5d6;
    --muted: #8796ab;
    --line: #233149;
    --line-strong: #31425f;
    --bg: #0a111e;
    --surface: #101a2c;

    --warn-bg: #2b1f0d;
    --warn-line: #b7791f;
    --warn-ink: #f6c98f;
    --danger-bg: #2c1215;
    --danger-ink: #fca5a5;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.8);

    --bs-body-color: var(--ink);
    --bs-body-bg: var(--bg);
    --bs-border-color: var(--line);
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 108, 182, 242;
    --bs-link-hover-color: var(--brand-hover);
    --bs-secondary-color: var(--muted);
}
[data-bs-theme="dark"] .app-bar {
    background: rgba(16, 26, 44, 0.88);
}
/* The logo is black line art: give it a light disc so it stays visible. */
[data-bs-theme="dark"] .brand img,
[data-bs-theme="dark"] .drawer-head img {
    padding: 2px;
    border-radius: 50%;
    background: #e6edf7;
}
[data-bs-theme="dark"] .brand-badge {
    background: #1d6fc2;
}
[data-bs-theme="dark"] .btn-primary {
    --bs-btn-bg: #1d6fc2;
    --bs-btn-border-color: #1d6fc2;
    --bs-btn-hover-bg: #2a80d6;
    --bs-btn-hover-border-color: #2a80d6;
    --bs-btn-active-bg: #2a80d6;
    --bs-btn-active-border-color: #2a80d6;
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
}
[data-bs-theme="dark"] .titleblock .tip,
[data-bs-theme="dark"] .main .tip {
    border-color: var(--line-strong);
}
[data-bs-theme="dark"] .main .warning {
    border-color: #5c3d12;
    border-left-color: var(--warn-line);
}
[data-bs-theme="dark"] .form-control::placeholder {
    color: #64748b;
}
[data-bs-theme="dark"] .stat-card.is-bad .stat-value {
    color: #f87171;
}
[data-bs-theme="dark"] .health-card.is-fail {
    border-color: #5b1d22;
}
[data-bs-theme="dark"] .bar span {
    background: var(--brand);
}
[data-bs-theme="dark"] .trace-error {
    background: #060b14;
    border: 1px solid var(--line);
}
[data-bs-theme="dark"] .status-answered,
[data-bs-theme="dark"] .status-reworked { background: rgba(34, 197, 94, 0.15); color: #86efac; }
[data-bs-theme="dark"] .status-conversational { background: var(--brand-soft); color: var(--brand); }
[data-bs-theme="dark"] .status-needs_clarification { background: rgba(56, 189, 248, 0.15); color: #7dd3fc; }
[data-bs-theme="dark"] .status-insufficient_evidence,
[data-bs-theme="dark"] .level-warning { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
[data-bs-theme="dark"] .status-error,
[data-bs-theme="dark"] .status-retrieval_unavailable,
[data-bs-theme="dark"] .status-generation_unavailable,
[data-bs-theme="dark"] .level-error,
[data-bs-theme="dark"] .level-critical,
[data-bs-theme="dark"] .dashboard-panel .nav-link .count.is-bad { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .tool-layout {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .app-bar-inner {
        gap: 12px;
        padding: 0 16px;
    }
    .brand-name .brand-full {
        display: none;
    }
    .app-bar-inner {
        gap: 8px;
    }
    .main {
        padding: 0 16px;
    }
    .titleblock {
        padding-top: 24px;
    }
    .suggestions {
        grid-template-columns: 1fr;
    }
    #memoData,
    #briefData,
    #fbnoteData,
    #statusForm {
        padding: 18px;
    }
    #noticebanner .noticetext {
        overflow: hidden;
        white-space: nowrap;
    }
    #noticebanner .noticetext p {
        display: inline-block;
        padding: 0 100%;
        animation: hscroll 20s linear infinite;
    }
}
@media (max-width: 576px) {
    body {
        font-size: 15px;
    }
    .app-nav a {
        padding: 6px 10px;
    }
    .icon-btn .label,
    .brand-name {
        display: none;
    }
    .scope-row {
        flex-wrap: nowrap;
    }
    .chatBubble .msg_container,
    .chatBubble .msg_container.has-sources {
        max-width: 100%;
    }
    .chatBubble.bot .avatar {
        display: none;
    }
    .chatBubble .source-excerpts {
        margin-left: 0;
    }
    #fileindex,
    #termsconditions {
        top: 5%;
        left: 5%;
        width: 90%;
        height: 90%;
    }
}
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
