/* ==========================================================================
   Uma — Design System & Stylesheet
   Modern editorial paper + ink aesthetic with mint & coral accents
   ========================================================================== */

:root {
    --ink: #12161d;
    --ink-soft: #1a2128;
    --ink-hover: #263238;
    --ink-active: #2b383f;
    --muted: #7b8582;
    --muted-soft: #88948e;
    --muted-dark: #626e69;
    --paper: #f7f6f2;
    --paper-card: #ffffff;
    --paper-subtle: #f1efe9;
    --paper-bubble: #ffffff;
    --line: #dfe0d8;
    --line-dark: #2a353c;
    --line-focus: #72d7aa;
    --mint: #a8e8c8;
    --mint2: #72d7aa;
    --mint-soft: #e4f7eb;
    --mint-glow: rgba(114, 215, 170, 0.22);
    --coral: #ed8068;
    --coral-soft: #fdf3f0;
    --white: #ffffff;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font-main: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --font-display: "Space Grotesk", "Inter", sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
    --shadow-soft: 0 10px 25px rgba(27, 48, 39, 0.07);
    --shadow-float: 0 18px 50px rgba(22, 29, 33, 0.12);
    --shadow-modal: 0 24px 70px rgba(18, 22, 29, 0.35);
    --transition: 0.18s ease;
}

/* Dark / Dim Theme — High Contrast & Deep Obsidian */
body.dark-theme,
body.dim-preview {
    --paper: #080b0f;
    --paper-card: #11161f;
    --paper-subtle: #161e29;
    --paper-bubble: #151e2b;
    --line: #222d3d;
    --ink: #f0f6fc;
    --muted: #8b9bb0;
    --muted-soft: #a5b4c7;
    --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.55);
    --shadow-float: 0 18px 55px rgba(0, 0, 0, 0.7);
    --shadow-modal: 0 24px 80px rgba(0, 0, 0, 0.85);
}

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

html, body {
    height: 100%;
    height: 100svh;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Crucial: Prevents document window from rolling */
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.25s ease, color 0.25s ease;
}

body.modal-open {
    overflow: hidden;
}

button, input, textarea {
    font-family: inherit;
    font-size: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ==========================================================================
   Layout Shell — Pinned Viewport
   ========================================================================== */
.shell {
    height: 100%;
    height: 100svh;
    max-height: 100svh;
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr);
    overflow: hidden; /* Keeps child columns self-contained */
    position: relative;
    transition: grid-template-columns 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Sidebar — Fixed & Scrollable When Needed
   ========================================================================== */
.side {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 18px 20px;
    background: #12161d;
    color: #edf2ee;
    border-right: 1px solid #1f272e;
    height: 100%;
    height: 100svh;
    max-height: 100svh;
    box-sizing: border-box;
    overflow-y: auto; /* Entire sidebar scrolls if window height is very small */
    overflow-x: hidden;
    z-index: 10;
    transition: width 0.24s ease, padding 0.24s ease, opacity 0.2s ease;
}

.side::-webkit-scrollbar {
    width: 5px;
}
.side::-webkit-scrollbar-thumb {
    background: #27343b;
    border-radius: 999px;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    position: fixed;
    top: 22px;
    left: 272px;
    z-index: 25;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid #354049;
    border-radius: 10px;
    color: #b9c7bf;
    background: #1d252b;
    font-size: 1.15rem;
    font-weight: 600;
    transition: all 0.2s ease;
    user-select: none;
}

.sidebar-toggle:hover {
    color: #12161d;
    background: var(--mint);
    border-color: var(--mint);
    transform: translateX(-1px);
}

/* Collapsed Sidebar State */
.shell.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

.sidebar-collapsed .side {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.sidebar-collapsed .sidebar-toggle {
    left: 18px;
    border-color: var(--line);
    color: #5f6d67;
    background: var(--paper-card);
    box-shadow: 0 8px 22px rgba(23, 37, 29, 0.14);
}

.sidebar-collapsed .sidebar-toggle:hover {
    background: var(--mint2);
    color: #12161d;
    border-color: var(--mint2);
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 6px;
    flex-shrink: 0;
}

.logo {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 13px 13px 13px 4px;
    background: var(--mint);
    color: #12161d;
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--mint-glow);
}

.brand strong {
    display: block;
    font-family: var(--font-display);
    font-size: 1.08rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: #82918a;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
}

.beta {
    margin-left: auto;
    border: 1px solid #344049;
    border-radius: 6px;
    padding: 4px 7px;
    color: var(--mint2);
    background: rgba(114, 215, 170, 0.08);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.12em;
}

/* New Chat Button */
.new {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #38434d;
    border-radius: 12px;
    color: #f5f8f5;
    background: rgba(255, 255, 255, 0.03);
    font-weight: 600;
    font-size: 0.88rem;
    flex-shrink: 0;
    transition: var(--transition);
}

.new:hover {
    border-color: var(--mint2);
    background: #20292e;
    color: #ffffff;
    transform: translateY(-1px);
}

.plus {
    color: var(--mint);
    font-size: 1.15rem;
    line-height: 1;
}

.shortcut {
    margin-left: auto;
    color: #809087;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
}

/* Recent Chats Section — Scrollable Chat History */
.history-section {
    flex: 1 1 0; /* Expands to fill available sidebar space */
    min-height: 120px;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevents overflow outside section */
}

.section-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 6px 8px;
    flex-shrink: 0;
}

.label {
    margin: 0;
    color: #84918a;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.text-button {
    border: none;
    background: transparent;
    color: #728078;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
}

.text-button:hover {
    color: var(--coral);
    background: rgba(237, 128, 104, 0.12);
}

/* Inner scrollable history container */
.history {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-right: 4px;
}

.history::-webkit-scrollbar {
    width: 4px;
}
.history::-webkit-scrollbar-thumb {
    background: #29343a;
    border-radius: 4px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 0;
    border-radius: 9px;
    padding: 9px 11px;
    color: #b8c4bd;
    background: transparent;
    text-align: left;
    font-size: 0.82rem;
    flex-shrink: 0;
    transition: var(--transition);
    position: relative;
}

.chat-item span.item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item:hover {
    color: #fff;
    background: #273238;
}

.chat-item.active {
    color: #fff;
    background: #273238;
    box-shadow: inset 3px 0 var(--mint);
    font-weight: 600;
}

.chat-item .arrow {
    margin-left: auto;
    color: #68766f;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: var(--transition);
}

.chat-item:hover .arrow,
.chat-item.active .arrow {
    opacity: 1;
    color: var(--mint);
}

.empty-history {
    color: #68766f;
    font-size: 0.76rem;
    padding: 8px 10px;
    margin: 0;
}

/* Quick Prompts Section */
.prompts {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.prompt {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 0;
    border-radius: 9px;
    padding: 8px 11px;
    color: #b8c4bd;
    background: transparent;
    text-align: left;
    font-size: 0.82rem;
    transition: var(--transition);
}

.prompt:hover {
    color: #fff;
    background: #273238;
}

.prompt-icon {
    display: grid;
    place-items: center;
    width: 23px;
    height: 23px;
    border-radius: 7px;
    color: var(--mint);
    background: #263436;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.prompt .prompt-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prompt .arrow {
    margin-left: auto;
    color: #68766f;
    font-size: 0.75rem;
}

.prompt:hover .arrow {
    color: var(--mint);
}

/* Sidebar Account & User Profile */
.sidebar-account {
    margin-top: auto;
    border-top: 1px solid #29343a;
    padding-top: 14px;
    flex-shrink: 0;
}

.auth-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 1px solid #313d46;
    border-radius: 10px;
    padding: 10px 12px;
    color: #e0ece5;
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.82rem;
    font-weight: 600;
    transition: var(--transition);
}

.auth-btn:hover {
    color: #ffffff;
    background: #232c32;
    border-color: var(--mint2);
    transform: translateY(-1px);
}

.auth-btn .auth-icon {
    font-size: 0.95rem;
    line-height: 1;
}

.auth-btn .arrow {
    margin-left: auto;
    color: #68766f;
    font-size: 0.75rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #29343a;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
}

.user-avatar {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--mint);
    color: #12161d;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-info strong {
    display: block;
    font-size: 0.82rem;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info small {
    display: block;
    font-size: 0.68rem;
    color: #82918a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    border: none;
    background: transparent;
    color: #7b8882;
    font-size: 1.1rem;
    padding: 4px;
    line-height: 1;
    border-radius: 6px;
    transition: var(--transition);
}

.logout-btn:hover {
    color: var(--coral);
    background: rgba(237, 128, 104, 0.12);
}

/* Sidebar Footer */
.side-foot {
    border-top: 1px solid #29343a;
    padding-top: 12px;
    color: #718078;
    font-size: 0.68rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.foot-note {
    padding: 0 4px;
    color: #718078;
    font-size: 0.68rem;
}

.about {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 1px solid #283339;
    border-radius: 9px;
    padding: 9px 11px;
    color: #bbc6bf;
    background: rgba(255, 255, 255, 0.02);
    text-align: left;
    font-size: 0.82rem;
    transition: var(--transition);
}

.about:hover {
    color: #fff;
    background: #273238;
    border-color: #38464f;
}

.about .arrow {
    margin-left: auto;
    color: #68766f;
}

/* ==========================================================================
   Main Chat Workspace — Pinned Header & Composer, Scrollable Messages
   ========================================================================== */
.main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    height: 100svh;
    max-height: 100svh;
    min-width: 0;
    overflow: hidden; /* Crucial: Main DOES NOT scroll */
    background: var(--paper);
    position: relative;
    transition: background 0.25s ease;
}

/* Header Top — Pinned */
.top {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px clamp(24px, 5.5vw, 80px);
    border-bottom: 1px solid var(--line);
    background: var(--paper);
    z-index: 5;
    transition: border-color 0.25s ease, background 0.25s ease;
}

.eyebrow {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 7px;
}

.online {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mint2);
    box-shadow: 0 0 0 3px var(--mint-glow);
    animation: pulseStatus 2.2s infinite;
}

.online.offline {
    background: var(--coral);
    box-shadow: 0 0 0 3px rgba(237, 128, 104, 0.25);
    animation: none;
}

@keyframes pulseStatus {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.75;
    }
}

.top h1 {
    margin: 4px 0 0;
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--ink);
}

.coral-spark {
    color: var(--coral);
    font-style: normal;
}

.top p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.83rem;
}

.stream {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 500;
    background: var(--paper-card);
    border: 1px solid rgba(92, 225, 166, 0.4);
    padding: 5px 12px;
    border-radius: 999px;
    transition: all 0.25s ease;
    user-select: none;
    box-shadow: 0 0 10px rgba(92, 225, 166, 0.16), inset 0 0 6px rgba(92, 225, 166, 0.06);
    animation: streamAmbientGlow 3s infinite ease-in-out;
}

@keyframes streamAmbientGlow {
    0%, 100% {
        border-color: rgba(92, 225, 166, 0.35);
        box-shadow: 0 0 8px rgba(92, 225, 166, 0.15), inset 0 0 4px rgba(92, 225, 166, 0.05);
    }
    50% {
        border-color: rgba(92, 225, 166, 0.65);
        box-shadow: 0 0 16px rgba(92, 225, 166, 0.35), inset 0 0 8px rgba(92, 225, 166, 0.12);
    }
}

.stream-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mint, #5ce1a6);
    box-shadow: 0 0 6px var(--mint, #5ce1a6);
    transition: background 0.2s ease;
}

.stream-wave {
    display: inline-flex;
    align-items: flex-end;
    gap: 2.5px;
    height: 13px;
}

.stream-wave span {
    display: inline-block;
    width: 2.5px;
    height: 4px;
    border-radius: 2px;
    background: rgba(92, 225, 166, 0.7);
    transition: all 0.2s ease;
}

/* Active State When Streaming Responses (Radiant Accent Glow) */
.stream.active {
    border-color: var(--mint, #5ce1a6);
    background: rgba(92, 225, 166, 0.15);
    color: var(--ink);
    box-shadow: 0 0 18px rgba(92, 225, 166, 0.5), 0 0 35px rgba(92, 225, 166, 0.25), inset 0 0 8px rgba(92, 225, 166, 0.2);
    animation: none;
}

.stream.active .stream-dot {
    background: var(--mint, #5ce1a6);
    box-shadow: 0 0 10px var(--mint, #5ce1a6);
    animation: streamDotPulse 1.2s infinite ease-in-out;
}

.stream.active .stream-wave span {
    background: var(--mint, #5ce1a6);
    box-shadow: 0 0 6px var(--mint, #5ce1a6);
    animation: streamWaveBar 0.9s infinite ease-in-out alternate;
}

.stream.active .stream-wave span:nth-child(1) {
    animation-delay: 0.0s;
    height: 6px;
}
.stream.active .stream-wave span:nth-child(2) {
    animation-delay: 0.2s;
    height: 13px;
}
.stream.active .stream-wave span:nth-child(3) {
    animation-delay: 0.4s;
    height: 9px;
}
.stream.active .stream-wave span:nth-child(4) {
    animation-delay: 0.15s;
    height: 11px;
}

@keyframes streamWaveBar {
    0% {
        transform: scaleY(0.25);
    }
    50% {
        transform: scaleY(1);
    }
    100% {
        transform: scaleY(0.4);
    }
}

@keyframes streamDotPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.85);
    }
}

/* ==========================================================================
   Messages Area — THIS IS THE ONLY PART THAT ROLLS IN CHAT
   ========================================================================== */
.messages {
    flex: 1 1 0;
    min-height: 0; /* Crucial so overflow works properly in grid */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px clamp(20px, 8vw, 130px) 24px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
    width: 6px;
}
.messages::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 999px;
}

/* Welcome View */
.welcome {
    width: min(760px, 100%);
    margin: 4vh auto auto;
    padding: 0 4px;
}

.welcome-kicker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.welcome-kicker span {
    color: var(--coral);
    font-size: 1rem;
}

.welcome h2 {
    max-width: 620px;
    margin: 16px 0 12px;
    font-family: var(--font-display);
    font-size: clamp(2.3rem, 4.8vw, 4.4rem);
    font-weight: 700;
    letter-spacing: -0.07em;
    line-height: 1.02;
    color: var(--ink);
}

.welcome h2 em {
    color: var(--coral);
    font-style: normal;
}

.welcome p {
    max-width: 490px;
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.65;
}

/* Prompt Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 36px;
}

.card {
    min-height: 112px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--paper-card);
    text-align: left;
    transition: var(--transition);
    color: var(--ink);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.card:hover {
    border-color: var(--mint2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

.card i {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-bottom: 14px;
    border-radius: 9px;
    color: #24815a;
    background: var(--mint-soft);
    font-style: normal;
    font-size: 0.85rem;
    font-weight: 700;
}

body.dark-theme .card i,
body.dim-preview .card i {
    background: rgba(114, 215, 170, 0.16);
    color: var(--mint2);
}

.card strong {
    display: block;
    font-size: 0.84rem;
    font-weight: 650;
}

.card small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

/* Messages Flow */
.messages-flow {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    margin: 0 auto;
}

/* Message Rows */
.user-message,
.uma-message {
    display: flex;
    width: min(760px, 100%);
    margin: 0 auto 22px;
    gap: 14px;
    align-items: flex-start;
    animation: messageFadeIn 0.22s ease-out;
}

@keyframes messageFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 11px 11px 11px 3px;
    background: var(--mint);
    color: #12161d;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-display);
    box-shadow: 0 4px 10px var(--mint-glow);
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .avatar {
    border-radius: 50%;
    color: #fff;
    background: #12161d;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

body.dark-theme .user-message .avatar,
body.dim-preview .user-message .avatar {
    background: #2b3640;
    color: #edf2ee;
}

.bubble {
    flex: 1;
    min-width: 0;
    padding: 3px 0;
    line-height: 1.7;
    color: var(--ink);
    font-size: 0.94rem;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: pre-line;
}

.user-bubble-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: min(640px, calc(100% - 46px));
    min-width: fit-content;
    position: relative;
}

.user-message .bubble {
    width: fit-content;
    min-width: 54px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 18px 5px 18px 18px;
    background: var(--paper-bubble);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.03);
    color: var(--ink);
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
}

.user-msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.user-message:hover .user-msg-actions,
.user-message:focus-within .user-msg-actions {
    opacity: 1;
}

@media (max-width: 768px) {
    .user-msg-actions {
        opacity: 0.8;
    }
}

.msg-action-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

.uma-message:hover .msg-action-bar,
.uma-message:focus-within .msg-action-bar {
    opacity: 1;
}

.msg-action-btn,
.edit-msg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper-card);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.msg-action-btn:hover,
.edit-msg-btn:hover {
    color: var(--ink);
    border-color: var(--mint2);
    background: var(--paper-subtle);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Icon only by default - smoothly reveal label on hover */
.edit-msg-btn .edit-label,
.msg-action-btn .copy-label {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.22s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.18s ease, margin 0.18s ease;
    margin-left: 0;
    pointer-events: none;
}

.edit-msg-btn:hover .edit-label,
.msg-action-btn:hover .copy-label {
    max-width: 80px;
    opacity: 1;
    margin-left: 5px;
}

.msg-action-btn.copied {
    border-color: var(--mint);
    color: var(--mint);
}

.msg-action-btn.copied .copy-label {
    max-width: 80px;
    opacity: 1;
    margin-left: 5px;
}

.user-edit-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: min(480px, 85vw);
    padding: 10px;
    border-radius: 14px;
    background: var(--paper-card);
    border: 1px solid var(--mint2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.user-edit-textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

.user-edit-textarea:focus {
    border-color: var(--mint);
}

.user-edit-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.user-edit-cancel {
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.user-edit-cancel:hover {
    color: var(--ink);
    background: rgba(0, 0, 0, 0.04);
}

.user-edit-save {
    padding: 5px 14px;
    border-radius: 8px;
    border: none;
    background: var(--mint);
    color: #12161d;
    font-size: 0.78rem;
    font-weight: 650;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--mint-glow);
    transition: var(--transition);
}

.user-edit-save:hover {
    background: var(--mint2);
}

/* Guest Mode Pill Badge */
.guest-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 14px;
    background: rgba(235, 107, 86, 0.1);
    border: 1px solid rgba(235, 107, 86, 0.28);
    color: #d94e34;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.guest-pill:hover {
    background: rgba(235, 107, 86, 0.16);
    transform: translateY(-1px);
}

.guest-pill[hidden],
.guest-pill.hidden,
.guest-pill[style*="display: none"],
body.user-logged-in .guest-pill,
body.user-logged-in #guestCounterBadge {
    display: none !important;
}

.uma-message .bubble {
    white-space: normal;
}

/* GitHub-Style Code Cards & Syntax Highlighting */
.code-card {
    margin: 16px 0;
    border-radius: 12px;
    background: #0d1117;
    border: 1px solid #30363d;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    font-family: var(--font-mono);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #161b22;
    border-bottom: 1px solid #21262d;
    color: #8b949e;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    user-select: none;
}

.code-lang {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    color: #c9d1d9;
    font-family: var(--font-mono);
}

.code-lang svg {
    color: var(--mint, #5ce1a6);
}

.copy-code-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #c9d1d9;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.15s ease;
}

.copy-code-btn:hover {
    background: #30363d;
    color: #ffffff;
    border-color: #8b949e;
}

.copy-code-btn.copied {
    background: #238636;
    border-color: #2ea043;
    color: #ffffff;
}

.code-pre {
    margin: 0;
    padding: 16px 18px;
    background: #0d1117;
    color: #e6edf3;
    overflow-x: auto;
    font-size: 0.88rem;
    line-height: 1.55;
    tab-size: 4;
    white-space: pre;
    font-family: var(--font-mono);
}

.code-body {
    font-family: var(--font-mono);
    font-size: inherit;
}

/* Syntax Highlighting Tokens (GitHub Dark Theme) */
.token-comment {
    color: #8b949e;
    font-style: italic;
}

.token-string {
    color: #7ee787; /* Green */
}

.token-keyword {
    color: #ff7b72; /* Pink / Coral */
    font-weight: 600;
}

.token-type {
    color: #79c0ff; /* Light Blue / Cyan */
    font-weight: 550;
}

.token-number {
    color: #d2a8ff; /* Lavender / Purple */
}

.token-fn {
    color: #5ce1a6; /* Mint / Green */
}

/* Inline Code Badge */
.inline-code {
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(175, 184, 193, 0.2);
    color: #d1515a;
    font-family: var(--font-mono);
    font-size: 0.86em;
    font-weight: 550;
    border: 1px solid rgba(175, 184, 193, 0.28);
}

body.dark-theme .inline-code {
    background: rgba(110, 118, 129, 0.22);
    color: #ff7b72;
    border-color: rgba(110, 118, 129, 0.35);
}

.bubble p {
    margin: 0 0 14px 0;
    line-height: 1.68;
    letter-spacing: -0.011em;
}

.bubble p:last-child {
    margin-bottom: 0;
}

/* Headings with clear visual hierarchy */
.md-h1, .md-h2, .md-h3, .md-h4, .md-h5, .md-h6 {
    color: var(--ink);
    font-family: var(--font-main);
    letter-spacing: -0.02em;
    margin-top: 1.5em;
    margin-bottom: 0.6em;
    line-height: 1.35;
}

.md-h1 {
    font-size: 1.36rem;
    font-weight: 700;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
}

.md-h2 {
    font-size: 1.22rem;
    font-weight: 700;
}

.md-h3 {
    font-size: 1.1rem;
    font-weight: 650;
}

.md-h4 {
    font-size: 1.0rem;
    font-weight: 600;
}

.md-h5, .md-h6 {
    font-size: 0.92rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

/* Unordered & Ordered Lists */
.md-ul, .md-ol {
    margin: 10px 0 16px 0;
    padding-left: 22px;
}

.md-ul {
    list-style-type: disc;
}

.md-ol {
    list-style-type: decimal;
}

.md-li, .md-uli, .md-oli {
    margin-bottom: 6px;
    line-height: 1.65;
    padding-left: 4px;
}

.md-ul .md-ul,
.md-ol .md-ol,
.md-ul .md-ol,
.md-ol .md-ul {
    margin: 4px 0 6px 0;
    padding-left: 18px;
}

/* Tables (Responsive & High-Contrast) */
.table-wrapper {
    width: 100%;
    margin: 16px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--paper-card);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    line-height: 1.5;
    text-align: left;
}

.md-table th {
    background: var(--paper-subtle);
    font-weight: 650;
    color: var(--ink);
    padding: 10px 14px;
    border-bottom: 2px solid var(--line);
    white-space: nowrap;
}

.md-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    vertical-align: top;
}

.md-table tr:last-child td {
    border-bottom: none;
}

.md-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.015);
}

body.dark-theme .md-table tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

body.dark-theme .table-wrapper {
    background: #0f141c;
    border-color: #222d3d;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

body.dark-theme .md-table th {
    background: #161e29;
    border-bottom-color: #2a3749;
    color: #f0f6fc;
}

body.dark-theme .md-table td {
    border-bottom-color: #1f2a38;
    color: #e6edf3;
}

/* Callouts / Notes / Tips / Warnings / Alerts */
.md-callout {
    margin: 16px 0;
    padding: 14px 18px;
    border-radius: 10px;
    border-left: 4px solid;
    font-size: 0.94rem;
    line-height: 1.6;
}

.md-callout-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
    margin-bottom: 6px;
    font-size: 0.88rem;
    letter-spacing: 0.01em;
}

.md-callout-body p {
    margin: 0;
    line-height: 1.6;
}

.md-callout-body p + p {
    margin-top: 8px;
}

/* Note / Info (Blue) */
.md-callout-note {
    background: rgba(9, 105, 218, 0.08);
    border-left-color: #0969da;
    color: var(--ink);
}
.md-callout-note .md-callout-header {
    color: #0969da;
}
body.dark-theme .md-callout-note {
    background: rgba(56, 139, 253, 0.12);
    border-left-color: #58a6ff;
    color: #e6edf3;
}
body.dark-theme .md-callout-note .md-callout-header {
    color: #58a6ff;
}

/* Tip (Mint / Green) */
.md-callout-tip {
    background: rgba(26, 127, 55, 0.08);
    border-left-color: #1a7f37;
    color: var(--ink);
}
.md-callout-tip .md-callout-header {
    color: #1a7f37;
}
body.dark-theme .md-callout-tip {
    background: rgba(46, 160, 67, 0.12);
    border-left-color: var(--mint2, #72d7aa);
    color: #e6edf3;
}
body.dark-theme .md-callout-tip .md-callout-header {
    color: var(--mint2, #72d7aa);
}

/* Important (Purple) */
.md-callout-important {
    background: rgba(130, 80, 223, 0.08);
    border-left-color: #8250df;
    color: var(--ink);
}
.md-callout-important .md-callout-header {
    color: #8250df;
}
body.dark-theme .md-callout-important {
    background: rgba(163, 113, 247, 0.12);
    border-left-color: #bc8cff;
    color: #e6edf3;
}
body.dark-theme .md-callout-important .md-callout-header {
    color: #bc8cff;
}

/* Warning (Amber / Gold) */
.md-callout-warning {
    background: rgba(154, 103, 0, 0.08);
    border-left-color: #9a6700;
    color: var(--ink);
}
.md-callout-warning .md-callout-header {
    color: #9a6700;
}
body.dark-theme .md-callout-warning {
    background: rgba(187, 128, 9, 0.12);
    border-left-color: #d29922;
    color: #e6edf3;
}
body.dark-theme .md-callout-warning .md-callout-header {
    color: #d29922;
}

/* Caution (Coral / Red) */
.md-callout-caution {
    background: rgba(207, 34, 46, 0.08);
    border-left-color: #cf222e;
    color: var(--ink);
}
.md-callout-caution .md-callout-header {
    color: #cf222e;
}
body.dark-theme .md-callout-caution {
    background: rgba(248, 81, 73, 0.12);
    border-left-color: #f85149;
    color: #e6edf3;
}
body.dark-theme .md-callout-caution .md-callout-header {
    color: #f85149;
}

/* Blockquotes */
.md-blockquote {
    margin: 14px 0;
    padding: 10px 16px;
    border-left: 4px solid var(--mint2, #72d7aa);
    background: var(--paper-subtle);
    border-radius: 0 8px 8px 0;
    color: var(--ink-soft);
    font-style: normal;
}

.md-blockquote p {
    margin: 0;
    line-height: 1.6;
}

body.dark-theme .md-blockquote {
    background: rgba(255, 255, 255, 0.035);
    border-left-color: var(--mint, #5ce1a6);
    color: #c9d1d9;
}

/* Markdown Links */
.md-link {
    color: #0969da;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.15s ease;
    font-weight: 500;
}

.md-link:hover {
    color: #0550ae;
}

body.dark-theme .md-link {
    color: #58a6ff;
}

body.dark-theme .md-link:hover {
    color: #79c0ff;
}

/* Horizontal Dividers */
.md-hr {
    border: none;
    height: 1px;
    background: var(--line);
    margin: 22px 0;
}

body.dark-theme .md-hr {
    background: #2a353c;
}

/* ==========================================================================
   Image Generation Card & Constellation Loader (Image 3)
   ========================================================================== */
.image-creating-card {
    width: min(360px, 100%);
    aspect-ratio: 1 / 1;
    border-radius: 20px;
    background: #242729;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 22px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    user-select: none;
    margin: 12px 0;
    animation: fadeInCard 0.25s ease;
}

@keyframes fadeInCard {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.image-creating-title {
    font-size: 0.96rem;
    font-weight: 500;
    color: #cfd6dd;
    letter-spacing: -0.01em;
}

.image-creating-graphic {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.image-creating-dots {
    display: block;
    overflow: visible;
}

.matrix-dot {
    animation: dotPulse 2.2s infinite ease-in-out var(--delay, 0s);
    transform-box: fill-box;
    transform-origin: center;
}

@keyframes dotPulse {
    0%, 100% {
        opacity: 0.18;
        transform: scale(0.65);
    }
    50% {
        opacity: 0.95;
        transform: scale(1.18);
    }
}

/* ==========================================================================
   Generated Chat Image Card (Minimal, Clean UI)
   ========================================================================== */
.chat-image-card {
    margin: 14px 0;
    max-width: 580px;
    width: 100%;
    border-radius: 14px;
    overflow: hidden;
    background: var(--paper-card);
    border: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-image-card:hover {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}

.chat-image-link {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.06);
    width: 100%;
    min-height: 260px;
    cursor: pointer;
}

.chat-image-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.02) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.02) 75%);
    background-size: 200% 100%;
    animation: imageShimmer 1.4s infinite ease-in-out;
    z-index: 1;
}

@keyframes imageShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.chat-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 520px;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.35s ease, transform 0.3s ease;
}

.chat-image.loaded {
    opacity: 1;
}

.chat-image-link:hover .chat-image {
    transform: scale(1.015);
}

.chat-image-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--paper-subtle);
    border-top: 1px solid var(--line);
}

.chat-image-caption {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55%;
}

.chat-image-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.image-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: var(--paper-card);
    color: var(--ink);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.image-action-btn:hover {
    border-color: var(--mint2);
    color: var(--mint2);
    background: var(--mint-soft);
}

.image-action-btn.active {
    background: var(--mint-soft);
    color: #24815a;
    border-color: var(--mint2);
}

body.dark-theme .image-action-btn.active {
    color: var(--mint2);
}

/* ==========================================================================
   Mathematics Solution Card (GitHub/Code card style)
   ========================================================================== */
.math-card {
    margin: 14px 0;
    border-radius: 12px;
    background: #0d1117;
    color: #e6edf3;
    border: 1px solid #30363d;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    overflow: hidden;
}

.math-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    background: #161b22;
    border-bottom: 1px solid #21262d;
    font-size: 0.75rem;
    font-weight: 600;
    color: #8b949e;
}

.math-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #5ce1a6;
}

.copy-math-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border: 1px solid #30363d;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: #c9d1d9;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.copy-math-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #8b949e;
    color: #fff;
}

.copy-math-btn.copied {
    background: rgba(92, 225, 166, 0.2);
    border-color: #5ce1a6;
    color: #5ce1a6;
}

.math-body {
    padding: 16px 14px;
    overflow-x: auto;
    text-align: center;
    font-size: 1.1rem;
    line-height: 1.6;
}

.katex-display {
    margin: 0 !important;
}

.md-hr {
    border: 0;
    height: 1px;
    background: var(--line);
    margin: 16px 0;
}

.math-fallback {
    display: block;
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

/* ==========================================================================
   Smart Copy Response Button & Message Action Bar
   ========================================================================== */
.uma-bubble-container {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

@media (max-width: 768px) {
    .uma-bubble-container {
        max-width: 88%;
    }
}

.msg-action-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    padding-left: 2px;
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--paper-card);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.msg-action-btn:hover {
    color: var(--ink);
    border-color: var(--mint2);
    background: var(--mint-soft);
}

.msg-action-btn.copied {
    color: #24815a;
    border-color: var(--mint2);
    background: var(--mint-soft);
}

body.dark-theme .msg-action-btn.copied {
    color: var(--mint2);
}

.msg-action-btn.liked {
    color: var(--mint2);
    border-color: var(--mint2);
}

/* Typing Indicator */
.typing {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    padding: 6px 2px;
}

.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mint2);
    animation: typingBounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.typing span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1.15);
        opacity: 1;
    }
}

/* Code block / pre styling inside bubbles */
.bubble code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 5px;
    border-radius: 5px;
}

body.dark-theme .bubble code,
body.dim-preview .bubble code {
    background: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Composer — Pinned at bottom of viewport
   ========================================================================== */
.composer {
    flex-shrink: 0;
    width: min(820px, calc(100% - 40px));
    margin: 0 auto;
    padding: 8px 0 20px;
    background: transparent;
}

.hint {
    display: flex;
    justify-content: space-between;
    padding: 0 6px 8px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 500;
}

.form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: flex-end;
}

.input {
    display: flex;
    align-items: flex-end;
    min-height: 58px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--paper-card);
    box-shadow: var(--shadow-float);
    transition: var(--transition);
}

.input:focus-within {
    border-color: var(--mint2);
    box-shadow: 0 0 0 4px var(--mint-glow), var(--shadow-float);
}

.input > .spark {
    padding: 4px 10px 0 0;
    color: var(--coral);
    font-size: 1rem;
    line-height: 1;
    user-select: none;
}

textarea {
    width: 100%;
    min-height: 36px;
    max-height: 140px;
    resize: none;
    border: 0;
    outline: 0;
    background: none;
    color: var(--ink);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 6px 0;
}

textarea::placeholder {
    color: var(--muted);
}

.attach {
    border: 0;
    color: var(--muted);
    background: none;
    font-size: 1.05rem;
    padding: 4px 6px;
    line-height: 1;
    border-radius: 6px;
    transition: var(--transition);
    opacity: 0.7;
}

.attach:hover {
    color: var(--coral);
    opacity: 1;
    background: rgba(237, 128, 104, 0.1);
}

.send {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 58px;
    padding: 0 20px;
    border: 0;
    border-radius: 17px;
    background: var(--mint);
    color: #12161d;
    font-weight: 700;
    font-size: 0.92rem;
    box-shadow: 0 10px 22px var(--mint-glow);
    transition: var(--transition);
    user-select: none;
}

.send b {
    font-size: 0.9rem;
    line-height: 1;
    transition: transform 0.18s ease;
}

.send:hover {
    background: var(--mint2);
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(114, 215, 170, 0.4);
}

.send:hover b {
    transform: translateX(2px) translateY(-2px);
}

.send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.send.stop-mode {
    background: #e05252 !important;
    color: #ffffff !important;
    box-shadow: 0 8px 20px rgba(224, 82, 82, 0.35) !important;
    cursor: pointer !important;
    opacity: 1 !important;
}

.send.stop-mode:hover {
    background: #c93b3b !important;
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(224, 82, 82, 0.45) !important;
}

.send.stop-mode b {
    display: none;
}

/* Top Header Actions (Stream + Theme button) */
.top-right-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-theme-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--paper-card);
    color: var(--ink);
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transition: var(--transition);
}

.header-theme-btn:hover {
    border-color: var(--mint2);
    color: var(--mint2);
    background: var(--mint-soft);
    transform: rotate(15deg);
}

/* ==========================================================================
   Quick Hover Toolbar
   ========================================================================== */
.hover-toolbar {
    position: fixed;
    top: 50%;
    right: 20px;
    z-index: 15;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 15px 40px rgba(23, 37, 29, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transform: translateY(-50%);
    transition: var(--transition);
}

.fab-toggle-btn {
    display: none;
}

.toolbar-items {
    display: grid;
    gap: 6px;
}

.tool-label {
    display: none;
}

body.dark-theme .hover-toolbar,
body.dim-preview .hover-toolbar {
    background: rgba(22, 28, 34, 0.88);
    border-color: #2b3842;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}

.tool {
    position: relative;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    color: #74817b;
    background: transparent;
    font-size: 1rem;
    transition: var(--transition);
}

.tool:hover,
.tool:focus-visible {
    color: #12161d;
    background: var(--mint-soft);
    outline: none;
    transform: translateX(-2px);
}

body.dark-theme .tool:hover,
body.dim-preview .tool:hover {
    color: var(--mint);
    background: rgba(114, 215, 170, 0.15);
}

.tool::after {
    content: attr(aria-label);
    position: absolute;
    right: 48px;
    top: 50%;
    padding: 6px 9px;
    border-radius: 7px;
    color: #fff;
    background: #12161d;
    font-size: 0.68rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(6px);
    transition: 0.16s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tool:hover::after,
.tool:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.tool-divider {
    height: 1px;
    margin: 2px 4px;
    background: var(--line);
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast {
    position: fixed;
    right: 22px;
    bottom: 24px;
    z-index: 50;
    display: none;
    padding: 11px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper-card);
    box-shadow: 0 14px 35px rgba(22, 34, 27, 0.15);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 600;
    animation: toastPop 0.22s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes toastPop {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   About Modal
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(18, 22, 29, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.about-modal {
    width: min(580px, calc(100vw - 32px));
    max-height: min(780px, calc(100svh - 36px));
    position: fixed;
    inset: 50% auto auto 50%;
    z-index: 110;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper-card);
    color: var(--ink);
    box-shadow: var(--shadow-modal);
    transform: translate(-50%, -50%);
    animation: modalIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translate(-50%, -46%) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.modal-close {
    width: 36px;
    height: 36px;
    position: sticky;
    top: 14px;
    left: calc(100% - 50px);
    z-index: 2;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper-card);
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    transition: var(--transition);
}

.modal-close:hover {
    border-color: var(--coral);
    color: var(--coral);
    background: var(--coral-soft);
}

.modal-brand {
    display: grid;
    justify-items: center;
    padding: 10px 28px 22px;
    text-align: center;
}

.modal-brand .logo {
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    margin-bottom: 12px;
}

.modal-brand h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.modal-brand p {
    max-width: 26rem;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.about-content {
    padding: 0 28px 32px;
}

.about-content section {
    border-top: 1px solid var(--line);
    padding: 18px 0;
}

.about-content h3 {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.about-content p {
    margin: 0 0 10px;
    color: var(--ink);
    font-size: 0.92rem;
    line-height: 1.68;
}

.about-content p:last-child {
    margin-bottom: 0;
}

.about-content a {
    color: #24815a;
    font-weight: 600;
}

body.dark-theme .about-content a,
body.dim-preview .about-content a {
    color: var(--mint2);
}

.about-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.about-links a {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 7px 13px;
    background: var(--paper-subtle);
    color: var(--ink);
    font-size: 0.82rem;
    transition: var(--transition);
}

.about-links a:hover {
    border-color: var(--mint2);
    color: #12161d;
    background: var(--mint);
}

/* ==========================================================================
   Auth Modal (Sign In / Sign Up)
   ========================================================================== */
.auth-modal {
    width: min(460px, calc(100vw - 32px));
    max-height: min(780px, calc(100svh - 36px));
    position: fixed;
    inset: 50% auto auto 50%;
    z-index: 110;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper-card);
    color: var(--ink);
    box-shadow: var(--shadow-modal);
    transform: translate(-50%, -50%);
    animation: modalIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    margin: 0 28px 18px;
    border-radius: 12px;
    background: var(--paper-subtle);
    border: 1px solid var(--line);
}

.auth-tab {
    flex: 1;
    text-align: center;
    padding: 8px 12px;
    border: none;
    border-radius: 9px;
    background: transparent;
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--muted);
    transition: var(--transition);
}

.auth-tab:hover {
    color: var(--ink);
}

.auth-tab.active {
    background: var(--paper-card);
    color: var(--ink);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.auth-alert {
    margin: 0 28px 14px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.4;
}

.auth-alert.error {
    background: rgba(237, 128, 104, 0.12);
    border: 1px solid var(--coral);
    color: var(--coral);
}

.auth-alert.success {
    background: rgba(114, 215, 170, 0.15);
    border: 1px solid var(--mint2);
    color: #24815a;
}

body.dark-theme .auth-alert.success,
body.dim-preview .auth-alert.success {
    color: var(--mint2);
}

.auth-form {
    padding: 0 28px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.form-group input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--paper-subtle);
    color: var(--ink);
    font-size: 0.92rem;
    transition: var(--transition);
}

.form-group input:focus {
    border-color: var(--mint2);
    background: var(--paper-card);
    box-shadow: 0 0 0 3px var(--mint-glow);
    outline: none;
}

.auth-submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    margin-top: 6px;
    border: none;
    border-radius: 12px;
    background: var(--mint);
    color: #12161d;
    font-weight: 700;
    font-size: 0.92rem;
    box-shadow: 0 8px 20px var(--mint-glow);
    transition: var(--transition);
}

.auth-submit-btn:hover {
    background: var(--mint2);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(114, 215, 170, 0.38);
}

.auth-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.auth-switch-text {
    text-align: center;
    padding: 0 28px 28px;
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.auth-switch-text button {
    border: none;
    background: transparent;
    color: var(--coral);
    font-weight: 600;
    padding: 0 2px;
    text-decoration: underline;
    cursor: pointer;
}

/* ==========================================================================
   Guest Limit Modal (Symmetrical Uniform Padding)
   ========================================================================== */
.guest-limit-modal {
    padding: 28px !important;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-sizing: border-box;
    max-width: 440px;
    width: min(440px, calc(100vw - 36px));
}

.guest-limit-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 !important;
    margin: 0 !important;
}

.guest-limit-modal .modal-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
}

.guest-limit-modal .close-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper-subtle);
    color: var(--muted);
    font-size: 0.95rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: var(--transition);
}

.guest-limit-modal .close-btn:hover {
    color: var(--coral);
    border-color: var(--coral);
}

.guest-limit-modal .auth-subtitle {
    padding: 0 !important;
    margin: 0 !important;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--muted);
}

.guest-limit-modal .guest-limit-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 !important;
    margin-top: 6px;
}

.guest-limit-modal .auth-submit-btn {
    margin-top: 0;
}

/* Accessibility & Utils */
.sr-only {
    width: 1px;
    height: 1px;
    position: absolute;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

[hidden] {
    display: none !important;
}

/* ==========================================================================
   Responsive Adaptations — Mobile First-Class Drawer & Clean Layout
   ========================================================================== */
@media (max-width: 900px) {
    .cards {
        grid-template-columns: 1fr;
    }
    .card {
        min-height: auto;
    }
}

/* Backdrop for Mobile Sidebar Drawer */
.sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .shell {
        grid-template-columns: 1fr !important;
        position: relative;
    }

    /* Off-canvas Drawer */
    .side {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(310px, 84vw) !important;
        height: 100% !important;
        height: 100svh !important;
        z-index: 120;
        transform: translateX(0);
        transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
        box-shadow: 14px 0 45px rgba(0, 0, 0, 0.65);
    }

    .shell.sidebar-collapsed .side {
        transform: translateX(-100%);
        pointer-events: none;
        box-shadow: none;
    }

    /* Dark Tap-to-Close Backdrop */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(14, 18, 24, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 115;
        transition: opacity 0.2s ease;
    }

    .shell.sidebar-collapsed .sidebar-backdrop {
        display: none;
    }

    .shell:not(.sidebar-collapsed) .sidebar-backdrop {
        display: block;
    }

    /* Sidebar Toggle Button */
    .sidebar-toggle {
        top: 14px;
        left: 14px;
        width: 38px;
        height: 38px;
        border: 1px solid var(--line);
        background: var(--paper-card);
        color: var(--ink);
        border-radius: 12px;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
        z-index: 130;
    }

    .shell:not(.sidebar-collapsed) .sidebar-toggle {
        left: calc(min(310px, 84vw) - 46px);
        background: #232c32;
        color: #b9c7bf;
        border-color: #3b4850;
    }

    /* Top Header — Clean & Compact on Mobile */
    .top {
        padding: 8px 12px 8px 50px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--line);
    }

    .top .eyebrow,
    #headerSubtitle {
        display: none !important;
    }

    .top h1 {
        font-size: 1.12rem;
        margin: 0;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-weight: 700;
        letter-spacing: -0.02em;
    }

    .top h1::before {
        content: "";
        display: inline-block;
        width: 6.5px;
        height: 6.5px;
        border-radius: 50%;
        background: var(--mint, #5ce1a6);
        box-shadow: 0 0 6px var(--mint, #5ce1a6);
    }

    /* Sidebar Toggle Button */
    .sidebar-toggle {
        top: 7px;
        left: 10px;
        width: 32px;
        height: 32px;
        border: 1px solid var(--line);
        background: var(--paper-card);
        color: var(--ink);
        border-radius: 9px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        z-index: 130;
        font-size: 1.1rem;
    }

    .shell:not(.sidebar-collapsed) .sidebar-toggle {
        left: calc(min(310px, 84vw) - 40px);
        background: #232c32;
        color: #b9c7bf;
        border-color: #3b4850;
    }

    /* Compact Streaming Indicator on Mobile */
    .stream {
        display: none;
        padding: 3px 8px;
        font-size: 0.68rem;
    }

    .stream.active {
        display: inline-flex;
    }

    .stream-text {
        display: none;
    }

    /* ==========================================================================
       Expandable Floating Action Button (FAB) Speed Dial on Mobile
       ========================================================================== */
    .hover-toolbar,
    body.dark-theme .hover-toolbar,
    body.dim-preview .hover-toolbar {
        position: fixed;
        right: 14px;
        bottom: 78px;
        top: auto;
        transform: none;
        z-index: 95;
        display: flex;
        flex-direction: column-reverse;
        align-items: flex-end;
        gap: 9px;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .fab-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--mint, #5ce1a6);
        color: #12161d;
        border: 1.5px solid rgba(255, 255, 255, 0.45);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28), 0 0 14px var(--mint-glow);
        cursor: pointer;
        font-size: 1.2rem;
        transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, box-shadow 0.2s ease;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .fab-toggle-btn:active {
        transform: scale(0.92);
    }

    .fab-icon-default {
        display: inline-block;
        line-height: 1;
        transition: transform 0.2s ease;
    }

    .fab-icon-close {
        display: none;
        line-height: 1;
        font-size: 1.05rem;
    }

    /* When FAB is Open */
    .hover-toolbar.open .fab-toggle-btn {
        background: var(--paper-card);
        color: var(--ink);
        border-color: var(--line);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
        transform: rotate(90deg);
    }

    .hover-toolbar.open .fab-icon-default {
        display: none;
    }

    .hover-toolbar.open .fab-icon-close {
        display: inline-block;
    }

    /* Toolbar Items on Mobile */
    .toolbar-items {
        display: flex;
        flex-direction: column-reverse;
        align-items: flex-end;
        gap: 8px;
        opacity: 0;
        pointer-events: none;
        transform: translateY(14px) scale(0.88);
        transform-origin: bottom right;
        transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .hover-toolbar.open .toolbar-items {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
    }

    .tool {
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        width: auto;
        height: auto;
        background: transparent;
        border: none;
        padding: 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transform: none;
    }

    .tool:hover,
    .tool:focus-visible {
        transform: none;
        background: transparent;
    }

    .tool-icon {
        display: grid;
        place-items: center;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--paper-card);
        border: 1px solid var(--line);
        color: var(--ink);
        font-size: 0.92rem;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
        transition: transform 0.18s ease, background 0.18s ease;
    }

    .tool:active .tool-icon {
        transform: scale(0.92);
        background: var(--mint-soft);
    }

    .tool-label {
        display: inline-block;
        padding: 4px 9px;
        border-radius: 8px;
        background: var(--paper-card);
        border: 1px solid var(--line);
        color: var(--ink);
        font-size: 0.74rem;
        font-weight: 600;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
        white-space: nowrap;
        pointer-events: none;
    }

    .tool::after {
        display: none !important;
    }

    .tool-divider {
        display: none;
    }

    /* Messages Flow — Clean Mobile Spacing */
    .messages {
        padding: 10px 12px 6px;
    }

    .welcome {
        margin-top: 1vh;
    }

    .welcome-kicker {
        font-size: 0.72rem;
        margin-bottom: 5px;
    }

    .welcome h2 {
        font-size: 1.45rem;
        line-height: 1.25;
        margin-bottom: 8px;
    }

    .welcome p {
        font-size: 0.83rem;
        line-height: 1.45;
    }

    .cards {
        grid-template-columns: 1fr;
        gap: 7px;
        margin-top: 12px;
    }

    .card {
        min-height: auto;
        padding: 10px 12px;
        border-radius: 12px;
    }

    .card i {
        display: none;
    }

    .card strong {
        font-size: 0.82rem;
    }

    .card small {
        font-size: 0.7rem;
    }

    .user-message,
    .uma-message {
        width: 100%;
        gap: 8px;
        margin-bottom: 14px;
    }

    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.65rem;
        border-radius: 8px;
    }

    .user-message .bubble {
        max-width: 88%;
        min-width: 48px;
        width: fit-content;
        padding: 9px 13px;
        font-size: 0.88rem;
        word-break: normal;
        overflow-wrap: break-word;
    }

    .user-edit-card {
        min-width: 0;
        width: 100%;
        max-width: calc(100vw - 72px);
        box-sizing: border-box;
    }

    .bubble {
        font-size: 0.88rem;
    }

    /* Composer */
    .composer {
        width: calc(100% - 14px);
        margin-bottom: 2px;
        padding: 2px 0 10px;
    }

    .hint {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 4px 6px !important;
    }

    .hint-desktop-text,
    .hint-keyboard-text {
        display: none !important;
    }

    .guest-pill {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 4px 12px;
        border-radius: 999px;
        background: rgba(239, 107, 74, 0.14);
        border: 1px solid rgba(239, 107, 74, 0.4);
        color: #ff8b70;
        font-size: 0.76rem;
        font-weight: 600;
        cursor: pointer;
    }

    .guest-pill[hidden],
    .guest-pill.hidden,
    .guest-pill[style*="display: none"],
    body.user-logged-in .guest-pill,
    body.user-logged-in #guestCounterBadge {
        display: none !important;
    }

    .guest-pill-text {
        display: inline-block !important;
        color: inherit !important;
        font-size: inherit !important;
        line-height: 1.3 !important;
    }

    .form {
        gap: 6px;
    }

    .input {
        min-height: 48px;
        padding: 6px 11px;
        border-radius: 14px;
    }

    textarea {
        font-size: 0.9rem;
        padding: 4px 0;
    }

    .send {
        min-height: 48px;
        padding: 0 15px;
        border-radius: 14px;
    }

    .send span {
        display: none;
    }

    .about-modal,
    .auth-modal {
        width: calc(100vw - 20px);
        max-height: calc(100svh - 24px);
        border-radius: 16px;
    }

    .guest-limit-modal {
        padding: 22px !important;
        width: calc(100vw - 28px) !important;
    }
}

/* ==========================================================================
   Live Streaming Cursor (Line-by-line smooth AI typing)
   ========================================================================== */
.live-stream-cursor {
    display: inline-block;
    color: var(--mint, #5ce1a6);
    font-weight: 700;
    margin-left: 2px;
    animation: streamCursorBlink 0.75s infinite ease-in-out;
    vertical-align: baseline;
    font-family: monospace;
    font-size: 1.05em;
}

@keyframes streamCursorBlink {
    0%, 100% { opacity: 1; transform: scaleY(1); }
    50% { opacity: 0; transform: scaleY(0.7); }
}

/* ==========================================================================
   Admin Dashboard & Diagnostics Modal
   ========================================================================== */
.admin-modal {
    width: min(560px, calc(100vw - 20px));
    max-height: min(85svh, 720px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.admin-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 22px 14px;
}

.admin-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--mint, #5ce1a6);
    margin-bottom: 4px;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

@media (max-width: 520px) {
    .admin-stats-grid {
        grid-template-columns: 1fr;
    }
    .admin-modal-header {
        padding: 16px 16px 10px;
    }
    #adminDashboardSection,
    #adminLoginSection {
        padding: 0 14px 14px !important;
    }
}

.admin-stat-card {
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--paper-subtle);
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.admin-stat-card .stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.admin-stat-card .stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--ink);
    line-height: 1.2;
}

.admin-stat-card .stat-sub {
    font-size: 0.72rem;
    color: var(--muted);
}

.admin-details-box,
.admin-recent-users-box {
    margin-bottom: 14px;
    padding: 14px;
    border-radius: 12px;
    background: var(--paper-subtle);
    border: 1px solid var(--line);
}

.admin-details-box h4,
.admin-recent-users-box h4 {
    margin: 0 0 10px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.admin-telemetry-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8rem;
}

.telemetry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.telemetry-row span {
    color: var(--muted);
}

.telemetry-row strong {
    color: var(--ink);
}

.admin-users-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.admin-user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 8px;
    background: var(--paper-card);
    border: 1px solid var(--line);
}

.admin-user-item strong {
    color: var(--ink);
    font-weight: 600;
}

.admin-user-item small {
    color: var(--muted);
    font-size: 0.72rem;
}

.admin-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 14px;
}

.admin-refresh-btn,
.admin-logout-btn {
    padding: 8px 14px;
    border-radius: 9px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--line);
}

.admin-refresh-btn {
    background: var(--mint-soft);
    color: #12161d;
    border-color: var(--mint2);
}

body.dark-theme .admin-refresh-btn {
    background: rgba(92, 225, 166, 0.18);
    color: var(--mint);
}

.admin-refresh-btn:hover {
    background: var(--mint);
    color: #12161d;
}

.admin-logout-btn {
    background: transparent;
    color: var(--coral);
    border-color: rgba(237, 128, 104, 0.3);
}

.admin-logout-btn:hover {
    background: rgba(237, 128, 104, 0.12);
}

/* ==========================================================================
   Uma In-App Image Lightbox Modal
   ========================================================================== */
.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeInLightbox 0.2s ease;
}

@keyframes fadeInLightbox {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.lightbox-dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    max-width: min(880px, 94vw);
    max-height: min(88vh, 880px);
    border-radius: 18px;
    background: #11151c;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.75);
    overflow: hidden;
}

.lightbox-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 10;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: #f0f6fc;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 1rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.2s ease;
}

.lightbox-close-btn:hover {
    background: rgba(237, 128, 104, 0.3);
    color: #ff8b70;
    transform: scale(1.08);
}

.lightbox-img-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #080b0f;
    overflow: hidden;
    max-height: calc(88vh - 65px);
}

.lightbox-img {
    max-width: 100%;
    max-height: calc(88vh - 65px);
    object-fit: contain;
    user-select: none;
}

.lightbox-caption-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    background: #151a23;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.lightbox-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #c9d1d9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lightbox-save-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 9px;
    background: var(--mint, #5ce1a6);
    color: #12161d;
    font-size: 0.78rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.lightbox-save-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* ==========================================================================
   Clean Chat Management System Styles (Rename, Pin, Share, Delete)
   ========================================================================== */

/* Chat History Item Row */
.chat-row {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    border-radius: 9px;
    background: transparent;
    transition: background 0.15s ease;
}

.chat-row:hover,
.chat-row.menu-open {
    background: #273238;
}

.chat-row.active {
    background: #273238;
    box-shadow: inset 3px 0 var(--mint, #5ce1a6);
}

.chat-row .chat-item {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 8px 9px 11px;
    border: 0;
    background: transparent;
    color: #b8c4bd;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.82rem;
    font-weight: 400;
    text-align: left;
    text-decoration: none !important;
    cursor: pointer;
    outline: none;
    line-height: 1.4;
    transition: color 0.15s ease;
}

.chat-row:hover .chat-item,
.chat-row.active .chat-item {
    color: #ffffff;
}

.chat-row.active .chat-item {
    font-weight: 500;
}

.chat-row .item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none !important;
    border-bottom: none !important;
    color: inherit;
    font-family: inherit;
    font-weight: inherit;
}

/* Absolute guarantee: No underlines on any chat history items under any state */
.chat-row,
.chat-row *,
.chat-row:hover *,
.chat-row:focus *,
.chat-row:active * {
    text-decoration: none !important;
    -webkit-text-decoration: none !important;
}

.chat-pin-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--mint2, #72d7aa);
    flex-shrink: 0;
    opacity: 0.9;
}

.chat-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-right: 4px;
    border-radius: 6px;
    background: transparent;
    border: 0;
    color: #7d8b84;
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.chat-row:hover .chat-more-btn,
.chat-row.menu-open .chat-more-btn {
    opacity: 0.85;
}

.chat-more-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    opacity: 1;
}

@media (hover: none) {
    .chat-more-btn {
        opacity: 0.7;
    }
}

/* Floating Compact Chat Context Menu */
.chat-context-menu {
    position: fixed;
    z-index: 9999;
    min-width: 154px;
    background: #181f2a;
    border: 1px solid #2a3749;
    border-radius: 9px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: fadeInMenu 0.12s ease-out;
}

@keyframes fadeInMenu {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: #d1d7e0;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    text-decoration: none !important;
    transition: background 0.15s ease, color 0.15s ease;
}

.menu-item .menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #8b949e;
    flex-shrink: 0;
}

.menu-item:hover {
    background: #242f40;
    color: #ffffff;
}

.menu-item:hover .menu-icon {
    color: #ffffff;
}

.menu-item-danger {
    color: #ff7b72;
}

.menu-item-danger .menu-icon {
    color: #ff7b72;
}

.menu-item-danger:hover {
    background: rgba(248, 81, 73, 0.15);
    color: #ff7b72;
}

.menu-item-danger:hover .menu-icon {
    color: #ff7b72;
}

.menu-divider {
    height: 1px;
    background: #2a3749;
    margin: 3px 0;
}

/* Modals (Share, Rename, Delete) */
.uma-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    z-index: 8000;
    animation: fadeInModal 0.18s ease;
}

.uma-modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 8001;
    width: min(420px, 92vw);
    background: var(--paper-card, #11161f);
    border: 1px solid var(--line, #222d3d);
    border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-modal, 0 24px 70px rgba(0, 0, 0, 0.5));
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: var(--ink, #f0f6fc);
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.uma-modal-dialog .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.uma-modal-dialog .modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
}

.modal-close-btn:hover {
    color: var(--ink);
}

.modal-desc {
    margin: 0 0 14px 0;
    font-size: 0.86rem;
    color: var(--muted);
    line-height: 1.5;
}

.modal-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.modal-form label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
}

.modal-form input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper-subtle, #161e29);
    color: var(--ink);
    font-size: 0.88rem;
    outline: none;
    font-family: inherit;
}

.modal-form input:focus {
    border-color: var(--mint2, #72d7aa);
}

.modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.modal-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.modal-btn-primary {
    background: var(--mint2, #72d7aa);
    color: #12161d;
}

.modal-btn-primary:hover {
    filter: brightness(1.08);
}

.modal-btn-secondary {
    background: var(--paper-subtle, rgba(255, 255, 255, 0.08));
    color: var(--ink);
    border: 1px solid var(--line);
}

.modal-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.modal-btn-danger {
    background: #da3633;
    color: #ffffff;
}

.modal-btn-danger:hover {
    background: #b62324;
}

.share-link-box {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.share-link-box input {
    flex: 1;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper-subtle);
    color: var(--ink);
    font-size: 0.82rem;
    font-family: var(--font-mono);
}

.share-feedback {
    font-size: 0.82rem;
    color: var(--mint2, #72d7aa);
    font-weight: 600;
}


