/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Custom Properties / Variables for Theming */
/* ========================================
   TRIVIO COLOR SYSTEM (UPSTOX-INSPIRED)
   Only 3 colors - use these everywhere
   ======================================== */
:root {
    /* === CORE TOKENS (use these) === */
    --white: #FFFFFF;
    --purple-dark: #4B2A7A;
    /* Brand / Primary actions only */
    --purple-light: #EEE9F7;
    /* Structure / Soft emphasis */
    --purple-border: #E3DBF3;
    /* Subtle borders */

    /* === LEGACY ALIASES (for backwards compatibility) === */
    --color-primary: #4B2A7A;
    --color-primary-hover: #3D2263;
    --color-primary-rgb: 75, 42, 122;
    --color-accent: #4B2A7A;
    --color-accent-rgb: 75, 42, 122;

    /* === BACKGROUND SYSTEM === */
    --bg-app: #FFFFFF;
    --bg-section: #EEE9F7;
    --bg-card: #FFFFFF;
    --bg-body: #FFFFFF;
    --bg-primary: #FFFFFF;
    --bg-secondary: #EEE9F7;
    --bg-glass: rgba(255, 255, 255, 0.98);

    /* === TEXT COLORS === */
    --text-primary: #1F1F1F;
    --text-secondary: #6B6B6B;
    --text-tertiary: #9A9A9A;
    --text-muted: #9A9A9A;

    /* === UI / BORDERS === */
    --border-color: #E6E6E6;
    --border-default: #E6E6E6;
    --focus-ring: rgba(75, 42, 122, 0.2);
    --disabled: #CFC7DD;
    --input-bg: #FFFFFF;

    /* === LEGACY COLOR ALIASES (for backwards compatibility) === */
    --primary-color: #5B2D8B;
    /* Maps to --color-primary */
    --primary-rgb: 91, 45, 139;
    --primary-hover: #4A2474;
    /* Maps to --color-primary-hover */
    --secondary-color: #7B3FE4;
    /* Maps to --color-accent */
    --accent-color: #7B3FE4;
    /* Maps to --color-accent */

    /* === STATUS COLORS (unchanged) === */
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --error-color: #EF4444;

    /* === SHADOWS === */
    --shadow-sm: 0px 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0px 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0px 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-glass: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-primary: 0 4px 15px rgba(91, 45, 139, 0.25);

    /* === BORDER RADIUS === */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    /* === TRANSITIONS === */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* === LAYOUT === */
    --header-height: 100px;
    --bottom-nav-height: 80px;
}

@media (max-width: 768px) {
    :root {
        --header-height: 90px;
        /* Reduced for mobile */
    }

    /* Mobile tab content padding */
    .tab-content {
        padding: 0 16px calc(var(--bottom-nav-height) + 120px);
    }

    /* Mobile global fade - more subtle */
    .app-container::after {
        height: 100px;
    }

    /* Mobile top fade - smaller */
    .app-container::before {
        height: 80px;
    }
}

:root {
    height: auto;
}

/* CRITICAL: Force scrollbar to always reserve space to prevent layout shift */
html {
    min-height: 100%;
    height: auto;
    overflow-y: scroll;
    /* Always show scrollbar track */
    scrollbar-gutter: stable;
    /* Reserve space for scrollbar */
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App container - consistent layout shell */
.app-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Ensure Home and Automations tabs can scroll */
body:has(#home.content.active),
body:has(#automations.content.active) {
    overflow-y: auto !important;
    height: auto !important;
}

body:has(#home.content.active) .app-container,
body:has(#automations.content.active) .app-container {
    overflow-y: auto !important;
    height: auto !important;
}

.main-content-centered {
    width: 100%;
    max-width: 100%;
    padding: var(--header-height) 0 calc(var(--bottom-nav-height) + 40px) 0;
    /* Dynamic bottom padding */
    margin: 0;
}

/* Tab Content Container */
.tab-content {
    max-width: 1200px;
    margin: 16px auto;
    /* Reduced from 30px - tighter layout */
    /* Bottom padding: bottom-nav + fade height + buffer */
    padding: 0 24px calc(var(--bottom-nav-height) + 160px);
    overflow: visible;
}

/* Full width for all tabs except chat */
.tab-content:has(#home.active),
.tab-content:has(#messages.active),
.tab-content:has(#files.active),
.tab-content:has(#productivity.active),
.tab-content:has(#profile.active),
.tab-content:has(#settings.active) {
    max-width: 1400px;
}

.content {
    display: none;
    background: transparent;
    padding: 40px;
    border-radius: 0;
    box-shadow: none;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    overflow: visible;
    min-height: calc(100vh - 140px);
}

.content.active {
    display: block;
}

.content h2 {
    color: var(--text-primary);
    margin-bottom: 24px;
    font-size: 2em;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.content p {
    color: var(--text-secondary);
    font-size: 1.1em;
    line-height: 1.7;
}

/* Shimmer Effect for Loading/Progress */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }

    100% {
        background-position: 1000px 0;
    }
}

.shimmer {
    animation: shimmer 2s infinite linear;
    background: linear-gradient(to right, var(--bg-app) 4%, var(--bg-section) 25%, var(--bg-app) 36%);
    background-size: 1000px 100%;
}

/* Glow Effect for Buttons */
.btn-primary {
    position: relative;
    overflow: hidden;
}

.btn-primary::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 60%);
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s, transform 0.3s;
}

.btn-primary:hover::after {
    opacity: 1;
    transform: scale(1);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: rgba(var(--color-primary-rgb), 0.4);
    border-radius: 5px;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--color-primary-rgb), 0.6);
}

/* ==================== GLOBAL TOP FADE OVERLAY ==================== */
/* Applies to ALL tabs - content fades gracefully below the header */
/* Header is at: top: 20px, height: ~72px, so bottom of header is at ~92px from top */

.app-container::before {
    content: '';
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    height: 100px;
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 1) 0%,
            rgba(255, 255, 255, 0.8) 60%,
            rgba(255, 255, 255, 0.3) 85%,
            rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    z-index: 900;
    /* Below header (1000), above content */
}

/* Hide top fade on Chat and Agents tabs since they have their own layout */
body:has(#chat.content.active) .app-container::before,
body:has(#agents.content.active) .app-container::before {
    display: none;
}

/* ==================== GLOBAL BOTTOM FADE OVERLAY ==================== */
/* Applies to ALL tabs - content fades gracefully above bottom navigation */
/* Bottom nav is at: bottom: 24px, height: 68px, so top of nav is at ~92px from bottom */

.app-container::after {
    content: '';
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 120px;
    background: linear-gradient(to top,
            rgba(255, 255, 255, 1) 0%,
            rgba(255, 255, 255, 1) 40%,
            rgba(255, 255, 255, 0.7) 65%,
            rgba(255, 255, 255, 0.3) 85%,
            rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    z-index: 1500;
    /* Above content, below bottom nav (2000) */
}

/* Hide global fade on Chat and Agents tabs since they have their own layout */
body:has(#chat.content.active) .app-container::after,
body:has(#agents.content.active) .app-container::after {
    display: none;
}


/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px !important;
    width: fit-content;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* =====================================================
   FORCED COLOR OVERRIDES - DO NOT REMOVE
   This section ensures the Upstox-style color system
   ===================================================== */

/* STEP 1: Force all page backgrounds to WHITE */
html,
body,
.app-container,
.main-content-centered,
.page-content,
.tab-content,
#home.content,
#chat.content,
#agents.content,
#automations.content,
.modern-chat-container,
.modern-messages-wrapper,
.agents-marketplace,
.agents-sidebar,
.agent-workspace,
.modern-chat-sidebar {
    background: #FFFFFF !important;
    background-color: #FFFFFF !important;
    background-image: none !important;
}

/* Force header to white */
.header-surface {
    background: #FFFFFF !important;
    background-image: none !important;
}

/* STEP 2: Mission Control title - section label style */
.mission-title {
    color: var(--purple-dark) !important;
    -webkit-text-fill-color: var(--purple-dark) !important;
    background: none !important;
    background-clip: unset !important;
    -webkit-background-clip: unset !important;
    font-weight: 600 !important;
    font-size: 1.75rem !important;
    opacity: 0.6 !important;
}

.mission-title-area {
    margin-top: 32px !important;
    margin-left: 16px !important;
    text-align: left !important;
}

/* STEP 3: Force light purple for structure elements */
.progress-ring-circle {
    stroke: var(--purple-light) !important;
}

/* User message bubbles - light purple */
.message-wrapper.user .message-bubble,
.agent-message.user {
    background: var(--purple-light) !important;
    background-color: var(--purple-light) !important;
    color: var(--text-primary) !important;
}

/* Template buttons - light purple */
.template-btn-create {
    background: var(--purple-light) !important;
    background-color: var(--purple-light) !important;
    color: var(--purple-dark) !important;
    border: 1px solid var(--purple-border) !important;
}

/* AI Insights buttons - light purple */
.ai-btn.primary {
    background: var(--purple-light) !important;
    background-image: none !important;
    color: var(--text-primary) !important;
}

/* Quick action cards - light purple background */
.quick-action-card:first-child,
.plan-my-day-card {
    background: var(--purple-light) !important;
}

/* AI Insights container - light purple */
.ai-card {
    background: var(--purple-light) !important;
    background-image: none !important;
}

/* Hero section - light purple */
.hero-main {
    background: var(--purple-light) !important;
}

/* Hero greeting text - dark neutral, NOT purple */
.hero-greeting-text {
    color: var(--text-primary) !important;
    opacity: 1 !important;
}

/* STEP 4: Dark purple ONLY for these action elements */
/* New Chat, Create Agent, Create Workflow, FAB, Active nav */
.sidebar-cta .create-agent-btn,
.chat-new-btn,
.new-chat-btn,
.bottom-nav-fab,
.primary-action-btn {
    background: var(--purple-dark) !important;
    color: #FFFFFF !important;
}

/* Bottom nav active state */
.bottom-nav-item.active {
    color: var(--purple-dark) !important;
}

/* Trivio logo */
.logo-text {
    color: var(--purple-dark) !important;
}