/* main.css - Design Tokens & Global Styles */

:root {
    /* Colors - Light Mode */
    --background: #FAF5FF;
    --foreground: #1E1B4B;
    --card: #ffffff;
    --card-foreground: #1E1B4B;
    --popover: #ffffff;
    --popover-foreground: #1E1B4B;
    --primary: #7C3AED;
    --primary-foreground: #ffffff;
    --secondary: #A78BFA;
    --secondary-foreground: #ffffff;
    --muted: #F3E8FF;
    --muted-foreground: #6B7280;
    --accent: #06B6D4;
    --accent-foreground: #ffffff;
    --destructive: #ef4444;
    --border: #E2E8F0;
    --input: #E2E8F0;
    --ring: #7C3AED;
    
    /* Shapes */
    --radius: 0.75rem;
    --radius-sm: calc(var(--radius) * 0.6);
    --radius-md: calc(var(--radius) * 0.8);
    --radius-lg: var(--radius);
    --radius-xl: calc(var(--radius) * 1.4);
    
    /* Typography */
    --font-sans: 'Be Vietnam Pro', sans-serif;
    
    /* Glassmorphism Defaults */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-blur: 40px;
}

[data-theme="dark"] {
    --background: #0F172A;
    --foreground: #F8FAFC;
    --card: #1E293B;
    --card-foreground: #F8FAFC;
    --popover: #1E293B;
    --popover-foreground: #F8FAFC;
    --primary: #8B5CF6;
    --primary-foreground: #ffffff;
    --secondary: #A78BFA;
    --secondary-foreground: #0F172A;
    --muted: #1E293B;
    --muted-foreground: #94A3B8;
    --accent: #06B6D4;
    --accent-foreground: #0F172A;
    --destructive: #ef4444;
    --border: rgba(148, 163, 184, 0.2);
    --input: rgba(148, 163, 184, 0.1);
    --ring: #8B5CF6;
    
    --glass-bg: rgba(15, 23, 42, 0.8);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-blur: 20px;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border-color: var(--border);
    transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                color 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                border-color 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                backdrop-filter 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                filter 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    height: 100vh;
    overflow: hidden;
}

/* Mesh Background */
.mesh-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background-color: var(--background);
}

.mesh-bg::before,
.mesh-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    transition: opacity 0.8s ease-in-out;
}

.mesh-bg::before {
    background-image: 
        radial-gradient(at 40% 20%, hsla(263, 70%, 92%, 1) 0px, transparent 50%),
        radial-gradient(at 80% 0%, hsla(189, 70%, 92%, 1) 0px, transparent 50%),
        radial-gradient(at 0% 50%, hsla(240, 70%, 94%, 1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, hsla(280, 70%, 94%, 1) 0px, transparent 50%);
    filter: saturate(1.2);
    opacity: 1;
}

[data-theme="dark"] .mesh-bg::before {
    opacity: 0;
}

.mesh-bg::after {
    background-image: 
        radial-gradient(at 40% 20%, hsla(263, 70%, 12%, 1) 0px, transparent 50%),
        radial-gradient(at 80% 0%, hsla(189, 70%, 12%, 1) 0px, transparent 50%),
        radial-gradient(at 0% 50%, hsla(263, 70%, 10%, 1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, hsla(280, 70%, 10%, 1) 0px, transparent 50%);
    filter: saturate(1.5);
    opacity: 0;
}

[data-theme="dark"] .mesh-bg::after {
    opacity: 1;
}

/* Glass Utility */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 24px -1px rgba(0, 0, 0, 0.1);
}

/* Animations */
.animate-in {
    animation-duration: 0.5s;
    animation-fill-mode: both;
}

.fade-in {
    animation-name: fadeIn;
}

.slide-in-from-top-4 {
    animation-name: slideInTop;
}

.slide-in-from-bottom-6 {
    animation-name: slideInBottom;
}

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

@keyframes slideInTop {
    from { transform: translateY(-1rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInBottom {
    from { transform: translateY(1.5rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.animate-float {
    animation: float 6s ease-in-out infinite;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--primary) 20%, transparent);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Markdown Typography */
.markdown-content {
    line-height: 1.6;
    font-size: 0.875rem;
    overflow-wrap: break-word;
    word-break: normal;
}

.markdown-content p {
    margin-bottom: 1rem;
}

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

.markdown-content strong {
    font-weight: 700;
}

.markdown-content ul, .markdown-content ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.markdown-content li {
    margin-bottom: 0.25rem;
}

.markdown-content pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 1rem;
    border-radius: 0.75rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.markdown-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.85em;
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
}

.markdown-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.5rem 0;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    background: var(--card);
}

.markdown-content table {
    width: 100%;
    min-width: 500px; /* Đảm bảo bảng không bị quá hẹp */
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ai-message-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
}

.message--ai .message__bubble {
    width: 100%;
}

.markdown-content th {
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    color: var(--primary);
    font-weight: 700;
    text-align: left;
    padding: 0.85rem 1.25rem;
    border-bottom: 2px solid color-mix(in srgb, var(--primary) 20%, transparent);
    white-space: nowrap; /* Header trên 1 dòng */
}

.markdown-content td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--foreground);
}

.markdown-content tr:nth-child(even) td {
    background-color: color-mix(in srgb, var(--primary) 2%, transparent);
}

.markdown-content tr:last-child td {
    border-bottom: none;
}

.markdown-content tr:hover td {
    background-color: color-mix(in srgb, var(--primary) 5%, transparent);
}

/* Premium Copy Feedback Badge */
.copy-badge {
    position: fixed;
    padding: 0.4rem 0.8rem;
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 2rem;
    font-size: 0.7rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(124, 58, 237, 0.4);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: badgePop 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes badgePop {
    0% {
        opacity: 0;
        transform: translate(-50%, 5px) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -25px) scale(1.1);
    }
    30% {
        transform: translate(-50%, -20px) scale(1);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -30px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -45px) scale(0.9);
    }
}
