/* LLM-enabled Service Function Monitoring Analyzer - Main Stylesheet */

/* Prevent layout shift during font loading */
@font-face {
    font-family: 'Outfit';
    font-display: swap; /* This helps prevent layout shift */
}

:root {
    --primary: #5691E3;
    --secondary: #7656E3;
    --accent-1: #5664E3;
    --accent-2: #56BDE3;
    --accent-3: #A456E3;
    --bg-main: #D2D4E5;
    --text-dark: #2c3e50;
    --text-light: #5a6c7d;
    --card-bg: rgba(255, 255, 255, 0.9);
    --border-light: rgba(86, 145, 227, 0.2);
    /* Layout constants */
    --nav-height: 76px;
    --footer-height: 64px;
}

* {
    box-sizing: border-box;
}

/* Prevent flash of unstyled content */
body {
    background: var(--bg-main);
    color: var(--text-dark);
    font-family: 'Outfit', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    padding-top: var(--nav-height); /* Account for fixed navbar */
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

body.loaded {
    opacity: 1;
}

/* Navigation Styles */
.navbar {
    background: var(--card-bg) !important;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 0.75rem 0;
    min-height: var(--nav-height); /* Prevent height jumping */
}

.navbar-brand {
    font-family: 'Space Grotesk', 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    min-height: 60px; /* Ensure consistent height */
    display: flex !important;
    align-items: center !important;
}

.navbar-logo {
    height: 56px;
    width: auto;
    transition: transform 0.3s ease;
    vertical-align: middle;
}

.navbar-logo:hover {
    transform: scale(1.05);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-line-1 {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 600;
    color: #000;
}

.brand-line-2 {
    font-size: clamp(0.7rem, 2vw, 0.85rem);
    font-weight: 500;
    color: var(--text-light);
    margin-top: -2px;
}

/* Media queries for fine-tuning */
@media (max-width: 992px) {
    .navbar .container {
        padding: 0 1rem; /* More padding on medium screens */
    }
    
    .navbar-brand {
        flex-shrink: 1; /* Allow brand to shrink if needed */
    }
}

@media (max-width: 768px) {
    .brand-text {
        line-height: 1.1;
    }
    
    .brand-line-1 {
        font-size: 0.85rem;
    }
    
    .brand-line-2 {
        font-size: 0.7rem;
        margin-top: -1px;
    }
    
    .navbar .container {
        padding: 0 0.75rem;
    }
    
    /* Reduce logo size on tablets */
    .navbar-logo {
        height: 48px;
    }
}

@media (max-width: 576px) {
    .brand-text {
        display: none; /* Hide text on very small screens to save space */
    }
    
    .navbar .container {
        padding: 0 0.5rem;
    }
    
    /* Further reduce logo size on phones */
    .navbar-logo {
        height: 40px;
    }
    
    .navbar-brand {
        min-height: 40px;
    }
}

@media (min-width: 1200px) {
    .brand-line-1 {
        font-size: 1.1rem;
    }
    
    .brand-line-2 {
        font-size: 0.85rem;
    }
    
    .navbar .container {
        padding: 0 1.5rem; /* More breathing room on large screens */
    }
}

.navbar-nav .nav-link {
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    border-radius: 20px;
    margin: 0 0.25rem;
}

.navbar-nav .nav-link:hover {
    background: rgba(86, 145, 227, 0.1);
    color: var(--primary) !important;
}

.language-toggle {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: 25px;
    padding: 0.25rem;
    margin-left: 1rem;
}

.language-toggle button {
    background: none;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    cursor: pointer;
}

.language-toggle button.active {
    background: var(--primary);
    color: white;
}

.language-toggle button:not(.active):hover {
    background: rgba(86, 145, 227, 0.1);
    color: var(--primary);
}

/* Button Styles */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    padding: 0.75rem 1.8rem;
    border-radius: 25px;
    font-family: 'Outfit', 'Space Grotesk', sans-serif;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(86, 145, 227, 0.4);
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-outline-primary {
    border: 2px solid var(--primary);
    color: var(--primary);
    border-radius: 25px;
    padding: 0.7rem 1.8rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-outline-primary:hover {
    background: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(86, 145, 227, 0.3);
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, 
        rgba(86, 145, 227, 0.1) 0%, 
        rgba(118, 86, 227, 0.1) 50%, 
        rgba(210, 212, 229, 0.3) 100%);
    padding: 8rem 0 5rem;
    min-height: 80vh;
    display: flex;
    align-items: center;
    position: relative;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 20% 50%, rgba(86, 145, 227, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(118, 86, 227, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.hero-content {
    position: relative;
    z-index: 1;
}

.hero-logo {
    position: relative;
    z-index: 1;
}

.hero-logo-img {
    width: 280px;
    height: auto;
    max-width: 100%;
    animation: heroLogoFloat 3s ease-in-out infinite;
    filter: drop-shadow(0 10px 20px rgba(86, 145, 227, 0.2));
    transition: transform 0.3s ease;
}

.hero-logo-img:hover {
    transform: scale(1.05);
}

@keyframes heroLogoFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.gradient-text {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Hero Title Styles */
.hero h1 {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.hero .display-4 {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-weight: 700;
    letter-spacing: -0.03em;
}

/* Section Title Styles */
.section-title {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Feature Card Titles */
.section-card h5 {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Card Styles */
.section-card {
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--border-light);
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
    margin-bottom: 2rem;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.section-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.15);
}

/* Ensure feature cards have equal height and buttons align at bottom */
.section-card.h-100 {
    height: 100%;
    min-height: 320px; /* Minimum height for consistency */
}

.section-card .mt-auto {
    margin-top: auto !important;
    padding-top: 1rem; /* Add some spacing above the button */
}

/* Feature card content spacing */
.section-card .text-muted {
    flex-grow: 1; /* Allow description to expand and push button to bottom */
    margin-bottom: 0;
}

/* Responsive adjustments for feature cards */
@media (max-width: 768px) {
    .section-card.h-100 {
        min-height: 280px; /* Slightly smaller on mobile */
        margin-bottom: 1.5rem;
    }
    
    .section-card .mt-auto {
        padding-top: 0.75rem;
    }
}

/* Ensure consistent button spacing across all feature cards */
.section-card .btn {
    white-space: nowrap; /* Prevent button text wrapping */
    min-width: 120px; /* Consistent button width */
}

.feature-icon {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
    margin: 0 auto 1.5rem;
    transition: all 0.3s ease;
}

.feature-icon:hover {
    transform: scale(1.1) rotate(5deg);
}

/* Chat Section */
.chat-window {
    height: 450px;
    overflow-y: auto;
    padding: 1.5rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 15px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-light);
}

.message-bubble {
    max-width: 85%;
    margin-bottom: 1.2rem;
    padding: 1rem 1.4rem;
    border-radius: 20px;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    line-height: 1.5;
    animation: messageSlide 0.3s ease-out;
    position: relative;
}

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

.user-message {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 5px;
}

.ai-message {
    background: white;
    border: 1px solid var(--border-light);
    color: var(--text-dark);
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* Table Styles */
.metrics-table {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.table th {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    font-family: 'Space Grotesk', 'JetBrains Mono', monospace;
    font-weight: 600;
    letter-spacing: -0.01em;
    padding: 1rem 0.75rem;
}

.table td {
    padding: 0.9rem 0.75rem;
    vertical-align: middle;
}

/* Form Styles */
.form-control, .form-select {
    border-radius: 12px;
    border: 2px solid var(--border-light);
    padding: 0.8rem 1.2rem;
    transition: all 0.3s ease;
}

/* Chat Input Textarea Specific Styles */
#messageInput {
    min-height: 48px;
    max-height: 120px;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
    transition: height 0.2s ease;
}

#messageInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(86, 145, 227, 0.25);
}

/* Chat form alignment */
#chatForm {
    align-items: flex-end;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(86, 145, 227, 0.15);
    transform: translateY(-1px);
}

/* Section Titles */
.section-title {
    color: var(--text-dark);
    font-weight: 700;
    margin-bottom: 3.5rem;
    text-align: center;
    position: relative;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 2px;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(86, 145, 227, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
}

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

/* Language Switch Transitions */
[data-lang] {
    transition: opacity 0.3s ease;
}

.fade-transition {
    opacity: 0.7;
}

/* Chat Page Specific Styles */
.max-w-5xl {
    max-width: 64rem; /* 1024px equivalent to Tailwind's max-w-5xl */
}

/* Enhanced Chat Layout */
.chat-window {
    height: 360px; /* Reduced from 450px for better fit */
    overflow-y: auto;
    padding: 1.5rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 15px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-light);
}

/* Enhanced Responsive Design */
@media (max-width: 1200px) {
    .container {
        max-width: 100%;
        padding: 0 2rem;
    }
    
    .max-w-5xl {
        max-width: 100%;
    }
}

@media (max-width: 992px) {
    .hero {
        padding: 6rem 0 4rem;
        text-align: center;
    }

    .hero-content {
        margin-bottom: 2rem;
    }

    .language-toggle {
        margin-left: 0;
        margin-top: 1rem;
    }

    .navbar-nav {
        text-align: center;
        padding-top: 1rem;
    }

    .feature-icon {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }

    .navbar-logo {
        height: 36px;
    }

    .hero-logo-img {
        width: 200px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    .hero {
        padding: 5rem 0 3rem;
        min-height: 70vh;
    }

    .hero h1 {
        font-size: 2.2rem;
        line-height: 1.3;
    }

    .hero .lead {
        font-size: 1rem;
    }

    .message-bubble {
        max-width: 95%;
        padding: 0.8rem 1.2rem;
    }

    .chat-window {
        height: 280px; /* Further reduced for mobile */
        padding: 1rem;
    }

    .btn {
        width: 100%;
        margin-bottom: 0.8rem;
        padding: 0.8rem 1.5rem;
    }

    .btn:last-child {
        margin-bottom: 0;
    }

/* ========================= */
/* Navbar/Auth Controls      */
/* (moved from base.html)    */
/* ========================= */

/* Auth Slot Container - Mutually Exclusive Rendering */
.auth-slot {
    display: flex;
    align-items: center;
    min-height: 36px; /* Consistent height to prevent layout shift */
    transition: opacity 0.2s ease;
}

/* Ensure smooth transitions when content changes */
.auth-slot > * {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading state styling */
#authLoading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#authLoading .spinner-border {
    width: 1rem;
    height: 1rem;
}

/* Skeleton loading animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    50%, 100% {
        left: 100%;
    }
}

/* Skeleton placeholder styling */
.skeleton-placeholder {
    cursor: wait;
    user-select: none;
}

/* Utility sizes */
.h-10 { height: 2.5rem !important; }
.rounded-2xl { border-radius: 1rem !important; }

/* Focus ring for accessibility */
.focus-visible\:ring-2:focus-visible {
    outline: 2px solid rgba(66, 153, 225, 0.6);
    outline-offset: 2px;
}

/* Nav buttons (for white navbar background) */
.nav-btn {
    transition: all 0.2s ease;
    border: 1px solid rgba(44, 62, 80, 0.2);
    background: rgba(44, 62, 80, 0.05);
    color: var(--text-dark);
    backdrop-filter: blur(10px);
}

.nav-btn:hover {
    background: rgba(44, 62, 80, 0.08);
    border-color: rgba(44, 62, 80, 0.3);
    color: var(--primary);
    transform: translateY(-1px);
}

.nav-btn:focus {
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.5);
    outline: none;
    color: var(--primary);
}

/* Language dropdown styling */
#languageDropdown {
    min-width: 80px;
    border: 1px solid rgba(44, 62, 80, 0.2);
    background: rgba(44, 62, 80, 0.05);
    color: var(--text-dark);
}

#languageDropdown:hover {
    background: rgba(44, 62, 80, 0.08);
    border-color: var(--primary);
    color: var(--primary);
}

#languageDropdown:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.5);
    color: var(--primary);
}

/* Language dropdown text colors */
#languageDropdown .fas { color: inherit; }
#currentLangCode { color: inherit; font-weight: 600; }

/* Overrides for specificity */
#languageDropdown { border: 1px solid rgba(44, 62, 80, 0.2) !important; background: rgba(44, 62, 80, 0.05) !important; color: var(--text-dark) !important; }
#languageDropdown:hover { background: rgba(44, 62, 80, 0.08) !important; border-color: var(--primary) !important; color: var(--primary) !important; }
#languageDropdown:focus { border-color: var(--primary) !important; color: var(--primary) !important; }

/* User dropdown button - content-based sizing */
#userDropdown button {
    border: 1px solid rgba(44, 62, 80, 0.2) !important;
    background: rgba(44, 62, 80, 0.05) !important;
    color: var(--text-dark) !important;
    min-width: auto !important; /* Remove fixed width */
    max-width: 200px; /* Prevent overly long names */
}

/* User name truncation for long names */
#userDropdown .user-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Login button styling - consistent sizing */
#authButtons {
    display: flex;
    align-items: center;
}

#authButtons .btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary)) !important;
    color: white !important;
    border: none !important;
    font-weight: 600 !important;
    white-space: nowrap; /* Prevent text wrapping */
}

#authButtons .btn:hover {
    background: linear-gradient(135deg, #4285f4, #8c5cf6) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(86, 145, 227, 0.4) !important;
}

/* Ensure icons inherit text color */
#languageDropdown i,
#userDropdown i { color: inherit !important; }

/* Responsive adjustments for auth slot */
@media (max-width: 767.98px) {
    #userDropdown .user-info { 
        display: none !important; 
    }
    #userDropdown button { 
        min-width: 40px !important;
        padding: 0.375rem 0.75rem !important;
    }
    .auth-slot {
        min-height: 32px; /* Slightly smaller on mobile */
    }
    #currentLangCode { display: inline !important; }
}
    
    /* Chat page specific mobile adjustments */
    .section-card {
        margin-bottom: 1.5rem;
        padding: 1rem !important; /* Reduce padding on mobile */
    }
    
    .section-card[style*="min-height"] {
        min-height: 400px !important; /* Reduce chat card height on mobile */
    }

    .navbar-logo {
        height: 32px;
    }

    .hero-logo-img {
        width: 160px;
    }

    .table-responsive {
        border-radius: 15px;
    }

    .table th, .table td {
        padding: 0.6rem 0.4rem;
        font-size: 0.85rem;
    }

    .navbar-brand {
        font-size: 1.2rem;
    }

    .section-title {
        font-size: 1.8rem;
        margin-bottom: 2.5rem;
    }
}

@media (max-width: 576px) {
    .container {
        padding: 0 0.75rem;
    }

    body {
        font-size: 0.9rem;
    }

    .hero {
        padding: 4rem 0 2.5rem;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .btn {
        font-size: 0.9rem;
        padding: 0.7rem 1.2rem;
    }

    .chat-window {
        height: 300px;
        padding: 0.8rem;
    }

    .message-bubble {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }

    .feature-icon {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }

    .form-control, .form-select {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .table {
        font-size: 0.8rem;
    }

    .table th, .table td {
        padding: 0.5rem 0.3rem;
    }

    .navbar {
        padding: 0.5rem 0;
    }

    .language-toggle {
        transform: scale(0.9);
    }

    .py-5 {
        padding-top: 2.5rem !important;
        padding-bottom: 2.5rem !important;
    }
}

@media (max-width: 400px) {
    .hero h1 {
        font-size: 1.6rem;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .chat-window {
        height: 280px;
    }

    .feature-icon {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
    }
}

/* Footer Styles */
.footer {
    background-color: #ffffff;
    border-top: 1px solid rgba(0,0,0,.125);
    position: relative;
    width: 100%;
}

.footer a.hover-primary {
    transition: color 0.3s ease;
}

.footer a.hover-primary:hover {
    color: var(--primary) !important;
}

/* Ensure main content fills space */
main {
    flex: 1 0 auto;
}

/* Legacy support for auth page using section-card */
.auth-page .section-card {
    display: block;
    width: 100%;
    max-width: none;
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--border-light);
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
    padding: 2rem;
    transition: all 0.3s ease;
}

.auth-page .section-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.15);
}

/* Footer responsive adjustments */
@media (max-width: 576px) {
    .footer .d-flex {
        flex-direction: column;
        text-align: center;
    }
    
    .footer .footer-left,
    .footer .footer-right {
        margin: 0.5rem 0;
    }
}

/* Custom Gray Color Utilities for Memory KPI */
.bg-secondary {
    background-color: #6c757d !important;
}

.bg-secondary.bg-opacity-10 {
    background-color: rgba(108, 117, 125, 0.1) !important;
}

.text-secondary {
    color: #6c757d !important;
}

/* ========================================
   ADMIN MEGA CARDS STYLES
   ======================================== */

/* Admin Mega Cards Grid Layout */
.admin-mega-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-top: 2rem;
}

/* Responsive Grid - Tablet */
@media (max-width: 1024px) {
    .admin-mega-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Responsive Grid - Mobile */
@media (max-width: 768px) {
    .admin-mega-cards-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* Mega Card Base Styles */
.mega-card {
    position: relative;
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    min-height: 400px;
}

.mega-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
}

.mega-card:focus-within {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Mega Card Content Layout */
.mega-card-content {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 400px;
}

/* Mega Card Header */
.mega-card-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.mega-card-icon-group {
    display: flex;
    gap: 0.75rem;
    flex-shrink: 0;
}

.mega-card-icon-group > div {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mega-card-title-section {
    flex: 1;
    min-width: 0;
}

.mega-card-title {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.mega-card-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0;
    line-height: 1.5;
}

/* KPIs Section */
.mega-card-kpis {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: rgba(var(--primary-rgb), 0.02);
    border-radius: 16px;
    border: 1px solid rgba(var(--primary-rgb), 0.08);
}

.kpi-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

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

.kpi-label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.kpi-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator i {
    font-size: 0.7rem;
}

/* Actions Section */
.mega-card-actions {
    margin-top: auto;
    padding-top: 1rem;
}

.mega-card-primary-cta {
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.875rem 1.5rem;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.mega-card-primary-cta:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.mega-card-secondary-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.mega-card-secondary-actions .btn {
    flex: 1;
    min-width: 0;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.mega-card-secondary-actions .btn:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Skeleton Loading States */
.mega-card-skeleton {
    padding: 2rem;
    height: 400px;
    display: flex;
    flex-direction: column;
}

.skeleton-header {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.skeleton-header::before {
    content: '';
    width: 60px;
    height: 60px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 50%;
}

.skeleton-header::after {
    content: '';
    flex: 1;
    height: 60px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 8px;
}

.skeleton-content {
    flex: 1;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.skeleton-actions {
    height: 100px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 12px;
}

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

/* Error States for Mega Cards */
.mega-card-error {
    padding: 2rem;
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--danger-rgb, 220, 53, 69), 0.02);
    border-radius: 24px;
    border: 1px dashed rgba(var(--danger-rgb, 220, 53, 69), 0.2);
}

.error-content {
    text-align: center;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.error-icon {
    opacity: 0.8;
}

.error-text {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.error-title {
    font-family: 'Space Grotesk', 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0;
}

.error-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 0;
}

.error-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    min-width: 200px;
}

.error-actions .btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.error-actions .retry-btn {
    background: var(--primary);
    border-color: var(--primary);
}

.error-actions .retry-btn:hover {
    background: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb, 86, 145, 227), 0.3);
}

.error-actions .details-btn {
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.error-actions .details-btn:hover {
    background: rgba(var(--secondary-rgb, 108, 117, 125), 0.1);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

/* Error modal styling */
.modal-content .bg-light {
    background-color: var(--bs-gray-100) !important;
}

/* ========================================
   TOP PROGRESS BAR - ROUTE LOADING
   ======================================== */

.top-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: rgba(var(--primary-rgb, 86, 145, 227), 0.1);
    z-index: 10000;
    opacity: 0;
    transform: translateY(-3px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-progress-bar.visible {
    opacity: 1;
    transform: translateY(0);
}

.top-progress-bar .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, 
        var(--primary) 0%,
        var(--accent-2) 50%,
        var(--primary) 100%
    );
    width: 0%;
    transition: width 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 0 8px rgba(var(--primary-rgb, 86, 145, 227), 0.4);
}

.top-progress-bar .progress-fill.indeterminate {
    width: 30%;
    animation: progress-indeterminate 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes progress-indeterminate {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(0%);
    }
    100% {
        transform: translateX(300%);
    }
}

/* ========================================
   LOADER OVERLAY - THRESHOLD BASED
   ======================================== */

.route-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.route-loader-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.loader-content {
    text-align: center;
    max-width: 300px;
    padding: 2rem;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(var(--primary-rgb, 86, 145, 227), 0.2);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: loader-spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

.loader-text {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.loader-subtext {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

@keyframes loader-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ========================================
   ENHANCED SHIMMER EFFECTS
   ======================================== */

.shimmer-enhanced {
    position: relative;
    overflow: hidden;
}

.shimmer-enhanced::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    animation: shimmer-sweep 2s ease-in-out infinite;
}

@keyframes shimmer-sweep {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Enhanced skeleton animations */
.skeleton-header::before,
.skeleton-header::after,
.skeleton-content,
.skeleton-actions {
    animation: skeleton-loading 1.8s ease-in-out infinite;
    background: linear-gradient(90deg, 
        #f0f0f0 25%, 
        #e8e8e8 37%, 
        #f0f0f0 63%
    );
    background-size: 400% 100%;
}

@keyframes skeleton-loading {
    0% {
        background-position: 100% 50%;
    }
    100% {
        background-position: -100% 50%;
    }
}

/* ========================================
   COUNT UP ANIMATIONS
   ======================================== */

.count-up {
    display: inline-block;
    font-feature-settings: 'tnum';
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.count-up.animating {
    transform: scale(1.1);
    color: var(--primary);
}

/* ========================================
   STALE DATA INDICATORS
   ======================================== */

.stale-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(var(--warning-rgb, 255, 193, 7), 0.1);
    border: 1px solid rgba(var(--warning-rgb, 255, 193, 7), 0.2);
    border-radius: 12px;
    padding: 0.25rem 0.5rem;
    margin-left: 0.5rem;
}

.stale-badge i {
    font-size: 0.625rem;
    opacity: 0.8;
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Critical CSS for immediate render */
.admin-shell-critical {
    /* Minimum required styles for shell */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Non-critical styles to be loaded later */
.admin-enhanced-styles {
    /* Enhanced animations and decorations */
    /* Will be loaded after critical path */
}

/* ========================================
   DARK MODE ENHANCEMENTS
   ======================================== */

@media (prefers-color-scheme: dark) {
    .route-loader-overlay {
        background: rgba(30, 30, 30, 0.92);
    }
    
    .loader-text {
        color: #ffffff;
    }
    
    .loader-subtext {
        color: #a0a0a0;
    }
    
    .top-progress-bar {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .skeleton-header::before,
    .skeleton-header::after,
    .skeleton-content,
    .skeleton-actions {
        background: linear-gradient(90deg, 
            #2a2a2a 25%, 
            #404040 37%, 
            #2a2a2a 63%
        );
        background-size: 400% 100%;
    }
    
    .shimmer-enhanced::before {
        background: linear-gradient(
            90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.1) 50%,
            transparent 100%
        );
    }
}

/* ========================================
   REDUCED MOTION SUPPORT
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .top-progress-bar,
    .route-loader-overlay,
    .count-up {
        transition: none;
    }
    
    .loader-spinner {
        animation: none;
        border: 3px solid var(--primary);
    }
    
    .shimmer-enhanced::before,
    .skeleton-header::before,
    .skeleton-header::after,
    .skeleton-content,
    .skeleton-actions {
        animation: none;
    }
    
    @keyframes progress-indeterminate {
        0%, 100% {
            transform: translateX(0%);
        }
    }
}

/* Accessibility Improvements */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .mega-card-kpis {
        background: rgba(255, 255, 255, 0.02);
        border-color: rgba(255, 255, 255, 0.08);
    }
    
    .skeleton-header::before,
    .skeleton-header::after,
    .skeleton-content,
    .skeleton-actions {
        background: linear-gradient(90deg, #2a2a2a 25%, #404040 50%, #2a2a2a 75%);
        background-size: 200% 100%;
    }
}

/* Mobile Optimizations */
@media (max-width: 576px) {
    .mega-card-content {
        padding: 1.5rem;
        min-height: 350px;
    }
    
    .mega-card-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .mega-card-icon-group {
        justify-content: center;
    }
    
    .mega-card-title {
        font-size: 1.25rem;
    }
    
    .mega-card-secondary-actions {
        flex-direction: column;
    }
    
    .mega-card-secondary-actions .btn {
        flex: none;
    }
    
    .mega-card-kpis {
        padding: 1rem;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .mega-card {
        border: 2px solid;
    }
    
    .mega-card:hover,
    .mega-card:focus-within {
        border-width: 3px;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .mega-card,
    .mega-card-primary-cta,
    .mega-card-secondary-actions .btn {
        transition: none;
    }
    
    .mega-card:hover,
    .mega-card:focus-within {
        transform: none;
    }
    
    .skeleton-header::before,
    .skeleton-header::after,
    .skeleton-content,
    .skeleton-actions {
        animation: none;
        background: #f0f0f0;
    }
}

/* === START: Grafana 圖表優化樣式 (最終版) === */

/* 使用更具體的選擇器，確保優先級更高 */
.message-wrapper.assistant .message-content.has-chart {
    max-width: 85%;
    width: 100%; /* 確保在容器內盡可能寬 */
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: hidden;
}

.message-wrapper.assistant .message-content.has-chart iframe {
    display: block;
    width: 100%;
    height: 350px;
    border-radius: 15px !important;
    border: 1px solid var(--border-light);
}

/* 手機版響應式設計 */
@media (max-width: 768px) {
    .message-wrapper.assistant .message-content.has-chart {
        max-width: 100%;
    }
}

/* === END: 新增樣式 === */