/* 
   ===== Telmi AI · Glassmorphism Design System ===== 
   Theme: Deep Space / Neon / Glass
*/

@font-face { font-family: 'Outfit'; src: url('../fonts/outfit/outfit-300.ttf') format('truetype'); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: 'Outfit'; src: url('../fonts/outfit/outfit-400.ttf') format('truetype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Outfit'; src: url('../fonts/outfit/outfit-500.ttf') format('truetype'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Outfit'; src: url('../fonts/outfit/outfit-600.ttf') format('truetype'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Outfit'; src: url('../fonts/outfit/outfit-700.ttf') format('truetype'); font-weight: 700; font-style: normal; font-display: swap; }

:root,
html[data-theme="telmi-default"] {
    /* --- Palette: Deep Space & Neon --- */
    --bg-deep: #050508;
    --bg-gradient-start: #0f0c29;
    --bg-gradient-mid: #302b63;
    --bg-gradient-end: #24243e;

    --primary: #8b5cf6;
    /* Violet */
    --primary-glow: #7c3aed;
    --secondary: #06b6d4;
    /* Cyan */
    --accent: #10b981;
    /* Emerald/Mint */

    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --text-faint: rgba(255, 255, 255, 0.4);

    /* Delivery state icons in chat bubbles. Themes may adjust contrast. */
    --chat-tick-pending: #52525b;
    --chat-tick-complete: #4ade80;

    /* --- Glass Effect --- */
    --glass-surface: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-highlight: rgba(255, 255, 255, 0.15);
    --glass-blur: 16px;
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

    /* --- Spacing & Radius --- */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-pill: 9999px;

    --header-height: 70px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-deep);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    /* Modern, geometric sans */
    font-size: 16px;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Animated Background Mesh */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 15% 50%, rgba(76, 29, 149, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(6, 182, 212, 0.15) 0%, transparent 50%);
    z-index: -1;
    pointer-events: none;
}

a {
    color: inherit;
    text-decoration: none;
    transition: 0.2s;
}

ul {
    list-style: none;
}

/* --- Typography --- */
h1,
h2,
h3,
h4 {
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}

h1 {
    font-size: 2.5rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.75rem;
}

h3 {
    font-size: 1.25rem;
}

.text-gradient {
    /* Use strong primary/secondary colors for visibility */
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-logo-text {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
}

.app-logo-pro {
    font-weight: 900;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-logo-enterprise-group {
    display: inline-flex;
    flex-direction: column;
    gap: 0;
}

.app-logo-enterprise-group span:last-child {
    margin-top: -2px;
    font-size: 0.6rem;
    letter-spacing: 2px;
    font-weight: 700;
    line-height: 0.8;
}

.app-logo-black-ops {
    margin-left: 6px;
    font-family: Impact, sans-serif;
    letter-spacing: 1.5px;
    color: #fff;
    text-shadow: 0 0 5px #f00, 0 0 10px #f00, 0 0 15px #f00;
}

.app-logo-family {
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    letter-spacing: 0;
}

.app-logo-crew {
    color: #f9a8d4;
    font-family: 'Sedgwick Ave Display', cursive;
    font-size: 1.08em;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-shadow: 0 0 12px rgba(236, 72, 153, 0.72);
}

.text-muted {
    color: var(--text-muted);
}

.text-small {
    font-size: 0.875rem;
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* --- Components: Cards (Glass) --- */
.glass-panel {
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow);
    padding: 24px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Card Variants */
/* Card Variants */
.glass-card-note {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-color: rgba(139, 92, 246, 0.2);
}

.glass-card-calendar {
    /* Schedule: True Blue */
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
    border-color: rgba(59, 130, 246, 0.2);
}

.glass-card-alert {
    /* Reminder: Deep Blue / Indigo - Distinct but Blue */
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.15) 0%, rgba(37, 99, 235, 0.05) 100%);
    border-color: rgba(37, 99, 235, 0.2);
    animation: PulseBorder 3s infinite;
}

@keyframes PulseBorder {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.2);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

/* --- Components: Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-size: 0.95rem;
    position: relative;
    overflow: hidden;
}

/* Primary Button: Gradient Glow */
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Ghost/Glass Button */
.btn-ghost {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-main);
}

.btn-ghost-danger {
    background: rgba(248, 113, 113, 0.1);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-ghost-danger:hover {
    background: rgba(248, 113, 113, 0.2) !important;
    border-color: #f87171;
}

.btn-ghost-surface {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-ghost-surface:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Standalone File Explorer surfaces stay themeable instead of relying on
   dark-theme inline colors. */
.file-explorer-modal {
    background: rgba(0, 0, 0, 0.86);
}

.file-explorer-task-marker {
    display: inline-block;
    margin-inline-end: 0.35em;
    font-family: system-ui, sans-serif;
    line-height: 1;
    user-select: none;
    vertical-align: -0.05em;
}

.file-explorer-task-marker.checked {
    color: var(--primary);
}

.file-explorer-panel {
    background: rgba(20, 20, 30, 0.92);
}

.file-explorer-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.file-explorer-breadcrumb {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 8px;
}

.file-explorer-up {
    min-height: 30px;
    padding: 4px 9px;
    white-space: nowrap;
}

.file-explorer-path {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-explorer-file-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    overflow: hidden;
}

.file-explorer-folder-main {
    justify-content: flex-start;
    text-align: left;
}

.file-explorer-file-name {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.file-explorer-file-name-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-explorer-path-badge {
    max-width: min(100%, 620px);
    padding: 3px 10px;
    font-size: 0.7rem;
    letter-spacing: 0.02em;
    text-transform: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-explorer-file-meta {
    padding-left: 22px;
}

.file-explorer-file-group {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
    flex: 1 1 0;
    min-width: 0;
    text-align: left;
}

.file-explorer-file-group .file-explorer-file-main {
    flex: 0 1 auto;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.file-shared-indicator {
    flex: 0 0 auto;
    border: 0;
    border-radius: 4px;
    padding: 2px 4px;
    background: transparent;
    color: var(--text-main);
    font-size: 0.78rem;
    line-height: 1.4;
    cursor: pointer;
}

.file-shared-indicator:hover,
.file-shared-indicator:focus-visible {
    background: var(--glass-highlight);
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

@media (max-width: 768px) {
    .file-explorer-row {
        flex-wrap: wrap;
    }

    .file-explorer-row > [data-folder-open],
    .file-explorer-row > .file-explorer-file-group {
        flex: 1 1 100% !important;
        order: -1;
    }

    .file-explorer-file-name {
        align-items: flex-start;
    }

    .file-explorer-file-name-text {
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .file-explorer-path-badge {
        max-width: 100%;
    }
}

/* --- Components: Inputs --- */
.input-group {
    margin-bottom: 20px;
}

.label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.input {
    width: 100%;
    padding: 14px 16px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: 0.2s;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.input::placeholder {
    color: var(--text-faint);
}

/* Telmi training personality selector: keep the preset and its description
   visually together while using each theme's own surface, border and shadow. */
.onb-personality-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 26px;
    padding: 16px 18px;
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow);
}

.onb-personality-panel > .label {
    margin-bottom: 0;
    color: var(--text-main);
    font-weight: 600;
}

.onb-personality-panel > .input {
    margin: 0;
}

.onb-personality-description {
    margin-top: 2px;
    padding-top: 11px;
    border-top: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1.5;
}

/* --- Components: Badges & Pills (Comic Flag Style) --- */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 16px;
    border-radius: 4px;
    /* Soft square */
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transform: skewX(-12deg);
    /* Comic/Action Skew */
    border: 1px solid var(--glass-border);
    border-left-width: 4px;
    /* Flag Pole / Spine */
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
    /* Pop shadow */
    transition: transform 0.2s, box-shadow 0.2s;
}

.badge:hover {
    transform: skewX(-12deg) translateY(-2px);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.15);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
    border-left-color: #34d399;
    text-shadow: 0 0 10px rgba(52, 211, 153, 0.4);
}

.badge-warn {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
    border-left-color: #fbbf24;
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
    border-left-color: #f87171;
    text-shadow: 0 0 10px rgba(248, 113, 113, 0.4);
}

/* --- Login Page Specifics --- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at center, rgba(48, 43, 99, 0.1) 0%, var(--bg-deep) 70%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-brand {
    margin-bottom: 30px;
    animation: float 6s ease-in-out infinite;
}

.login-logo {
    width: 80px;
    height: 80px;
    filter: drop-shadow(0 0 15px rgba(139, 92, 246, 0.4));
}

.login-title {
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
}

/* --- Layout: App Shell --- */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.app-sidebar {
    width: 280px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-sidebar.sidebar-collapsed {
    margin-left: -280px;
}

/* Floating Expand Button (Global) */
.floating-expand-btn {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 44px;
    height: 44px;
    z-index: 9000;
    background: rgba(20, 20, 35, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    color: var(--text-muted);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease;
}

.floating-expand-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    color: white;
    border-color: var(--primary);
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: none;
    background: transparent;
    pointer-events: none;
    /* Let clicks pass through transparent areas */
}

/* View Section Switching */
.view-section {
    display: none;
    flex: 1;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.view-section.active {
    display: flex;
}

/* Re-enable pointer events for children */
.app-header>* {
    pointer-events: auto;
}

/* Sidebar Nav */
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    transition: 0.2s;
    cursor: pointer;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(139, 92, 246, 0.15);
    color: var(--primary);
}

.chat-usage-icon {
    position: relative;
    display: inline-block;
    width: 24px;
    flex: 0 0 24px;
    line-height: 1;
    vertical-align: middle;
}

.chat-usage-icon > i {
    width: 100%;
    margin: 0;
    pointer-events: none;
}

.chat-usage-icon > .chat-usage-icon__fill {
    position: absolute;
    inset: 0;
    visibility: hidden;
    clip-path: inset(calc(100% - var(--usage-fill, 100%)) 0 0 0);
}

.chat-usage-icon.has-usage .chat-usage-icon__fill {
    visibility: visible;
}

html[data-theme="telmi-default"] .nav-item.active[data-tab="chat"] .chat-usage-icon__track {
    color: var(--text-muted);
}

/* Color the glyph itself so theme rules on the icon cannot replace the gradient. */
.chat-usage-icon__fill::before {
    display: inline-block;
    background: linear-gradient(110deg, #bc57ff 0%, #6542ff 45%, #00d5f5 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

/* Chat Interface */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubbles */
.bubble {
    padding: 12px 16px;
    padding-bottom: 22px;
    /* Space for timestamp */
    border-radius: 18px;
    max-width: 85%;
    width: fit-content;
    min-width: 85px;
    /* Ensure space for time+ticks */
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
    /* For absolute timestamp */
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bubble.user {
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.bubble.assistant {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    margin-right: auto;
}

.bubble a.chat-link-badge,
.bubble.assistant a.chat-link-badge,
.public-group-card .public-group-desc a.chat-link-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    margin: 0 2px;
    padding: 2px 8px 2px 5px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    font-size: 0.86em;
    line-height: 1.4;
    text-decoration: none;
    vertical-align: baseline;
    overflow-wrap: anywhere;
}

.public-group-card .public-group-desc a.chat-link-badge:hover,
.bubble a.chat-link-badge:hover {
    background: rgba(255, 255, 255, 0.2);
}

.bubble .chat-link-badge img,
.public-group-card .public-group-desc .chat-link-badge img {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    border-radius: 50%;
}

.bubble.system {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-left: 4px solid #f87171;
    text-shadow: 0 0 10px rgba(248, 113, 113, 0.3);
    font-size: 0.85rem;
    font-weight: 600;
    align-self: flex-start;
    width: fit-content;
    max-width: 90%;
    margin: 4px 0 8px 5px;
    text-align: left;
    border-radius: 4px;
    transform: skewX(-6deg);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
    font-family: 'Outfit', sans-serif;
    /* Keep the absolute SYSTEM label on a separate visual row. */
    padding-top: 30px;
}

.bubble-meta {
    font-size: 0.65rem;
    opacity: 0.6;
    position: absolute;
    top: 4px;
}

.bubble.user .bubble-meta {
    left: 10px;
    /* Name on top-left for user */
    display: none;
    /* Usually hide "ME" label to be clean */
}

.bubble.assistant .bubble-meta {
    right: 10px;
    /* Name on top-right for assistant */
    display: none;
    /* Clean look */
}

/* Timestamp: Opposite corner to bubble alignment */
.bubble-time {
    font-size: 0.65rem;
    opacity: 0.7;
    position: absolute;
    bottom: 4px;
}

.bubble.user .bubble-time {
    right: 12px;
    /* Swap to Right */
    left: auto;
    color: rgba(255, 255, 255, 0.9);
}

.bubble.assistant .bubble-time {
    left: 12px;
    /* Swap to Left */
    right: auto;
    color: var(--text-muted);
}

/* Date Divider */
.date-divider {
    display: flex;
    justify-content: center;
    margin: 16px 0;
    width: 100%;
    align-self: center;
}

.date-divider span {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Chat Input Bar */
.chat-input-wrapper {
    padding: 20px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

/* Chat Mentions (Upward dropdown) */
.mention-menu {
    position: absolute;
    left: 0;
    right: auto;
    bottom: calc(100% + 8px);
    max-height: 240px;
    overflow-y: auto;
    z-index: 120;
    border-radius: 14px;
    background: rgba(12, 12, 22, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(14px);
    padding: 6px;
    width: min(460px, 62vw);
    min-width: 300px;
}

.mention-item {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-main);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
}

.mention-item:last-child {
    margin-bottom: 0;
}

.mention-item:hover,
.mention-item.active {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(139, 92, 246, 0.55);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2) inset;
}

.mention-item-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mention-item-type {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.9;
}

/* Reuse contact badge styling, floating over the upper-right input edge. */
.from-badge.pinned-chat-contact {
    position: absolute;
    right: 12px;
    bottom: calc(100% - 10px);
    z-index: 5;
    max-width: min(260px, calc(100% - 24px));
    min-width: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 3px 6px 3px 8px;
    background: var(--glass-bg, var(--bg-deep));
    font-size: .7rem;
}

.pinned-chat-contact[hidden] { display: none !important; }
.pinned-chat-contact > i { color: var(--primary); flex: 0 0 auto; }
.from-badge-text.pinned-chat-contact-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

html[data-theme="telmi-papyrus"] .from-badge.pinned-chat-contact {
    background-color: #faf4e4;
}

html[data-theme="telmi-light-blue"] .from-badge.pinned-chat-contact {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
}

html[data-theme="telmi-light-blue"] .pinned-chat-contact .pinned-chat-contact-name {
    background: none;
    color: #fff;
    -webkit-text-fill-color: #fff;
}

html[data-theme="telmi-light-blue"] .pinned-chat-contact > i,
html[data-theme="telmi-light-blue"] .pinned-chat-contact .pinned-chat-contact-clear {
    color: #fff;
}

.mention-contact-row { display: flex; align-items: stretch; gap: 2px; margin-bottom: 4px; }
.mention-contact-row:last-child { margin-bottom: 0; }
.mention-contact-row > .mention-item { flex: 1; min-width: 0; margin-bottom: 0; }
.mention-contact-row .mention-item-type { flex: 0 0 auto; }

.mention-pin,
.pinned-chat-contact-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    min-height: 36px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.mention-pin i { transform: rotate(35deg); opacity: .65; }
.mention-pin[aria-pressed="true"] { color: var(--primary); background: var(--glass-bg, var(--glass-surface)); border-color: var(--primary); }
.mention-pin[aria-pressed="true"] i { transform: none; opacity: 1; }
.mention-pin:hover, .pinned-chat-contact-clear:hover { color: var(--primary); border-color: var(--primary); }
.pinned-chat-contact-clear {
    position: relative;
    width: 20px;
    min-height: 20px;
    border: 0;
    border-radius: 999px;
    color: var(--text-main);
    font-size: 1rem;
    line-height: 1;
}
/* A larger invisible touch target keeps the visible badge compact. */
.pinned-chat-contact-clear::after { content: ''; position: absolute; inset: -10px -6px -10px -4px; }
.mention-pin:focus-visible, .pinned-chat-contact-clear:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (pointer: coarse) {
    .mention-pin { width: 44px; min-height: 44px; }
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 14px;
    color: white;
    resize: none;
    max-height: 150px;
    overflow-y: hidden;
    transition: height 0.15s ease, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

#chat-form {
    position: relative;
}

.chat-prompt-wrap {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
}

.chat-prompt-wrap .chat-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

/* Match the send button at one line while preserving multiline growth. */
html:not([data-theme="telmi-neon-afterlife"]) #prompt.chat-input {
    min-height: 52px;
}

.chat-prompt-wrap .chat-input[hidden] { display: none !important; }

.voice-input-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    box-sizing: border-box;
    padding: 8px 12px;
    color: var(--text-main);
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
}

.voice-input-panel[hidden] { display: none !important; }
.voice-input-status { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.voice-input-message { flex: 1 1 80px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.voice-input-timer { flex: 0 0 auto; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: .82rem; }
.voice-input-indicator { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 14px; width: 14px; height: 14px; color: var(--secondary); }
.voice-input-indicator.is-recording { width: 10px; height: 10px; flex-basis: 10px; border-radius: 50%; background: #ef4444; animation: voice-record-pulse 1.2s ease-in-out infinite; }
.voice-input-controls { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.voice-control-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; color: var(--text-main); background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-md); cursor: pointer; }
.voice-control-btn:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.voice-control-btn:disabled { opacity: .45; cursor: not-allowed; }
.voice-control-btn[hidden] { display: none !important; }
.voice-control-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.voice-stop-btn { color: #ef4444; }
.voice-mode .composer-submit-btn:disabled { opacity: .5; cursor: not-allowed; }
.voice-mode .composer-mode-toggle:disabled, .voice-mode #chat-file-btn:disabled,
.voice-mode #toggle-opts:disabled, .voice-mode #sidebar-expand-input-btn:disabled { opacity: .45; cursor: not-allowed; }
@keyframes voice-record-pulse { 50% { opacity: .38; transform: scale(.78); } }
@media (prefers-reduced-motion: reduce) { .voice-input-indicator { animation: none !important; } }

.chat-memory-char-count {
    position: absolute;
    right: 11px;
    bottom: 8px;
    z-index: 1;
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.42);
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.2;
    pointer-events: none;
    user-select: none;
}

.chat-memory-char-count.at-limit {
    color: #fca5a5;
}

.composer-submit-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex: 0 0 auto;
    align-self: flex-end;
}

.composer-submit-btn {
    height: 52px;
    width: 52px;
    padding: 0;
    border-radius: 14px;
    flex-shrink: 0;
}

.composer-mode-toggle {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 52px;
    padding: 0;
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    background: var(--glass-bg);
    color: var(--text-muted);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    cursor: pointer;
}

.composer-mode-arrows { display: flex; flex-direction: column; gap: 4px; }
.composer-mode-arrows .composer-mode-toggle { height: 24px; border-radius: 7px; }
.composer-mode-arrows .composer-mode-toggle:disabled { opacity: .4; cursor: not-allowed; }
.composer-mode-arrows .composer-mode-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.composer-mode-toggle:hover,
.chat-input-wrapper.web-search-mode .composer-mode-toggle {
    border-color: var(--primary);
    color: var(--primary);
}

.chat-input-wrapper.web-search-mode .composer-submit-btn,
.chat-input-wrapper.web-search-mode .composer-submit-btn:hover {
    background: #090909;
    color: #fff;
    border-color: #fff;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.32);
}

.chat-input-wrapper.web-search-mode .composer-submit-btn .fa-globe {
    font-size: 1.18rem;
}

.bubble.system.web-search-notice {
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(56, 189, 248, 0.42);
    border-left-color: #38bdf8;
    color: #bae6fd;
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
    outline: none;
}

/* Upsert Mode: Gradient Border/Glow */
.chat-input.upsert-mode {
    border-color: transparent;
    background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), linear-gradient(135deg, var(--primary), var(--secondary));
    background-origin: border-box;
    background-clip: padding-box, border-box;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

.bubble.memory-success {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-left: 4px solid #34d399;
    /* Flag pole style */
    text-shadow: 0 0 10px rgba(52, 211, 153, 0.4);
    align-self: flex-start;
    text-align: left;
    max-width: 90%;
    font-size: 0.9rem;
    padding: 12px 20px;
    border-radius: 4px;
    /* Square off for flag look */
    transform: skewX(-5deg);
    /* Slight skew like the badge */
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
    /* Add spacing */
    margin-left: 5px;
    /* Offset for skew */
}

/* Utilities */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.4s ease;
}

.w-full {
    width: 100%;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-center {
    text-align: center;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Mobile Tweaks */
@media (max-width: 768px) {

    /* Lock body scroll to prevent "taller than screen" bounce */
    html,
    body {
        height: 100%;
        overflow: hidden;
        position: fixed;
        /* iOS Safari fix */
        width: 100%;
    }

    .app-shell {
        flex-direction: column;
        height: 100%;
        width: 100%;
    }

    /* Hide Side Nav */
    .app-sidebar {
        display: none;
    }

    /* Header visible on mobile for Group Context */
    .app-header {
        display: flex;
        height: 60px;
        padding: 0 16px;
        z-index: 1000;
        /* High Z-level */
        position: fixed;
        /* Always stick */
        top: 0;
        left: 0;
        right: 0;
        /* Add background to obscure scrolling content behind it */
        background: linear-gradient(to bottom, rgba(5, 5, 8, 0.9) 0%, rgba(5, 5, 8, 0) 100%);
        pointer-events: none;
        /* Let clicks pass, but children auto */
    }

    .app-header>* {
        pointer-events: auto;
    }

    /* Adjust Main Content for Bottom Nav & Header */
    .app-main {
        padding-top: 60px;
        /* Space for fixed header */
        padding-bottom: 80px;
        /* Space for bottom nav */
        height: 100%;
        width: 100%;
    }

    /* Mobile Bottom Nav */
    /* Mobile Bottom Nav */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(70px + env(safe-area-inset-bottom));
        /* Height + Safe Area */
        min-height: 70px;
        background: rgba(5, 5, 8, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--glass-border);
        justify-content: space-around;
        align-items: flex-start;
        /* Align top so padding pushes items up/center relative to 70px block if needed, or Center if padding handles it */
        align-items: center;
        padding-top: 0;
        padding-bottom: env(safe-area-inset-bottom);
        /* Push content up */
        z-index: 100;
        padding-left: 10px;
        padding-right: 10px;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.3);
    }

    .mobile-nav .nav-item {
        flex-direction: column;
        gap: 4px;
        padding: 8px;
        font-size: 0.7rem;
        background: transparent !important;
        /* Remove bg active style */
        color: var(--text-muted);
        opacity: 0.7;
    }

    .mobile-nav .nav-item.active {
        color: var(--primary);
        opacity: 1;
        transform: translateY(-2px);
    }

    .mobile-nav .nav-item i {
        font-size: 1.4rem;
        margin-bottom: 2px;
    }

    .bubble {
        max-width: 90%;
    }

    /* Adjust chat area */
    .chat-area {
        padding: 16px;
        /* Mask to fade out top 20% */
        mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
        -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
    }

    .chat-input-wrapper {
        padding: 10px 12px;
    }

    /* Web search is switched by swiping the submit control on mobile. */
    .composer-mode-toggle {
        display: none;
    }
    .composer-mode-arrows { display: none; }

    .voice-input-status {
        display: grid;
        grid-template-columns: 14px minmax(0, 1fr);
        column-gap: 8px;
        row-gap: 4px;
        align-items: center;
    }
    .voice-input-indicator { grid-column: 1; grid-row: 1; justify-self: center; }
    .voice-input-message { grid-column: 2; grid-row: 1; }
    .voice-input-timer { grid-column: 2; grid-row: 2; }
    .voice-input-timer:empty { display: none; }

    /* Keep the composer flush with the viewport and mobile navigation. */
    #view-chat.active .chat-input-wrapper {
        position: fixed;
        z-index: 90;
        left: 0;
        right: 0;
        bottom: calc(70px + env(safe-area-inset-bottom));
        width: 100%;
        background: rgba(5, 5, 8, 0.98);
    }

    /* Prevent the latest bubble from being obscured by the fixed composer. */
    #view-chat.active .chat-area {
        padding-bottom: var(--mobile-chat-composer-reserve, calc(118px + env(safe-area-inset-bottom)));
    }

    .mention-menu {
        left: 0;
        right: 0;
        bottom: calc(100% + 6px);
        max-height: 200px;
        width: auto;
        min-width: 0;
    }

    /* Hide sidebar expand button on mobile */
    .floating-expand-btn {
        display: none !important;
    }
}

/* Desktop: Hide Mobile Nav */
@media (min-width: 769px) {
    .mobile-nav {
        display: none;
    }

    .chat-area {
        padding-left: 48px;
        padding-right: 48px;
    }
}

/* Keep wide Markdown tables scrollable inside their message bubble. */
.bubble .chat-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    margin: 10px 0;
}

.bubble .chat-table-scroll:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Markdown Code Blocks */
.bubble pre {
    background: #282c34;
    /* Atom One Dark bg match */
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.bubble code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

/* Shared controls for rendered code blocks and text file previews. */
.telmi-code-box {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 10px 0;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    overflow: hidden;
}

.telmi-code-toolbar {
    display: flex;
    flex: 0 0 auto;
    justify-content: flex-end;
    padding: 4px 8px;
    background: var(--glass-bg, rgba(255, 255, 255, 0.04));
    color: var(--text-main, #f4f5fb);
}

.telmi-code-copy {
    min-height: 32px;
    min-width: 84px;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
}

.telmi-code-copy:hover {
    border-color: var(--primary, #8b5cf6);
}

.telmi-code-copy:focus-visible {
    outline: 2px solid var(--primary, #8b5cf6);
    outline-offset: 1px;
}

.telmi-code-box > pre {
    margin: 0;
    width: 100%;
    box-sizing: border-box;
    border: 0;
    border-radius: 0 0 8px 8px;
    box-shadow: none;
}

#file-viewer-body > .telmi-code-box {
    display: flex;
    flex-direction: column;
    max-height: 68vh;
}

#file-viewer-body > .telmi-code-box > pre {
    min-height: 0;
}

@media print {
    .telmi-code-toolbar { display: none; }
}

/* Inline code strings */
.bubble p code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    color: #e06c75;
}

/* Restore native Markdown bullets suppressed by the global UI list reset.
   Revert also preserves the browser's markers for nested and mixed lists. */
:where(.bubble, .mantis-markdown, .public-group-desc, #legal-content) ul {
    list-style-type: revert;
}

/* Chat and Mantis already provide their own list indentation. */
:where(.public-group-desc, #legal-content) :is(ul, ol) {
    margin-block: 0.5rem;
    padding-inline-start: 1.5rem;
}

/* File previews use their own checkbox markers for Markdown task items. */
.mantis-markdown li:has(> .file-explorer-task-marker, > p > .file-explorer-task-marker) {
    list-style-type: none;
}

/* Assistant Lists */
.bubble ul,
.bubble ol {
    margin-left: 20px;

    /* System Bubble Style (Neon Badge Look) */
    .bubble.system {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text-muted);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-left: 4px solid rgba(255, 255, 255, 0.4);
        border-radius: 4px;
        font-size: 0.8rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        padding: 8px 16px;
        width: fit-content;
        margin-right: auto;
        margin-left: 10px;
        /* Offset for skew */
        margin-top: 8px;
        margin-bottom: 8px;
        transform: skewX(-12deg);
        box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
    }

    .bubble.system .bubble-meta {
        display: none;
    }
}

/* --- Range Slider Gradient --- */
.input-range-gradient {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    outline: none;
    margin: 10px 0;
    transition: background 0.3s;
}

.input-range-gradient:hover {
    background: rgba(255, 255, 255, 0.15);
}

.input-range-gradient::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    border: 2px solid white;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: -6px;
    /* Center thumb on track if needed, usually auto for webkit unless track has height */
}

/* Firefox Support */
.input-range-gradient::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    border: 2px solid white;
}

/* --- Gradient Toggle Switch --- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    /* Wider for pill shape */
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--glass-border);
    /* Muted off state */
    transition: .4s;
    border-radius: 34px;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.slider {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.4);
}

.toggle-switch input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

.toggle-switch input:checked+.slider:before {
    transform: translateX(24px);
}

.glass-card-task {
    /* No border-left */
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.15) 0%, rgba(14, 165, 233, 0.15) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Board content can contain plain URLs and tokens with no natural wrap points. */
#board-grid > .glass-panel {
    min-width: 0;
    max-width: 100%;
}

#board-grid .board-card-copy {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#board-grid .board-card-row > * {
    min-width: 0;
}

.board-link-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    margin: 0 2px;
    padding: 2px 8px 2px 5px;
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    font-size: 0.82em;
    line-height: 1.4;
    text-decoration: none;
    vertical-align: baseline;
    overflow-wrap: anywhere;
}

.board-link-badge:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.28);
}

.board-link-badge img {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    border-radius: 50%;
}

.calendar-event-row {
    width: 100%;
    min-width: 0;
}

.calendar-event-content {
    flex: 1 1 0;
    min-width: 0;
}

.calendar-event-title {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.calendar-event-title .board-link-badge span {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* --- Badge Counter --- */
.nav-item {
    position: relative;
    /* For badge positioning */
}

.badge-counter {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #ff3b30;
    /* iOS Red */
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 4px;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

/* --- Business Theme ------------------------------------------------------ */
/*
   Keep all alternate palette rules in this scope. New themes can follow the
   same pattern without changing markup or the default visual language.
*/
html[data-theme="telmi-business"] {
    --bg-deep: #080808;
    --bg-gradient-start: #0b0b0c;
    --bg-gradient-mid: #141416;
    --bg-gradient-end: #1c1c1f;

    --primary: #f5f5f5;
    --primary-glow: #d4d4d8;
    --secondary: #a1a1aa;
    --accent: #d4d4d8;

    --text-main: #f7f7f8;
    --text-muted: rgba(247, 247, 248, 0.68);
    --text-faint: rgba(247, 247, 248, 0.42);

    --glass-bg: rgba(24, 24, 27, 0.88);
    --glass-surface: rgba(255, 255, 255, 0.055);
    --glass-border: rgba(255, 255, 255, 0.13);
    --glass-highlight: rgba(255, 255, 255, 0.18);
    --glass-shadow: 0 12px 34px rgba(0, 0, 0, 0.46);
}

html[data-theme="telmi-business"] body::before {
    background:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.045) 0%, transparent 42%),
        radial-gradient(circle at 82% 82%, rgba(255, 255, 255, 0.025) 0%, transparent 44%);
}

html[data-theme="telmi-business"] .app-sidebar,
html[data-theme="telmi-business"] .chat-input-wrapper {
    background: rgba(5, 5, 6, 0.72);
}

@media (max-width: 768px) {
    html[data-theme="telmi-business"] #view-chat.active .chat-input-wrapper {
        background: rgba(5, 5, 6, 0.98);
    }
}

html[data-theme="telmi-business"] .nav-item.active,
html[data-theme="telmi-business"] .nav-item:hover,
html[data-theme="telmi-business"] .mention-item:hover,
html[data-theme="telmi-business"] .mention-item.active {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.24);
    color: var(--text-main);
    box-shadow: none;
}

html[data-theme="telmi-business"] .btn-primary {
    background: linear-gradient(135deg, #ffffff 0%, #c7c7cc 100%);
    color: #101012;
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.1);
}

html[data-theme="telmi-business"] .btn-primary:hover {
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.18);
}

html[data-theme="telmi-business"] .input:focus,
html[data-theme="telmi-business"] .chat-input:focus {
    border-color: rgba(255, 255, 255, 0.72);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}

html[data-theme="telmi-business"] .toggle-switch input:checked + .slider,
html[data-theme="telmi-business"] .input-range-gradient::-webkit-slider-thumb,
html[data-theme="telmi-business"] .input-range-gradient::-moz-range-thumb {
    background: linear-gradient(135deg, #ffffff 0%, #a1a1aa 100%);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.16);
}

html[data-theme="telmi-business"] .bubble.user {
    background: linear-gradient(135deg, #ffffff 0%, #c9c9cf 100%);
    color: #111113;
}

html[data-theme="telmi-business"] .bubble.user .bubble-time {
    color: rgba(17, 17, 19, 0.68);
}

html[data-theme="telmi-business"] .bubble.assistant {
    background: rgba(24, 24, 27, 0.9);
}

html[data-theme="telmi-business"] .chat-input.upsert-mode {
    background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), linear-gradient(135deg, #8b5cf6, #06b6d4);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

html[data-theme="telmi-business"] .glass-card-note,
html[data-theme="telmi-business"] .glass-card-calendar,
html[data-theme="telmi-business"] .glass-card-alert,
html[data-theme="telmi-business"] .glass-card-task,
html[data-theme="telmi-business"] .task-list-item.done {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.13);
    box-shadow: none;
}

html[data-theme="telmi-business"] .task-list-item-checkbox {
    accent-color: #f5f5f5;
}

html[data-theme="telmi-business"] .chat-loading-overlay {
    background: rgba(7, 7, 8, 0.9);
}

html[data-theme="telmi-business"] .chat-loading-spinner {
    background: conic-gradient(from 180deg, #ffffff 0%, #8f8f96 50%, #ffffff 100%);
    box-shadow: 0 0 24px rgba(255, 255, 255, 0.12);
}

html[data-theme="telmi-business"] .chat-loading-label {
    background: linear-gradient(135deg, #ffffff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

html[data-theme="telmi-business"] .chat-loading-meta {
    color: rgba(255, 255, 255, 0.58);
}

html[data-theme="telmi-business"] .loader-lg {
    border-top-color: #ffffff;
    border-right-color: #8f8f96;
}

html[data-theme="telmi-business"] .app-update-pill {
    color: #111113;
    background: linear-gradient(135deg, #ffffff, #c7c7cc);
    border-color: rgba(255, 255, 255, 0.58);
    box-shadow: 0 14px 34px rgba(255, 255, 255, 0.12);
}

html[data-theme="telmi-business"] .ghost-cockpit-strip,
html[data-theme="telmi-business"] .ghost-cockpit-panel,
html[data-theme="telmi-business"] .ghost-cockpit-card,
html[data-theme="telmi-business"] .ghost-cockpit-metric,
html[data-theme="telmi-business"] .ghost-cockpit-mini-metric,
html[data-theme="telmi-business"] .ghost-cockpit-empty {
    background: rgba(22, 22, 24, 0.94);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

html[data-theme="telmi-business"] .ghost-cockpit-strip::before {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
}

html[data-theme="telmi-business"] .ghost-cockpit-icon,
html[data-theme="telmi-business"] .ghost-cockpit-mission-nav button:not(:disabled):hover {
    background: linear-gradient(135deg, #f5f5f5, #a1a1aa);
    color: #111113;
    box-shadow: none;
}

html[data-theme="telmi-business"] .ghost-cockpit-mission-browser {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.13);
}

html[data-theme="telmi-business"] .ghost-cockpit-mission-head,
html[data-theme="telmi-business"] .ghost-cockpit-mission-status,
html[data-theme="telmi-business"] .ghost-cockpit-metric i {
    color: #d4d4d8;
}

html[data-theme="telmi-business"] .ghost-card,
html[data-theme="telmi-business"] .mantis-module-card,
html[data-theme="telmi-business"] .mantis-instance-card,
html[data-theme="telmi-business"] .mantis-instance-cron-panel {
    background: linear-gradient(145deg, rgba(28, 28, 31, 0.94), rgba(16, 16, 18, 0.94)) !important;
    border-color: rgba(255, 255, 255, 0.11) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 18px 38px rgba(0, 0, 0, 0.2) !important;
}

html[data-theme="telmi-business"] #ghost-list .btn,
html[data-theme="telmi-business"] #ghost-list .ghost-agentic-toggle,
html[data-theme="telmi-business"] #ghost-list .ghost-autonomy-toggle,
html[data-theme="telmi-business"] .ghost-name-edit,
html[data-theme="telmi-business"] .mantis-doc-tab,
html[data-theme="telmi-business"] .mantis-brand-icon {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.13);
    box-shadow: none;
}

html[data-theme="telmi-business"] #ghost-list .btn:hover,
html[data-theme="telmi-business"] .ghost-name-edit:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: none;
}

html[data-theme="telmi-business"] .ghost-observation-toggle.is-on,
html[data-theme="telmi-business"] .mantis-doc-tab.active {
    color: #111113;
    background: linear-gradient(135deg, #ffffff, #c7c7cc);
    border-color: rgba(255, 255, 255, 0.58);
    box-shadow: none;
}

html[data-theme="telmi-business"] .mantis-readme-collapsed::after {
    background: linear-gradient(180deg, rgba(18, 18, 20, 0), rgba(18, 18, 20, 0.98));
}

html[data-theme="telmi-business"] .mantis-markdown blockquote {
    border-left-color: rgba(255, 255, 255, 0.55);
}

/* --- Light Blue Theme ---------------------------------------------------- */
/*
   Sky Blue is intentionally a light canvas: #F0F9FF, white surfaces and
   navy ink. Signature violet/cyan system and group treatments keep their
   Default values so operational badges remain recognisable across themes.
*/
html[data-theme="telmi-light-blue"] {
    color-scheme: light;

    --bg-deep: #f0f9ff;
    --bg-gradient-start: #f0f9ff;
    --bg-gradient-mid: #d9f1ff;
    --bg-gradient-end: #b9e2fa;

    /* Keep the default signature gradient for badges, system states and CTAs. */
    --primary: #8b5cf6;
    --primary-glow: #7c3aed;
    --secondary: #06b6d4;
    --accent: #10b981;

    --text-main: #082c4c;
    --text-muted: rgba(8, 44, 76, 0.72);
    --text-faint: rgba(8, 44, 76, 0.5);

    --chat-tick-pending: #68839b;
    --chat-tick-complete: #4ade80;

    --glass-bg: rgba(240, 249, 255, 0.9);
    --glass-surface: rgba(255, 255, 255, 0.68);
    --glass-border: rgba(75, 139, 180, 0.28);
    --glass-highlight: rgba(255, 255, 255, 0.94);
    --glass-shadow: 0 16px 42px rgba(27, 89, 128, 0.16);
}

html[data-theme="telmi-light-blue"] body::before {
    background:
        radial-gradient(circle at 9% 10%, rgba(255, 255, 255, 0.98) 0%, transparent 31%),
        radial-gradient(circle at 90% 8%, rgba(179, 224, 248, 0.62) 0%, transparent 40%),
        radial-gradient(circle at 52% 100%, rgba(132, 198, 234, 0.5) 0%, transparent 45%);
}

html[data-theme="telmi-light-blue"] .app-sidebar,
html[data-theme="telmi-light-blue"] .chat-input-wrapper {
    background: rgba(240, 249, 255, 0.94);
    border-color: rgba(75, 139, 180, 0.24);
}

html[data-theme="telmi-light-blue"] .nav-item.active,
html[data-theme="telmi-light-blue"] .nav-item:hover,
html[data-theme="telmi-light-blue"] .mention-item:hover,
html[data-theme="telmi-light-blue"] .mention-item.active {
    background: rgba(178, 224, 248, 0.42);
    border-color: rgba(48, 127, 175, 0.32);
    color: #082c4c;
    box-shadow: 0 8px 22px rgba(66, 150, 202, 0.16);
}

html[data-theme="telmi-light-blue"] .input:focus,
html[data-theme="telmi-light-blue"] .chat-input:focus {
    border-color: rgba(32, 115, 166, 0.76);
    box-shadow: 0 0 0 4px rgba(110, 191, 235, 0.22);
}

html[data-theme="telmi-light-blue"] .chat-input {
    color: var(--text-main);
}

html[data-theme="telmi-light-blue"] .chat-input::placeholder {
    color: rgba(8, 44, 76, 0.5);
}

html[data-theme="telmi-light-blue"] .bubble.assistant {
    background: rgba(255, 255, 255, 0.88);
    border-color: rgba(75, 139, 180, 0.25);
}

html[data-theme="telmi-light-blue"] .chat-input.upsert-mode {
    background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), linear-gradient(135deg, #8b5cf6, #06b6d4);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

html[data-theme="telmi-light-blue"] #group-context-menu {
    color: var(--text-main);
    background: rgba(250, 254, 255, 0.98) !important;
    border-color: rgba(48, 127, 175, 0.36) !important;
    box-shadow: 0 16px 40px rgba(31, 102, 148, 0.24) !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu > div:first-child {
    background: rgba(208, 237, 252, 0.64) !important;
    border-bottom-color: rgba(48, 127, 175, 0.18) !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu .nav-item,
html[data-theme="telmi-light-blue"] #group-context-menu .nav-item i,
html[data-theme="telmi-light-blue"] #group-context-menu .nav-item span {
    color: var(--text-main) !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu .nav-item:hover {
    background: rgba(190, 229, 250, 0.64) !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu .nav-item > div:last-child {
    background: transparent !important;
    border-color: rgba(48, 127, 175, 0.5) !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu .nav-item > div:last-child:has(.fa-check) {
    background: #0a4d78 !important;
    border-color: #0a4d78 !important;
}

html[data-theme="telmi-light-blue"] #group-context-menu .nav-item > div:last-child .fa-check {
    color: #fff !important;
}

html[data-theme="telmi-light-blue"] .glass-card-note,
html[data-theme="telmi-light-blue"] .glass-card-calendar,
html[data-theme="telmi-light-blue"] .glass-card-alert,
html[data-theme="telmi-light-blue"] .glass-card-task,
html[data-theme="telmi-light-blue"] .glass-card-schedule,
html[data-theme="telmi-light-blue"] .task-list-item.done {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(224, 243, 255, 0.9));
    border-color: rgba(75, 139, 180, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.94), 0 12px 28px rgba(31, 102, 148, 0.13);
}

/* Light Blue contrast pass for legacy dark-theme inline content styles. */
html[data-theme="telmi-light-blue"] .glass-card-task .board-card-copy:not(.text-muted),
html[data-theme="telmi-light-blue"] .glass-card-schedule .board-card-copy,
html[data-theme="telmi-light-blue"] .glass-card-alert [style*="font-size:1.2rem"][style*="color:white"],
html[data-theme="telmi-light-blue"] .glass-card-schedule > div[style*="background:rgba(255,255,255,0.06)"] > div:last-child,
html[data-theme="telmi-light-blue"] #recurring-schedule-modal #recurring-schedule-body [style*="color:white"] {
    color: var(--text-main) !important;
}

html[data-theme="telmi-light-blue"] .view-section h3[style*="color:white"],
html[data-theme="telmi-light-blue"] .view-section h4[style*="color:white"],
html[data-theme="telmi-light-blue"] #ghost-list .ghost-card-name,
html[data-theme="telmi-light-blue"] #ghost-list .ghost-id-line,
html[data-theme="telmi-light-blue"] #ghost-list .ghost-card-name i[style*="color:white"],
html[data-theme="telmi-light-blue"] .mantis-markdown,
html[data-theme="telmi-light-blue"] .mantis-markdown strong,
html[data-theme="telmi-light-blue"] .mantis-markdown h1,
html[data-theme="telmi-light-blue"] .mantis-markdown h2,
html[data-theme="telmi-light-blue"] .mantis-markdown h3,
html[data-theme="telmi-light-blue"] .mantis-instance-card [style*="color:white"],
html[data-theme="telmi-light-blue"] .mantis-instance-cron-panel [style*="color:white"],
html[data-theme="telmi-light-blue"] #gt-creator-builder [style*="color:white"],
html[data-theme="telmi-light-blue"] #gt-question-label,
html[data-theme="telmi-light-blue"] #onb-question-label {
    color: var(--text-main) !important;
}

html[data-theme="telmi-light-blue"] #onb-card textarea#onb-answer {
    color: var(--text-main) !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(75, 139, 180, 0.28) !important;
}

/* Account actions use a secondary Sky Blue surface, not the dark-theme ghost button. */
html[data-theme="telmi-light-blue"] #view-profile #btn-memory-manager,
html[data-theme="telmi-light-blue"] #view-profile #btn-file-explorer,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-chat-history,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-cache,
html[data-theme="telmi-light-blue"] #view-profile #btn-logout,
html[data-theme="telmi-light-blue"] #view-profile button[onclick="openLegalModal()"] {
    color: #082c4c !important;
    background: linear-gradient(135deg, #d9f1ff, #b9e2fa) !important;
    border-color: rgba(48, 127, 175, 0.32) !important;
    box-shadow: 0 8px 18px rgba(52, 131, 179, 0.12);
}

html[data-theme="telmi-light-blue"] #view-profile #btn-memory-manager i,
html[data-theme="telmi-light-blue"] #view-profile #btn-file-explorer i,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-chat-history i,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-cache i,
html[data-theme="telmi-light-blue"] #view-profile #btn-logout i,
html[data-theme="telmi-light-blue"] #view-profile button[onclick="openLegalModal()"] i {
    color: inherit !important;
}

html[data-theme="telmi-light-blue"] #view-profile #btn-memory-manager:hover,
html[data-theme="telmi-light-blue"] #view-profile #btn-file-explorer:hover,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-chat-history:hover,
html[data-theme="telmi-light-blue"] #view-profile #btn-clear-cache:hover,
html[data-theme="telmi-light-blue"] #view-profile #btn-logout:hover,
html[data-theme="telmi-light-blue"] #view-profile button[onclick="openLegalModal()"]:hover {
    color: #082c4c !important;
    background: linear-gradient(135deg, #c8ebfd, #9cd7f4) !important;
    border-color: rgba(32, 115, 166, 0.5) !important;
}

html[data-theme="telmi-light-blue"] .ghost-cockpit-strip,
html[data-theme="telmi-light-blue"] .ghost-cockpit-panel,
html[data-theme="telmi-light-blue"] .ghost-cockpit-card,
html[data-theme="telmi-light-blue"] .ghost-cockpit-metric,
html[data-theme="telmi-light-blue"] .ghost-cockpit-mini-metric,
html[data-theme="telmi-light-blue"] .ghost-cockpit-empty {
    background: rgba(248, 253, 255, 0.86);
    border-color: rgba(75, 139, 180, 0.22);
    box-shadow: 0 12px 30px rgba(31, 102, 148, 0.12);
}

html[data-theme="telmi-light-blue"] .ghost-cockpit-strip::before {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1), rgba(169, 220, 249, 0.48), rgba(255, 255, 255, 0.1));
}

html[data-theme="telmi-light-blue"] .ghost-cockpit-icon {
    background: linear-gradient(145deg, #ffffff, #b8e4fa);
    color: #082c4c;
    box-shadow: 0 10px 26px rgba(83, 166, 211, 0.2);
}

html[data-theme="telmi-light-blue"] .ghost-cockpit-mission-browser {
    background: rgba(255, 255, 255, 0.64);
    border-color: rgba(75, 139, 180, 0.22);
}

html[data-theme="telmi-light-blue"] .ghost-cockpit-mission-head,
html[data-theme="telmi-light-blue"] .ghost-cockpit-mission-status,
html[data-theme="telmi-light-blue"] .ghost-cockpit-metric i {
    color: #0a4d78;
}

html[data-theme="telmi-light-blue"] .ghost-card,
html[data-theme="telmi-light-blue"] .mantis-module-card,
html[data-theme="telmi-light-blue"] .mantis-instance-card,
html[data-theme="telmi-light-blue"] .mantis-instance-cron-panel {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(216, 240, 255, 0.93)) !important;
    border-color: rgba(75, 139, 180, 0.25) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.96), 0 18px 38px rgba(31, 102, 148, 0.13) !important;
}

html[data-theme="telmi-light-blue"] #ghost-list .btn,
html[data-theme="telmi-light-blue"] #ghost-list .ghost-agentic-toggle,
html[data-theme="telmi-light-blue"] #ghost-list .ghost-autonomy-toggle,
html[data-theme="telmi-light-blue"] .ghost-name-edit,
html[data-theme="telmi-light-blue"] .mantis-doc-tab,
html[data-theme="telmi-light-blue"] .mantis-brand-icon {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(75, 139, 180, 0.22);
}

html[data-theme="telmi-light-blue"] #ghost-list .btn:hover,
html[data-theme="telmi-light-blue"] .ghost-name-edit:hover {
    background: rgba(194, 232, 252, 0.62);
    border-color: rgba(48, 127, 175, 0.42);
}

html[data-theme="telmi-light-blue"] .mantis-readme-collapsed::after {
    background: linear-gradient(180deg, rgba(240, 249, 255, 0), rgba(240, 249, 255, 0.98));
}

html[data-theme="telmi-light-blue"] .mantis-markdown blockquote {
    border-left-color: rgba(44, 131, 181, 0.62);
}

html[data-theme="telmi-light-blue"] ::-webkit-scrollbar-track {
    background: rgba(203, 231, 247, 0.72);
}

html[data-theme="telmi-light-blue"] ::-webkit-scrollbar-thumb {
    background: rgba(56, 138, 184, 0.56);
    border-color: rgba(240, 249, 255, 0.88);
}

@media (max-width: 768px) {
    html[data-theme="telmi-light-blue"] #view-chat.active .chat-input-wrapper,
    html[data-theme="telmi-light-blue"] .mobile-nav {
        background: rgba(240, 249, 255, 0.96);
        border-color: rgba(75, 139, 180, 0.24);
    }

    html[data-theme="telmi-light-blue"] .mobile-nav .nav-item,
    html[data-theme="telmi-light-blue"] .mobile-nav .nav-item i {
        color: rgba(8, 44, 76, 0.68);
        opacity: 1;
    }

    html[data-theme="telmi-light-blue"] .mobile-nav .nav-item.active,
    html[data-theme="telmi-light-blue"] .mobile-nav .nav-item.active i {
        color: #082c4c;
    }
}

/* --- Papyrus Theme ------------------------------------------------------- */
/*
   An archival paper-and-ink palette. It deliberately avoids themed symbols
   and decorative motifs: the atmosphere comes from texture, restraint, and
   mineral status colours rather than cultural shorthand.
*/
html[data-theme="telmi-papyrus"] {
    color-scheme: light;

    --bg-deep: #e9d9b6;
    --bg-gradient-start: #f5ead2;
    --bg-gradient-mid: #ead6ad;
    --bg-gradient-end: #d6bb86;

    --primary: #302317;
    --primary-glow: #755634;
    --secondary: #80613d;
    --accent: #526747;

    --text: #271d14;
    --text-main: #271d14;
    --text-muted: rgba(39, 29, 20, 0.7);
    --text-faint: rgba(39, 29, 20, 0.48);

    --chat-tick-pending: #5b5144;
    --chat-tick-complete: #4fa878;

    --glass-bg: rgba(250, 244, 228, 0.9);
    --glass-surface: rgba(255, 250, 239, 0.7);
    --glass-border: rgba(78, 55, 31, 0.24);
    --glass-highlight: rgba(255, 255, 255, 0.62);
    --glass-shadow: 0 14px 34px rgba(71, 49, 25, 0.16);
}

html[data-theme="telmi-papyrus"] body {
    background:
        radial-gradient(ellipse at 15% 8%, rgba(255, 255, 255, 0.68), transparent 34%),
        radial-gradient(ellipse at 88% 84%, rgba(137, 101, 54, 0.16), transparent 42%),
        linear-gradient(145deg, #f5ead2 0%, #e7d1a7 53%, #d6bb86 100%);
    color: var(--text-main);
}

html[data-theme="telmi-papyrus"] body::before {
    opacity: 1;
    background:
        repeating-linear-gradient(0deg, rgba(83, 57, 27, 0.018) 0 1px, transparent 1px 5px),
        radial-gradient(circle at 72% 16%, rgba(121, 89, 44, 0.09), transparent 27%),
        radial-gradient(circle at 18% 86%, rgba(121, 89, 44, 0.06), transparent 31%);
}

html[data-theme="telmi-papyrus"] h1,
html[data-theme="telmi-papyrus"] h2,
html[data-theme="telmi-papyrus"] h3,
html[data-theme="telmi-papyrus"] h4,
html[data-theme="telmi-papyrus"] h5,
html[data-theme="telmi-papyrus"] h6,
html[data-theme="telmi-papyrus"] .public-group-title,
html[data-theme="telmi-papyrus"] .mantis-markdown h1,
html[data-theme="telmi-papyrus"] .mantis-markdown h2,
html[data-theme="telmi-papyrus"] .mantis-markdown h3 {
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
    letter-spacing: -0.018em;
}

html[data-theme="telmi-papyrus"] ::selection {
    background: rgba(128, 97, 61, 0.32);
    color: #1e160f;
}

html[data-theme="telmi-papyrus"] .app-sidebar,
html[data-theme="telmi-papyrus"] .chat-input-wrapper {
    background: rgba(244, 234, 211, 0.82);
    border-color: rgba(78, 55, 31, 0.22);
}

@media (max-width: 768px) {
    html[data-theme="telmi-papyrus"] #view-chat.active .chat-input-wrapper {
        background: rgba(244, 234, 211, 0.98);
    }
}

html[data-theme="telmi-papyrus"] .app-sidebar::before {
    background: linear-gradient(180deg, rgba(255, 252, 243, 0.66), rgba(222, 197, 153, 0.2));
}

html[data-theme="telmi-papyrus"] .nav-item,
html[data-theme="telmi-papyrus"] .nav-item i,
html[data-theme="telmi-papyrus"] .text-muted,
html[data-theme="telmi-papyrus"] .text-small,
html[data-theme="telmi-papyrus"] .label {
    color: var(--text-muted);
}

html[data-theme="telmi-papyrus"] .nav-item.active,
html[data-theme="telmi-papyrus"] .nav-item:hover,
html[data-theme="telmi-papyrus"] .mention-item:hover,
html[data-theme="telmi-papyrus"] .mention-item.active {
    background: rgba(125, 94, 54, 0.15);
    border-color: rgba(91, 65, 36, 0.28);
    color: var(--text-main);
    box-shadow: inset 3px 0 0 #80613d;
}

html[data-theme="telmi-papyrus"] .btn,
html[data-theme="telmi-papyrus"] .input,
html[data-theme="telmi-papyrus"] .chat-input,
html[data-theme="telmi-papyrus"] select.input,
html[data-theme="telmi-papyrus"] textarea.input {
    color: var(--text-main);
    background-color: rgba(255, 251, 240, 0.84);
    border-color: rgba(78, 55, 31, 0.26);
}

html[data-theme="telmi-papyrus"] .input::placeholder,
html[data-theme="telmi-papyrus"] .chat-input::placeholder {
    color: rgba(39, 29, 20, 0.46);
}

html[data-theme="telmi-papyrus"] .input:focus,
html[data-theme="telmi-papyrus"] .chat-input:focus {
    border-color: rgba(112, 83, 47, 0.76);
    box-shadow: 0 0 0 4px rgba(128, 97, 61, 0.13);
}

html[data-theme="telmi-papyrus"] .btn-primary,
html[data-theme="telmi-papyrus"] .bubble.user,
html[data-theme="telmi-papyrus"] .app-update-pill {
    background: linear-gradient(135deg, #352719 0%, #795a36 100%);
    color: #fff8e8;
    border-color: rgba(61, 42, 23, 0.7);
    box-shadow: 0 8px 20px rgba(77, 53, 27, 0.22);
}

html[data-theme="telmi-papyrus"] .btn-primary:hover,
html[data-theme="telmi-papyrus"] .app-update-pill:hover {
    background: linear-gradient(135deg, #463321 0%, #8d6a40 100%);
    box-shadow: 0 10px 24px rgba(77, 53, 27, 0.28);
}

/* Keep web search visually distinct from the normal Papyrus chat send action. */
html[data-theme="telmi-papyrus"] .chat-input-wrapper.web-search-mode .composer-submit-btn,
html[data-theme="telmi-papyrus"] .chat-input-wrapper.web-search-mode .composer-submit-btn:hover {
    background: #fff8e8;
    background-image: none;
    color: #352719;
    border-color: rgba(61, 42, 23, 0.72);
    box-shadow: 0 5px 16px rgba(77, 53, 27, 0.2);
}

html[data-theme="telmi-papyrus"] .chat-input-wrapper.web-search-mode .composer-submit-btn .fa-globe {
    color: #352719;
}

html[data-theme="telmi-papyrus"] .bubble.user .bubble-time {
    color: rgba(255, 248, 232, 0.7);
}

html[data-theme="telmi-papyrus"] .bubble.assistant {
    background: rgba(255, 250, 238, 0.84);
    border-color: rgba(78, 55, 31, 0.25);
    color: var(--text-main);
    box-shadow: 0 8px 18px rgba(70, 48, 25, 0.08);
}

html[data-theme="telmi-papyrus"] .bubble.memory-success {
    background: rgba(221, 233, 210, 0.92);
    border-color: rgba(63, 99, 69, 0.38);
    color: #2b5532;
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] .bubble.system.web-search-notice {
    background: rgba(216, 230, 217, 0.94);
    border-color: rgba(63, 112, 73, 0.42);
    border-left-color: #467c4e;
    color: #315d39;
    text-shadow: none;
}

html[data-theme="telmi-papyrus"] .bubble.system,
html[data-theme="telmi-papyrus"] .bubble.system.mission-start {
    background: rgba(243, 217, 210, 0.94);
    border-color: rgba(149, 60, 47, 0.38);
    border-left-color: #a24738;
    color: #6f2e27;
    box-shadow: 4px 4px 0 rgba(112, 46, 39, 0.1);
    text-shadow: none;
}

html[data-theme="telmi-papyrus"] .mission-start-sender {
    color: rgba(111, 46, 39, 0.75);
}

html[data-theme="telmi-papyrus"] .mission-start-chip {
    background: linear-gradient(135deg, rgba(117, 166, 104, 0.18), rgba(201, 224, 177, 0.42));
    border-color: rgba(56, 108, 65, 0.42);
    color: #2f6139;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

html[data-theme="telmi-papyrus"] .mission-start-chip i {
    color: #3d9355;
}

html[data-theme="telmi-papyrus"] .from-badge {
    background: linear-gradient(135deg, rgba(116, 92, 229, 0.12), rgba(29, 181, 207, 0.12));
    border-color: rgba(92, 111, 207, 0.46);
}

html[data-theme="telmi-papyrus"] .from-badge-text {
    background: linear-gradient(90deg, #6955d7, #159eba);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

html[data-theme="telmi-papyrus"] .bubble .bubble-reply {
    color: #674c2f;
    background: #e7d7bb;
    border: 0;
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] .bubble .bubble-reply:hover {
    color: #50391f;
    background: #dcc8a6;
}

html[data-theme="telmi-papyrus"] .group-badge {
    color: #fffdf5;
    background: linear-gradient(135deg, #745ee4 0%, #1aaeca 100%);
    border-color: rgba(255, 255, 255, 0.72);
    box-shadow: 0 5px 14px rgba(70, 95, 184, 0.2);
}

html[data-theme="telmi-papyrus"] .badge-success {
    background: rgba(220, 235, 210, 0.94);
    color: #315d39;
    border-color: rgba(49, 93, 57, 0.38);
}

html[data-theme="telmi-papyrus"] .badge-warn,
html[data-theme="telmi-papyrus"] .badge-warning {
    background: rgba(244, 228, 179, 0.94);
    color: #78561a;
    border-color: rgba(120, 86, 26, 0.38);
}

html[data-theme="telmi-papyrus"] .badge-error {
    background: rgba(242, 216, 207, 0.94);
    color: #913d30;
    border-color: rgba(145, 61, 48, 0.36);
}

html[data-theme="telmi-papyrus"] .badge-neutral,
html[data-theme="telmi-papyrus"] .badge-muted {
    background: rgba(224, 214, 195, 0.9);
    color: #54483a;
    border-color: rgba(84, 72, 58, 0.26);
}

html[data-theme="telmi-papyrus"] .toggle-switch input:checked + .slider,
html[data-theme="telmi-papyrus"] .input-range-gradient::-webkit-slider-thumb,
html[data-theme="telmi-papyrus"] .input-range-gradient::-moz-range-thumb {
    background: linear-gradient(135deg, #3b2b1b, #85633b);
    box-shadow: 0 0 10px rgba(91, 65, 36, 0.2);
}

html[data-theme="telmi-papyrus"] .toggle-switch .slider:before {
    background-color: #fffaf0;
}

html[data-theme="telmi-papyrus"] .chat-input.upsert-mode {
    background-image: linear-gradient(135deg, #fffaf0 0%, #f4e4c6 52%, #e5c996 100%), linear-gradient(135deg, #d8c3a5, #b99568) !important;
    background-clip: padding-box, border-box !important;
    color: #271d14;
    box-shadow: 0 0 15px rgba(128, 97, 61, 0.18);
}

html[data-theme="telmi-papyrus"] .glass-panel,
html[data-theme="telmi-papyrus"] .glass-card-note,
html[data-theme="telmi-papyrus"] .glass-card-calendar,
html[data-theme="telmi-papyrus"] .glass-card-alert,
html[data-theme="telmi-papyrus"] .glass-card-task,
html[data-theme="telmi-papyrus"] .task-list-item.done {
    background: rgba(250, 244, 228, 0.76);
    border-color: rgba(78, 55, 31, 0.22);
    box-shadow: 0 8px 20px rgba(70, 48, 25, 0.08);
}

html[data-theme="telmi-papyrus"] .task-list-item-checkbox {
    accent-color: #4d3822;
}

html[data-theme="telmi-papyrus"] .chat-loading-overlay {
    background: rgba(242, 230, 204, 0.91);
}

html[data-theme="telmi-papyrus"] .chat-loading-spinner {
    background: conic-gradient(from 180deg, #38291a 0%, #a17b45 48%, #4f6748 75%, #38291a 100%);
    box-shadow: 0 0 24px rgba(91, 65, 36, 0.2);
}

html[data-theme="telmi-papyrus"] .chat-loading-label {
    background: linear-gradient(135deg, #38291a 0%, #80613d 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

html[data-theme="telmi-papyrus"] .chat-loading-meta {
    color: rgba(56, 41, 26, 0.68);
}

html[data-theme="telmi-papyrus"] .loader-lg {
    border-top-color: #3b2b1b;
    border-right-color: #8b6940;
}

html[data-theme="telmi-papyrus"] .modal-overlay {
    background: rgba(47, 32, 19, 0.43);
}

html[data-theme="telmi-papyrus"] .file-explorer-modal {
    background: rgba(47, 32, 19, 0.43);
}

html[data-theme="telmi-papyrus"] .file-explorer-panel {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98);
    border-color: rgba(78, 55, 31, 0.31);
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28);
}

html[data-theme="telmi-papyrus"] .file-explorer-header {
    border-bottom-color: rgba(78, 55, 31, 0.22);
}

html[data-theme="telmi-papyrus"] .file-explorer-up {
    color: var(--text-main);
    background: rgba(232, 215, 184, 0.82);
    border-color: rgba(78, 55, 31, 0.25);
}

html[data-theme="telmi-papyrus"] .file-explorer-up:hover {
    background: rgba(220, 200, 166, 0.92);
    border-color: rgba(78, 55, 31, 0.4);
}

html[data-theme="telmi-papyrus"] .modal-box,
html[data-theme="telmi-papyrus"] .ghost-rename-modal-box,
html[data-theme="telmi-papyrus"] .ghost-tools-modal-box,
html[data-theme="telmi-papyrus"] .ghost-creds-modal-box {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98);
    border-color: rgba(78, 55, 31, 0.31);
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28);
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-strip,
html[data-theme="telmi-papyrus"] .ghost-cockpit-panel,
html[data-theme="telmi-papyrus"] .ghost-cockpit-card,
html[data-theme="telmi-papyrus"] .ghost-cockpit-metric,
html[data-theme="telmi-papyrus"] .ghost-cockpit-mini-metric,
html[data-theme="telmi-papyrus"] .ghost-cockpit-empty {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.91);
    border-color: rgba(78, 55, 31, 0.22);
    box-shadow: 0 8px 20px rgba(70, 48, 25, 0.1);
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-strip::before {
    background: linear-gradient(90deg, rgba(128, 97, 61, 0.03), rgba(128, 97, 61, 0.13), rgba(128, 97, 61, 0.03));
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-icon,
html[data-theme="telmi-papyrus"] .ghost-cockpit-mission-nav button:not(:disabled):hover {
    background: linear-gradient(135deg, #372819, #80613d);
    color: #fff8e8;
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-mission-browser {
    background: rgba(255, 251, 240, 0.72);
    border-color: rgba(78, 55, 31, 0.22);
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-mission-head,
html[data-theme="telmi-papyrus"] .ghost-cockpit-mission-status,
html[data-theme="telmi-papyrus"] .ghost-cockpit-metric i {
    color: #624826;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-status-chip.status-active {
    background: #d9e7e9;
    border-color: rgba(43, 92, 112, 0.32);
    color: #245a71;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-status-chip.status-waiting {
    background: #f4e4b8;
    border-color: rgba(128, 94, 29, 0.32);
    color: #7d591a;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-status-chip.status-idle {
    background: #e5dcc7;
    border-color: rgba(84, 72, 58, 0.25);
    color: #51483d;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-status-chip.status-blocked {
    background: #f1d8cf;
    border-color: rgba(145, 61, 48, 0.3);
    color: #963e30;
}

html[data-theme="telmi-papyrus"] .ghost-cockpit-status-chip.status-done {
    background: #dce9d2;
    border-color: rgba(63, 99, 69, 0.3);
    color: #416345;
}

html[data-theme="telmi-papyrus"] .ghost-card,
html[data-theme="telmi-papyrus"] .mantis-module-card,
html[data-theme="telmi-papyrus"] .mantis-instance-card,
html[data-theme="telmi-papyrus"] .mantis-instance-cron-panel {
    color: var(--text-main);
    background: linear-gradient(145deg, rgba(255, 250, 239, 0.94), rgba(239, 223, 188, 0.9)) !important;
    border-color: rgba(78, 55, 31, 0.24) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 14px 32px rgba(70, 48, 25, 0.11) !important;
}

html[data-theme="telmi-papyrus"] #ghost-list .ghost-card-name,
html[data-theme="telmi-papyrus"] #ghost-list .ghost-id-line,
html[data-theme="telmi-papyrus"] .mantis-markdown,
html[data-theme="telmi-papyrus"] .mantis-markdown strong,
html[data-theme="telmi-papyrus"] .mantis-markdown h1,
html[data-theme="telmi-papyrus"] .mantis-markdown h2,
html[data-theme="telmi-papyrus"] .mantis-markdown h3 {
    color: var(--text-main);
}

html[data-theme="telmi-papyrus"] .view-section h3[style*="color:white"],
html[data-theme="telmi-papyrus"] .view-section h4[style*="color:white"],
html[data-theme="telmi-papyrus"] #ghost-list [style*="color:white"],
html[data-theme="telmi-papyrus"] .mantis-instance-card [style*="color:white"],
html[data-theme="telmi-papyrus"] .mantis-instance-cron-panel [style*="color:white"] {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #ghost-list .ghost-card-name i[style*="color:white"] {
    color: #4b3520 !important;
}

html[data-theme="telmi-papyrus"] .memory-upload-error-item,
html[data-theme="telmi-papyrus"] .memory-upload-chunk.failed {
    background: rgba(242, 215, 207, 0.92);
    border-color: rgba(149, 60, 47, 0.34);
    color: #8b382d;
}

html[data-theme="telmi-papyrus"] #ghost-list .btn,
html[data-theme="telmi-papyrus"] #ghost-list .ghost-agentic-toggle,
html[data-theme="telmi-papyrus"] #ghost-list .ghost-autonomy-toggle,
html[data-theme="telmi-papyrus"] .ghost-name-edit,
html[data-theme="telmi-papyrus"] .mantis-doc-tab,
html[data-theme="telmi-papyrus"] .mantis-brand-icon {
    color: var(--text-main);
    background: rgba(255, 251, 240, 0.78);
    border-color: rgba(78, 55, 31, 0.22);
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] #ghost-list .btn:hover,
html[data-theme="telmi-papyrus"] .ghost-name-edit:hover {
    background: rgba(230, 209, 168, 0.78);
    border-color: rgba(78, 55, 31, 0.42);
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] .ghost-observation-toggle.is-on,
html[data-theme="telmi-papyrus"] .mantis-doc-tab.active {
    color: #fff8e8;
    background: linear-gradient(135deg, #38291a, #80613d);
    border-color: rgba(61, 42, 23, 0.68);
    box-shadow: none;
}

html[data-theme="telmi-papyrus"] .mantis-readme-collapsed::after {
    background: linear-gradient(180deg, rgba(250, 244, 228, 0), rgba(250, 244, 228, 0.98));
}

html[data-theme="telmi-papyrus"] .mantis-markdown blockquote {
    color: var(--text-muted);
    border-left-color: #80613d;
    background: rgba(231, 211, 172, 0.34);
}

html[data-theme="telmi-papyrus"] .mantis-markdown pre,
html[data-theme="telmi-papyrus"] .mantis-markdown code {
    color: #3e2c19;
    background: rgba(224, 207, 172, 0.54);
    border-color: rgba(78, 55, 31, 0.2);
}

/* Papyrus-only contrast pass for inline dark-theme component styles. */
html[data-theme="telmi-papyrus"] .mention-menu {
    background: rgba(250, 244, 228, 0.98);
    border-color: rgba(78, 55, 31, 0.34);
    box-shadow: 0 16px 40px rgba(55, 37, 18, 0.24);
}

html[data-theme="telmi-papyrus"] .mention-item {
    color: var(--text-main);
    border-bottom-color: rgba(78, 55, 31, 0.14);
}

html[data-theme="telmi-papyrus"] .mention-item-name {
    color: var(--text-main);
}

html[data-theme="telmi-papyrus"] .mention-item-type {
    color: #765b3b;
}

html[data-theme="telmi-papyrus"] .mention-item:hover,
html[data-theme="telmi-papyrus"] .mention-item.active {
    background: rgba(218, 195, 153, 0.5);
    border-color: rgba(128, 97, 61, 0.4);
    box-shadow: inset 3px 0 0 #80613d;
}

html[data-theme="telmi-papyrus"] .glass-card-task p {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] .public-group-card {
    color: var(--text-main);
    background: linear-gradient(145deg, rgba(255, 252, 243, 0.96), rgba(241, 225, 192, 0.9)) !important;
    border-color: rgba(108, 81, 46, 0.25) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.76), 0 12px 28px rgba(70, 48, 25, 0.1);
}

html[data-theme="telmi-papyrus"] .public-group-card .public-group-desc a {
    color: #287c9c;
}

html[data-theme="telmi-papyrus"] #view-profile #btn-memory-manager,
html[data-theme="telmi-papyrus"] #view-profile #btn-file-explorer,
html[data-theme="telmi-papyrus"] #view-profile #btn-clear-chat-history,
html[data-theme="telmi-papyrus"] #view-profile #btn-clear-cache,
html[data-theme="telmi-papyrus"] #view-profile #btn-logout,
html[data-theme="telmi-papyrus"] #view-profile button[onclick="openLegalModal()"],
html[data-theme="telmi-papyrus"] #view-profile #btn-memory-manager i,
html[data-theme="telmi-papyrus"] #view-profile #btn-file-explorer i,
html[data-theme="telmi-papyrus"] #view-profile #btn-clear-chat-history i,
html[data-theme="telmi-papyrus"] #view-profile #btn-clear-cache i,
html[data-theme="telmi-papyrus"] #view-profile #btn-logout i,
html[data-theme="telmi-papyrus"] #view-profile button[onclick="openLegalModal()"] i {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #onb-question-label,
html[data-theme="telmi-papyrus"] #onb-question-label .text-muted {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #onb-card textarea#onb-answer {
    color: var(--text-main) !important;
    background: rgba(255, 251, 240, 0.9) !important;
    border-color: rgba(78, 55, 31, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #group-context-menu {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98) !important;
    border-color: rgba(78, 55, 31, 0.32) !important;
    box-shadow: 0 16px 40px rgba(55, 37, 18, 0.25) !important;
}

html[data-theme="telmi-papyrus"] #group-context-menu > div:first-child {
    background: rgba(231, 211, 172, 0.5) !important;
    border-bottom-color: rgba(78, 55, 31, 0.18) !important;
}

html[data-theme="telmi-papyrus"] #group-context-menu .nav-item,
html[data-theme="telmi-papyrus"] #group-context-menu .nav-item i,
html[data-theme="telmi-papyrus"] #group-context-menu .nav-item span {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #group-context-menu .nav-item > div:last-child {
    border-color: rgba(78, 55, 31, 0.46) !important;
}

html[data-theme="telmi-papyrus"] #ghost-train-modal > .glass-panel {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98) !important;
    border-color: rgba(78, 55, 31, 0.31) !important;
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #ghost-train-modal #gt-content-area > div[style*="border-bottom"],
html[data-theme="telmi-papyrus"] #ghost-tools-modal .ghost-tools-modal-box > div[style*="border-bottom"] {
    background: rgba(231, 211, 172, 0.58) !important;
    border-bottom-color: rgba(78, 55, 31, 0.2) !important;
}

html[data-theme="telmi-papyrus"] #ghost-train-modal [style*="background:rgba(255,255,255,0.05)"],
html[data-theme="telmi-papyrus"] #ghost-tools-modal [style*="background:rgba(255,255,255,0.05)"],
html[data-theme="telmi-papyrus"] #ghost-tools-modal .ghost-tools-section,
html[data-theme="telmi-papyrus"] #ghost-tools-modal .ghost-tools-chip,
html[data-theme="telmi-papyrus"] #ghost-tools-modal .ghost-tools-preset {
    background: rgba(255, 251, 240, 0.76) !important;
    border-color: rgba(78, 55, 31, 0.22) !important;
}

html[data-theme="telmi-papyrus"] #ghost-train-modal [style*="color:rgba(255"],
html[data-theme="telmi-papyrus"] #ghost-tools-modal [style*="color:rgba(255"] {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #memory-modal > .modal {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98) !important;
    border-color: rgba(78, 55, 31, 0.31) !important;
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #memory-upload-info-modal .memory-upload-info-card {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98) !important;
    border-color: rgba(78, 55, 31, 0.31) !important;
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #memory-upload-info-modal .memory-upload-info-example {
    color: var(--text-main);
    background: rgba(255, 251, 240, 0.78) !important;
    border-color: rgba(78, 55, 31, 0.24) !important;
}

html[data-theme="telmi-papyrus"] #memory-modal [style*="background:rgba(255,255,255,0.03)"],
html[data-theme="telmi-papyrus"] #memory-modal [style*="background:rgba(255,255,255,0.02)"],
html[data-theme="telmi-papyrus"] #memory-modal #rag-list > .glass-panel {
    background: rgba(255, 251, 240, 0.78) !important;
    border-color: rgba(78, 55, 31, 0.2) !important;
    box-shadow: none !important;
}

html[data-theme="telmi-papyrus"] #memory-modal [style*="border-top:1px solid rgba(255,255,255"],
html[data-theme="telmi-papyrus"] #memory-modal [style*="border-bottom:1px solid rgba(255,255,255"] {
    border-color: rgba(78, 55, 31, 0.2) !important;
}

html[data-theme="telmi-papyrus"] #legal-modal > .glass-panel {
    color: var(--text-main);
    background: rgba(250, 244, 228, 0.98) !important;
    border-color: rgba(78, 55, 31, 0.31) !important;
    box-shadow: 0 24px 64px rgba(55, 37, 18, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #legal-modal > .glass-panel > div[style*="border-bottom"] {
    background: rgba(231, 211, 172, 0.58) !important;
    border-bottom-color: rgba(78, 55, 31, 0.2) !important;
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-select {
    color: var(--text-main) !important;
    background: rgba(255, 251, 240, 0.94) !important;
    border-color: rgba(78, 55, 31, 0.28) !important;
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-content {
    color: var(--text-main) !important;
    background: linear-gradient(145deg, rgba(255, 252, 243, 0.72), rgba(239, 221, 183, 0.34));
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-content :is(p, li, strong, em, span, blockquote, td, th) {
    color: var(--text-main) !important;
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-content :is(h1, h2, h3, h4) {
    color: #322216 !important;
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-content a {
    color: #287c9c !important;
    text-decoration-color: rgba(40, 124, 156, 0.38);
}

html[data-theme="telmi-papyrus"] #legal-modal #legal-content blockquote,
html[data-theme="telmi-papyrus"] #legal-modal #legal-content table {
    border-color: rgba(78, 55, 31, 0.24);
    background: rgba(255, 251, 240, 0.48);
}

/* Board dialogs use inline dark shells, so give the whole Board flow its own parchment treatment. */
html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #edit-board-modal, #recurring-schedule-modal, #create-board-modal) {
    background: rgba(47, 32, 19, 0.5) !important;
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #edit-board-modal, #recurring-schedule-modal, #create-board-modal) > .glass-panel {
    color: var(--text-main);
    background:
        linear-gradient(145deg, rgba(255, 252, 243, 0.98), rgba(241, 224, 185, 0.96)) !important;
    border-color: rgba(78, 55, 31, 0.33) !important;
    box-shadow: 0 26px 70px rgba(55, 37, 18, 0.36) !important;
}

html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #edit-board-modal, #recurring-schedule-modal, #create-board-modal) > .glass-panel > div[style*="border-bottom"] {
    border-bottom-color: rgba(78, 55, 31, 0.2) !important;
}

html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #edit-board-modal, #recurring-schedule-modal, #create-board-modal) > .glass-panel > div[style*="background:rgba(0,0,0"] {
    background: linear-gradient(135deg, rgba(231, 211, 172, 0.76), rgba(246, 235, 208, 0.84)) !important;
}

html[data-theme="telmi-papyrus"] :is(#task-list-modal, #recurring-schedule-modal) > .glass-panel > div[style*="border-top"] {
    background: rgba(239, 222, 185, 0.5) !important;
    border-top-color: rgba(78, 55, 31, 0.2) !important;
}

html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #recurring-schedule-modal) :is(#calendar-list, #task-list-items, #recurring-schedule-body) {
    color: var(--text-main);
    background: linear-gradient(180deg, rgba(255, 252, 243, 0.34), rgba(238, 217, 177, 0.2));
}

html[data-theme="telmi-papyrus"] #calendar-modal #calendar-list > div[style*="background:rgba(255,255,255,0.05)"],
html[data-theme="telmi-papyrus"] #task-list-modal .task-list-item,
html[data-theme="telmi-papyrus"] #recurring-schedule-modal #recurring-schedule-body .glass-panel {
    color: var(--text-main);
    background: rgba(255, 251, 240, 0.78) !important;
    border-color: rgba(78, 55, 31, 0.22) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 6px 16px rgba(70, 48, 25, 0.06) !important;
}

html[data-theme="telmi-papyrus"] #task-list-modal .task-list-item.done {
    background: rgba(221, 233, 210, 0.72) !important;
    border-color: rgba(63, 99, 69, 0.32) !important;
}

html[data-theme="telmi-papyrus"] #task-list-modal .task-list-item-handle,
html[data-theme="telmi-papyrus"] #recurring-schedule-modal #recurring-schedule-body [style*="color:white"] {
    color: #5c4630 !important;
}

html[data-theme="telmi-papyrus"] :is(#calendar-modal, #task-list-modal, #recurring-schedule-modal, #create-board-modal) > .glass-panel > button.btn-ghost {
    color: #4e371f !important;
    background: rgba(255, 251, 240, 0.78) !important;
    border-color: rgba(78, 55, 31, 0.26) !important;
}

html[data-theme="telmi-papyrus"] #create-board-modal #create-board-error {
    color: #913d30 !important;
}

html[data-theme="telmi-papyrus"] ::-webkit-scrollbar-track {
    background: rgba(225, 204, 166, 0.62);
}

html[data-theme="telmi-papyrus"] ::-webkit-scrollbar-thumb {
    background: rgba(105, 77, 43, 0.56);
    border-color: rgba(250, 244, 228, 0.82);
}

@media (max-width: 768px) {
    html[data-theme="telmi-papyrus"] .mobile-nav {
        background: rgba(245, 234, 211, 0.94);
        border-top-color: rgba(78, 55, 31, 0.24);
        box-shadow: 0 -8px 24px rgba(70, 48, 25, 0.16);
    }

    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item,
    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item i {
        color: #59432c;
        opacity: 1;
    }

    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item.active,
    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item.active i {
        color: #312317;
        text-shadow: 0 2px 8px rgba(112, 83, 47, 0.18);
    }

    /* Mobile tabs do not have enough room for the desktop inset active bar. */
    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item.active {
        position: relative;
        background: transparent !important;
        box-shadow: none;
    }

    html[data-theme="telmi-papyrus"] .mobile-nav .nav-item.active::after {
        content: "";
        position: absolute;
        left: calc(50% - 14px);
        bottom: 1px;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #312317;
        box-shadow: 0 1px 3px rgba(78, 55, 31, 0.28);
    }

}

/* Transparent text mirror: only contact backgrounds cover the native textarea. */
.contact-highlights {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    box-sizing: border-box;
    border-style: solid;
    border-color: transparent;
    border-radius: var(--radius-md);
    white-space: pre-wrap;
    overflow-wrap: break-word;
    overflow: hidden;
    pointer-events: none;
    color: transparent !important;
}
.contact-highlights[hidden] { display: none !important; }
.contact-highlights mark {
    color: transparent !important;
    background: rgba(56, 189, 248, 0.24);
    border-radius: 3px;
    padding: 0;
    font: inherit;
}

/* Keep native board date controls aligned with each theme's calendar palette. */
:is(html[data-theme="telmi-default"], html[data-theme="telmi-business"])
:is(#create-board-modal, #edit-board-modal) input[type="datetime-local"] {
    color-scheme: dark;
}

:is(html[data-theme="telmi-papyrus"], html[data-theme="telmi-light-blue"], html[data-theme="telmi-neon-afterlife"])
:is(#create-board-modal, #edit-board-modal) input[type="datetime-local"] {
    color-scheme: light;
}
