:root {
    --color-bg-darker: #f2f2f2;
    --color-bg-glow: #e6e6e6;
    --color-card: #ffffff;
    --color-card-alt: #ededed;
    --color-cream: #141414;
    --color-cream-dim: #6e6e6e;
    --color-accent: #1a1a1a;
    --color-accent-dark: #000000;
    --color-pop: #4a4a4a;
    --color-online: #6ee7a0;
    --color-border: rgba(0, 0, 0, 0.12);
    /* hairline for edges of the black panels, where a dark border disappears */
    --color-border-light: rgba(255, 255, 255, 0.12);
    --color-coffee: #0d0d0d;
    --color-coffee-alt: #1c1c1c;

    --radius-lg: 20px;
    --radius-md: 14px;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.08), 0 16px 40px rgba(0, 0, 0, 0.18);
    --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.14);
    /* soft dark halo for the black panels; a white glow would vanish on the light page */
    --glow-dark: 0 0 48px rgba(0, 0, 0, 0.35);

    /* English text uses BLK English; any Arabic letters in it have no glyph
       there, so the browser falls through to BLK Arabic for just those */
    --font-main: "BLK English", "BLK Arabic", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-heading: var(--font-main);
    --font-arabic: "BLK Arabic", "BLK English", "Segoe UI", Tahoma, sans-serif;
}

* {
    box-sizing: border-box;
}

/* Both files are bold-only. The weight range maps every font-weight onto
   them, so the browser doesn't fake-bold an already bold font. */
@font-face {
    font-family: 'BLK English';
    src: url('assets/Fonts/DIN Condensed Bold.ttf') format('truetype');
    font-weight: 100 900;
    /* DIN Condensed draws much smaller than Inter at the same font-size;
       scale it up once here instead of changing every font-size */
    size-adjust: 120%;
    font-display: swap;
}

@font-face {
    font-family: 'BLK Arabic';
    src: url('assets/Fonts/GE-Dinar-One-Bold.otf') format('opentype');
    font-weight: 100 900;
    font-display: swap;
}

body {
    margin: 0;
    height: 100vh;
    display: grid;
    grid-template-columns: 264px 1fr;
    grid-template-rows: auto 1fr auto;
    position: relative;
    overflow: hidden;
    padding: 24px 24px 24px 0;
    font-family: var(--font-main);
    color: var(--color-cream);

    background-color: var(--color-bg-darker);
    background-image:
        radial-gradient(circle at 15% 20%, rgba(0, 0, 0, 0.05), transparent 45%),
        radial-gradient(circle at 85% 15%, rgba(0, 0, 0, 0.04), transparent 40%),
        radial-gradient(circle at 50% 100%, rgba(0, 0, 0, 0.035), transparent 50%);
    background-size: 200% 200%;
    animation: bg-pan 20s ease-in-out infinite;

    transition: grid-template-columns 0.25s ease;
}

body.sidebar-hidden {
    grid-template-columns: 0 1fr;
}

/* Floating ambient blobs, purely decorative */
body::before,
body::after {
    content: "";
    position: fixed;
    border-radius: 50%;
    filter: blur(70px);
    pointer-events: none;
    z-index: 0;
}

body::before {
    top: -12%;
    left: -10%;
    width: 320px;
    height: 320px;
    background: radial-gradient(circle, var(--color-accent), transparent 70%);
    opacity: 0.06;
    animation: blob-float-a 16s ease-in-out infinite;
}

body::after {
    bottom: -15%;
    right: -10%;
    width: 360px;
    height: 360px;
    background: radial-gradient(circle, var(--color-pop), transparent 70%);
    opacity: 0.05;
    animation: blob-float-b 20s ease-in-out infinite;
}

@keyframes bg-pan {
    0%, 100% { background-position: 0% 0%; }
    50% { background-position: 100% 100%; }
}

@keyframes blob-float-a {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, 40px) scale(1.15); }
}

@keyframes blob-float-b {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-40px, -30px) scale(1.1); }
}

@keyframes fade-slide-in {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- Header ---------- */

.chat-header {
    position: relative;
    z-index: 1;
    grid-column: 2;
    justify-self: center;
    width: 100%;
    max-width: 1180px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, var(--color-coffee), var(--color-coffee-alt));
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    box-shadow: var(--shadow-card), var(--glow-dark);
    margin-bottom: 16px;
    animation: fade-slide-in 0.5s ease both;
}

.logo-placeholder {
    position: relative;
    flex-shrink: 0;
    width: 48px;
    height: 64px;
    border-radius: 10px;
    background: #ffffff;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.logo-placeholder:hover {
    transform: rotate(-4deg) scale(1.06);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.logo-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

/* Little steam wisps rising off the logo, for fun */
.logo-placeholder::before,
.logo-placeholder::after {
    content: "";
    position: absolute;
    top: -2px;
    width: 6px;
    height: 14px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    filter: blur(2px);
    opacity: 0;
    animation: steam-rise 3s ease-in-out infinite;
}

.logo-placeholder::before { left: 14px; animation-delay: 0s; }
.logo-placeholder::after { left: 28px; animation-delay: 1.2s; }

@keyframes steam-rise {
    0% { opacity: 0; transform: translateY(0) scale(1); }
    20% { opacity: 0.6; }
    100% { opacity: 0; transform: translateY(-22px) scale(1.6); }
}

.header-text h3 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: clamp(1rem, 2.2vw, 1.5rem);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: linear-gradient(90deg, #ffffff, #b3b3b3);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    /* white glow on the black header; drop-shadow because text-shadow
       bleeds through the transparent, gradient-clipped letters */
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.3));
    transition: filter 0.3s ease;
}

.header-text h3:hover {
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6)) drop-shadow(0 0 16px rgba(255, 255, 255, 0.35));
}

/* Arabic tagline, pushed to the far side of the header */
.header-text-ar {
    margin-left: auto;
}

.header-text-ar h3 {
    font-family: var(--font-arabic);
    font-size: clamp(1.1rem, 2.4vw, 1.65rem);
    /* letter-spacing breaks the joins between Arabic letters */
    letter-spacing: 0;
    line-height: 1.5;
    background-image: linear-gradient(270deg, #ffffff, #b3b3b3);
}

/* ---------- Sidebar ---------- */

#sidebar {
    position: relative;
    z-index: 1;
    grid-column: 1;
    grid-row: 1 / -1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 64px 16px 24px;
    background: linear-gradient(180deg, var(--color-coffee), var(--color-coffee-alt));
    border-right: 1px solid var(--color-border-light);
    /* glow only spills to the right, toward the chat */
    box-shadow: 10px 0 48px rgba(0, 0, 0, 0.3);
    animation: fade-slide-in 0.5s ease both;
}

#new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: #ffffff;
    color: var(--color-coffee);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 22px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

#new-chat-btn::before {
    content: "+";
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
}

#new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    background: #ececec;
}

#new-chat-btn:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

#toggle-chat-list-btn {
    position: fixed;
    top: 30px;
    left: 16px;
    z-index: 20;
    width: auto;
    padding: 3px 8px;
    background: transparent;
    color: #c9c9c9;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

#toggle-chat-list-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.5);
}

/* Once the sidebar collapses, this button sits directly on the light
   page instead of the dark rail, so it needs dark text instead. */
body.sidebar-hidden #toggle-chat-list-btn {
    color: var(--color-cream-dim);
    border-color: var(--color-border);
}

body.sidebar-hidden #toggle-chat-list-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-cream);
    border-color: var(--color-accent);
}

#chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: 8px;

    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#chat-list::before {
    content: "Recent";
    padding: 8px 10px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8f8f8f;
}

#chat-list::-webkit-scrollbar {
    width: 6px;
}

#chat-list::-webkit-scrollbar-track {
    background: transparent;
}

#chat-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 8px;
}

#logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    flex-shrink: 0;
    background: transparent;
    color: #c9c9c9;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: 12px 22px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

#logout-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.5);
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #d0d0d0;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.chat-list-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    transform: translateX(2px);
}

.chat-list-item-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-menu {
    position: relative;
    flex-shrink: 0;
}

.chat-menu-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #a0a0a0;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.chat-list-item:hover .chat-menu-btn,
.chat-menu.open .chat-menu-btn {
    opacity: 1;
}

.chat-menu-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
}

.chat-menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 5;
    display: none;
    flex-direction: column;
    min-width: 120px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.chat-menu.open .chat-menu-dropdown {
    display: flex;
}

.chat-menu-item {
    padding: 8px 14px;
    background: transparent;
    border: none;
    text-align: left;
    font-family: inherit;
    font-size: 0.82rem;
    color: #2b2b2b;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-menu-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

.chat-menu-item-danger {
    color: #c0392b;
}

.chat-menu-item-danger:hover {
    background: rgba(255, 90, 90, 0.14);
}

/* ---------- Authentication ---------- */

/* Shown on page load while resumeSession() runs; removed by showApp()/showLogin() */
#app-loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-bg-darker);
}

.app-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: app-loading-spin 0.8s linear infinite;
}

@keyframes app-loading-spin {
    to { transform: rotate(360deg); }
}

#auth-container {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
    background-color: var(--color-bg-darker);
    background-image:
        radial-gradient(circle at 15% 20%, rgba(0, 0, 0, 0.05), transparent 45%),
        radial-gradient(circle at 85% 15%, rgba(0, 0, 0, 0.04), transparent 40%),
        radial-gradient(circle at 50% 100%, rgba(0, 0, 0, 0.035), transparent 50%);
}

#auth-container::before {
    content: "";
    position: absolute;
    inset: 0;
    /* contain keeps the tall icon's shape instead of stretching it to the screen */
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.20;
    pointer-events: none;
}

#authentication-form {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    width: 100%;
    min-height: 420px;
    max-width: 550px;
    background: linear-gradient(135deg, var(--color-coffee), var(--color-coffee-alt));
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: 40px 48px;
    /* softer than the chat panels' --glow-dark */
    box-shadow: var(--shadow-card), 0 0 36px rgba(0, 0, 0, 0.25);
    animation: fade-slide-in 0.5s ease both;
}

/* White tile so the black logo shows on the black card (same idea as .logo-placeholder) */
.auth-logo {
    align-self: center;
    flex-shrink: 0;
    width: 72px;
    height: 96px;
    padding: 6px;
    border-radius: 14px;
    background: #ffffff;
    /* soft white glow so the tile lifts off the black card */
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4), 0 0 24px rgba(255, 255, 255, 0.25);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.auth-logo:hover {
    transform: rotate(-4deg) scale(1.06);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5), 0 0 32px rgba(255, 255, 255, 0.4);
}

.auth-logo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.auth-title {
    margin: 0 0 8px;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
    background: linear-gradient(90deg, #ffffff, #b3b3b3);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    /* shrink to the text so only hovering the words triggers the zoom */
    align-self: center;
    transition: transform 0.3s ease, filter 0.3s ease;
}

.auth-title:hover {
    transform: scale(1.05);
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
}

#user-email,
#user-password {
    background: var(--color-bg-darker);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    color: var(--color-cream);
    font-size: 1.05rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#user-email::placeholder,
#user-password::placeholder {
    color: var(--color-cream-dim);
}

/* white ring: these inputs sit on a black card, where a dark ring is invisible */
#user-email:focus,
#user-password:focus {
    border-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.28);
}

#LoginBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: var(--color-coffee);
    border: none;
    border-radius: var(--radius-md);
    padding: 16px 22px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

#LoginBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    background: #ececec;
}

#LoginBtn:active:not(:disabled) {
    transform: translateY(0);
    filter: brightness(0.95);
}

/* the button is only disabled while the login request runs; a light band sweeps across it */
#LoginBtn:disabled {
    position: relative;
    overflow: hidden;
    cursor: progress;
}

#LoginBtn:disabled::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(0, 0, 0, 0.12) 50%, transparent 80%);
    transform: translateX(-100%);
    animation: login-shimmer 1.2s ease-in-out infinite;
}

@keyframes login-shimmer {
    to { transform: translateX(100%); }
}

/* Coffee beans drifting up behind the login card */
.auth-beans {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.bean {
    position: absolute;
    bottom: -60px;
    left: var(--x);
    width: var(--s);
    height: calc(var(--s) * 1.35);
    border-radius: 50%;
    background: var(--color-accent);
    opacity: 0.12;
    animation: bean-drift var(--d) linear var(--delay) infinite;
}

/* the crease down the middle of the bean */
.bean::after {
    content: "";
    position: absolute;
    top: 15%;
    bottom: 15%;
    left: 40%;
    width: 30%;
    border-left: 2px solid var(--color-bg-darker);
    border-radius: 50%;
}

@keyframes bean-drift {
    from { transform: translateY(0) rotate(0deg); }
    to { transform: translateY(calc(-100vh - 120px)) rotate(var(--r)); }
}

/* Successful login: the card shrinks away, then the whole screen fades into the app */
#auth-container.auth-success {
    animation: auth-fade-out 0.4s ease 0.3s forwards;
}

#auth-container.auth-success #authentication-form {
    animation: auth-card-exit 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes auth-card-exit {
    to {
        opacity: 0;
        transform: scale(0.85) translateY(-12px);
    }
}

@keyframes auth-fade-out {
    to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-beans {
        display: none;
    }

    #LoginBtn:disabled::after {
        animation: none;
        transform: none;
        background: rgba(0, 0, 0, 0.08);
    }

    #auth-container.auth-success,
    #auth-container.auth-success #authentication-form {
        animation-duration: 0.01s;
        animation-delay: 0s;
    }
}

/* ---------- Modals ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
}

.modal-overlay.open {
    display: flex;
}

/* Sits above #auth-container (z-index: 100) so it isn't hidden behind
   the login screen when validation fails. */
#auth-error-overlay,
#auth-unauthorized-overlay {
    z-index: 150;
}

.modal-box {
    width: 100%;
    max-width: 320px;
    margin: 0 16px;
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card);
    animation: fade-slide-in 0.2s ease both;
}

.modal-title {
    margin: 0 0 12px;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    color: #121212;
}

.modal-message {
    margin: 0 0 20px;
    font-size: 0.88rem;
    color: #6b6b6b;
}

.modal-input {
    width: 100%;
    margin-bottom: 20px;
    padding: 10px 14px;
    background: #f0f0f0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: #121212;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-btn {
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

.modal-btn-secondary {
    background: transparent;
    color: #6b6b6b;
    border: 1px solid var(--color-border);
}

.modal-btn-secondary:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #121212;
}

.modal-btn-primary {
    background: var(--color-coffee);
    color: #ffffff;
}

.modal-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.modal-btn-danger {
    background: #c0392b;
    color: #fff5f2;
}

.modal-btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(192, 57, 43, 0.35);
    filter: brightness(1.05);
}

/* ---------- Decorative stickers ---------- */

.chat-header::before,
.chat-header::after,
#chatbot-form::before,
#chatbot-form::after {
    content: "";
    position: absolute;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    pointer-events: none;
    z-index: 2;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.chat-header::before {
    left: -108px;
    top: 50%;
    width: 82px;
    height: 82px;
}

.chat-header::after {
    right: -104px;
    top: 50%;
    width: 80px;
    height: 100px;
}

/* Anchored to the form (not #chat-window, which needs overflow:auto to
   scroll messages and would clip/scroll anything positioned outside it).
   Offsets are computed to land beside #chat-window's left/right edges. */
#chatbot-form::before {
    left: -118px;
    top:  -190px;
    width: 88px;
    height: 108px;
}

#chatbot-form::after {
    right: -160px;
    top: -167px;
    width: 150px;
    height: 82px;
}

@keyframes float-flower {
    0%, 100% { transform: translateY(-50%) rotate(-10deg); }
    50% { transform: translateY(-58%) rotate(-6deg); }
}

@keyframes float-cup {
    0%, 100% { transform: translateY(-50%) rotate(8deg); }
    50% { transform: translateY(-42%) rotate(12deg); }
}

@keyframes float-matcha {
    0%, 100% { transform: translateY(0) rotate(-8deg); }
    50% { transform: translateY(-8px) rotate(-4deg); }
}

@keyframes float-text {
    0%, 100% { transform: translateY(0) rotate(5deg); }
    50% { transform: translateY(-6px) rotate(8deg); }
}

/* ---------- Chat window ---------- */

#chat-window {
    position: relative;
    z-index: 1;
    grid-column: 2;
    justify-self: center;
    align-self: stretch;
    width: 100%;
    max-width: 1180px;
    height: 98%;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px 20px 60px; /* Added more bottom padding for disclaimer */
    box-shadow: var(--shadow-card);
    margin-bottom: 16px;
    animation: fade-slide-in 0.5s ease 0.08s both;

    scrollbar-width: thin;
    scrollbar-color: #c4c4c4 transparent;
}

.chat-disclaimer {
    position: absolute;
    inset: 0;
    margin: auto;
    width: fit-content;
    height: fit-content;
    max-width: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--color-accent-dark);
    text-align: center;
    pointer-events: none;
    z-index: 10;
    animation: disclaimer-float 3s ease-in-out infinite;
}

.chat-disclaimer::after {
    content: "☕";
    font-size: 1.3rem;
}

@keyframes disclaimer-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

#chat-window::-webkit-scrollbar {
    width: 8px;
}

#chat-window::-webkit-scrollbar-track {
    background: transparent;
}

#chat-window::-webkit-scrollbar-thumb {
    background: #c4c4c4;
    border-radius: 8px;
}

/* Message bubbles are told apart by their real class (.user-message /
   .bot-message), set in index.html when each <div> is appended — not by
   position, since two same-sender messages in a row would break nth-child. */
#chat-window > div {
    position: relative;
    max-width: 75%;
    padding: 11px 16px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.92rem;
    word-wrap: break-word;
    animation: message-in 0.25s ease-out;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#chat-window > div:hover {
    transform: translateY(-2px);
}

/* Black bubble for the user, light for the bot; the squared corner
   points at whichever side the message came from. */
.user-message {
    align-self: flex-end;
    background: var(--color-coffee);
    color: #ffffff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.26);
}

.user-message:hover {
    box-shadow: var(--shadow-hover), 0 0 26px rgba(0, 0, 0, 0.34);
}

.bot-message {
    align-self: flex-start;
    background: #f5f5f5;
    color: var(--color-cream);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 6px;
}

.bot-message:hover {
    box-shadow: var(--shadow-hover);
}

/* Markdown inside bot replies (rendered by marked) */
.bot-message > :first-child { margin-top: 0; }
.bot-message > :last-child { margin-bottom: 0; }

.bot-message p {
    margin: 0.5em 0;
}

.bot-message ul,
.bot-message ol {
    margin: 0.5em 0;
    padding-left: 1.3em;
}

.bot-message a {
    color: inherit;
    text-decoration: underline;
}

.bot-message table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    margin: 0.6em 0;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.bot-message th,
.bot-message td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}

.bot-message th {
    background: var(--color-coffee);
    color: #ffffff;
    font-weight: 600;
}

.bot-message code {
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.07);
    font-size: 0.85em;
}

.bot-message pre {
    margin: 0.6em 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--color-coffee);
    color: #f2f2f2;
    overflow-x: auto;
}

.bot-message pre code {
    padding: 0;
    background: none;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-cream-dim);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

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

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

/* ---------- Input form ---------- */

#chatbot-form {
    position: relative;
    z-index: 1;
    grid-column: 2;
    justify-self: center;
    width: 100%;
    max-width: 1180px;
    display: flex;
    gap: 10px;
    background: linear-gradient(135deg, var(--color-coffee), var(--color-coffee-alt));
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: var(--shadow-card), var(--glow-dark);
    animation: fade-slide-in 0.5s ease 0.16s both;
}

#user-input {
    flex: 1;
    background: var(--color-bg-darker);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--color-cream);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#user-input::placeholder {
    color: var(--color-cream-dim);
}

#user-input:focus {
    border-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.28);
}

#chatbot-form button[type="submit"] {
    display: inline-flex;
    align-items: center;
    background: #ffffff;
    color: var(--color-coffee);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 22px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

#chatbot-form button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    background: #ececec;
}

#chatbot-form button[type="submit"]:hover::after {
    transform: translateX(4px);
}

#chatbot-form button[type="submit"]:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

#chatbot-form button[type="submit"]:disabled {
    background: #3a3a3a;
    color: #8f8f8f;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#chatbot-form button[type="submit"]:disabled:hover {
    transform: none;
    box-shadow: none;
    background: #3a3a3a;
}

/* Keyboard focus ring for every button */
button:focus-visible {
    outline: 2px solid #8f8f8f;
    outline-offset: 2px;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        grid-template-columns: 1fr;
        padding: 16px;
    }

    #sidebar {
        grid-column: 1;
        grid-row: auto;
        max-height: 180px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 16px;
    }

    .chat-header,
    #chat-window,
    #chatbot-form {
        grid-column: 1;
        max-width: 100%;
    }

    #chat-window {
        height: 60vh;
    }
}

@media (max-width: 1180px) {
    .chat-header::before,
    .chat-header::after,
    #chatbot-form::before,
    #chatbot-form::after {
        display: none;
    }
}

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
