/**
 * Enhanced UI Styles
 * Modern, responsive, and accessible design system
 */

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

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

/* ===== GLOBAL ENHANCEMENTS ===== */
* {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

body {
    animation: fadeIn 0.3s ease-in;
}

/* ===== NAVIGATION ENHANCEMENTS ===== */
nav {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

nav a, nav button {
    position: relative;
    transition: all 0.3s ease;
}

nav a::after, nav button::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: currentColor;
    transition: width 0.3s ease;
}

nav a:hover::after, nav button:hover::after {
    width: 100%;
}

nav a.active {
    color: #3b82f6;
    font-weight: 600;
}

nav a.active::after {
    width: 100%;
}

/* ===== CARDS & CONTAINERS ===== */
.card {
    animation: slideUp 0.4s ease-out;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.dark .card:hover {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

/* ===== BUTTONS ===== */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn:active {
    transform: scale(0.98);
}

/* ===== LOADING SKELETONS ===== */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.dark .skeleton {
    background: linear-gradient(
        90deg,
        #374151 25%,
        #4b5563 50%,
        #374151 75%
    );
    background-size: 200% 100%;
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

.skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: 1rem;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* ===== FORMS ===== */
input, select, textarea {
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

input:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
}

input:valid:not(:placeholder-shown) {
    border-color: #10b981;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 300px;
    padding: 1rem 1.5rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-left: 4px solid;
}

.dark .toast {
    background: #1f2937;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.toast.success {
    border-left-color: #10b981;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.warning {
    border-left-color: #f59e0b;
}

.toast.info {
    border-left-color: #3b82f6;
}

.toast-icon {
    font-size: 1.5rem;
}

.toast-content {
    flex: 1;
}

.toast-close {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

/* ===== CHATBOT ENHANCEMENTS ===== */
#chatbotToggle {
    animation: pulse 2s infinite;
    transition: all 0.3s ease;
}

#chatbotToggle:hover {
    animation: none;
    transform: scale(1.1);
}

#chatbotPanel {
    animation: slideUp 0.3s ease-out;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.chat-message {
    animation: fadeIn 0.3s ease-out;
    max-width: 80%;
    word-wrap: break-word;
}

.chat-message.user {
    margin-left: auto;
}

.chat-message.assistant {
    margin-right: auto;
}

/* ===== TABLE ENHANCEMENTS ===== */
table {
    border-collapse: separate;
    border-spacing: 0;
}

table tbody tr {
    transition: all 0.2s ease;
}

table tbody tr:hover {
    background-color: rgba(59, 130, 246, 0.05);
    transform: scale(1.01);
}

.dark table tbody tr:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

/* ===== MODAL ENHANCEMENTS ===== */
.modal-backdrop {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    animation: slideUp 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

/* ===== SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.dark ::-webkit-scrollbar-track {
    background: #374151;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* ===== BADGES & TAGS ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.badge:hover {
    transform: scale(1.05);
}

.badge-primary {
    background: #dbeafe;
    color: #1e40af;
}

.dark .badge-primary {
    background: #1e3a8a;
    color: #dbeafe;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.dark .badge-success {
    background: #064e3b;
    color: #d1fae5;
}

/* ===== TOOLTIPS ===== */
.tooltip {
    position: relative;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    padding: 0.5rem 0.75rem;
    background: #1f2937;
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1000;
}

.tooltip:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

/* ===== RESPONSIVE ENHANCEMENTS ===== */
@media (max-width: 768px) {
    .toast-container {
        left: 10px;
        right: 10px;
        top: 70px;
    }

    .toast {
        min-width: auto;
        width: 100%;
    }

    #chatbotPanel {
        width: calc(100% - 2rem);
        right: 1rem;
        left: 1rem;
        bottom: 80px;
    }

    nav .flex {
        flex-wrap: wrap;
    }

    nav a, nav button {
        font-size: 0.875rem;
        padding: 0.5rem;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ===== UTILITY CLASSES ===== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

.slide-up {
    animation: slideUp 0.4s ease-out;
}

.pulse-animation {
    animation: pulse 2s infinite;
}

.shimmer {
    animation: shimmer 1.5s infinite;
}

/* ===== TEXT TRUNCATION FIXES ===== */
.card {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.card p,
.card li,
.card span {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Fix list items - ensure bullets are visible */
.card ul,
.card ol {
    padding-left: 1.25rem;
    margin-left: 0;
    overflow: visible;
}

.card ul li,
.card ol li {
    padding-left: 0.5rem;
    margin-left: 0;
    list-style-position: outside;
    overflow: visible;
}

/* Custom bullet points for better visibility */
.card ul[style*="list-style: none"] li {
    display: flex;
    align-items: flex-start;
    padding-left: 0;
    margin-left: 0;
    min-width: 0;
    overflow: visible;
}

.card ul[style*="list-style: none"] li > span:first-child {
    flex-shrink: 0;
    width: auto;
    min-width: 0.5rem;
    margin-right: 0.5rem;
}

.card ul[style*="list-style: none"] li > span:last-child {
    flex: 1;
    min-width: 0;
    overflow: visible;
    word-wrap: break-word;
}

/* Prevent text truncation in labels and buttons */
label,
button {
    white-space: normal;
    word-wrap: break-word;
}

/* Ensure checkboxes and labels don't truncate */
label.flex.items-center {
    min-width: 0;
    overflow: visible;
    white-space: nowrap;
}

label.flex.items-center span {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    min-width: fit-content;
}

/* Input fields - prevent truncation */
.input-field {
    min-width: 0 !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
}

/* Specific fix for chat input */
#chatInput {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    text-overflow: clip !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
}

/* Buttons with icons - ensure text doesn't truncate */
button.btn-primary,
button.btn-secondary {
    min-width: fit-content;
    overflow: visible;
    white-space: nowrap;
}

button.btn-primary i,
button.btn-secondary i {
    flex-shrink: 0;
}

/* Ensure flex containers don't truncate content */
.flex {
    min-width: 0;
}

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

/* But allow overflow for specific cases */
.card.overflow-visible,
.card .overflow-visible {
    overflow: visible !important;
}

/* Ensure cards don't clip content - but keep overflow-hidden for tables */
.card {
    overflow: visible;
}

.card > * {
    overflow: visible;
}

/* Exception: cards with tables should have overflow */
.card.overflow-hidden,
.card > .overflow-hidden {
    overflow: hidden;
}

/* But info cards and option cards should be visible */
.card.bg-blue-50,
.card.bg-blue-900\/20 {
    overflow: visible !important;
}

/* Fix for info cards */
.card .flex.items-start {
    min-width: 0;
}

.card .flex.items-start > div {
    min-width: 0;
    flex: 1;
}

/* Input fields full width */
.input-field {
    width: 100%;
    box-sizing: border-box;
}

/* Grid items full width */
.grid > div {
    min-width: 0;
}

/* Responsive text */
@media (max-width: 768px) {
    .card h3,
    .card p,
    .card li {
        font-size: 0.875rem;
    }

    .card h2 {
        font-size: 1.25rem;
    }
}

/* ===== SIDEBAR HOVER TOGGLE ===== */
/* Sidebar base styles */
#sidebar {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Collapsed sidebar - chỉ hiện icon (64px = 4rem) */
#sidebar.sidebar-collapsed {
    width: 4rem !important;
}

/* Hide text when collapsed */
#sidebar.sidebar-collapsed .sidebar-link span,
#sidebar.sidebar-collapsed h1,
#sidebar.sidebar-collapsed .badge,
#sidebar.sidebar-collapsed .p-6 > div > h1 {
    opacity: 0;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.2s ease, width 0.2s ease;
    margin: 0;
}

/* Center icons when collapsed */
#sidebar.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

#sidebar.sidebar-collapsed .sidebar-link i {
    margin-right: 0 !important;
}

/* Center logo icon when collapsed */
#sidebar.sidebar-collapsed .p-6 {
    padding: 1rem;
    display: flex;
    justify-content: center;
}

#sidebar.sidebar-collapsed .p-6 > div {
    justify-content: center;
}

/* Hover to expand - smooth transition */
#sidebar.sidebar-collapsed:hover {
    width: 16rem !important;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 45;
}

/* Show text on hover */
#sidebar.sidebar-collapsed:hover .sidebar-link span,
#sidebar.sidebar-collapsed:hover h1,
#sidebar.sidebar-collapsed:hover .badge,
#sidebar.sidebar-collapsed:hover .p-6 > div > h1 {
    opacity: 1;
    width: auto;
    overflow: visible;
    margin: 0;
}

/* Restore padding on hover */
#sidebar.sidebar-collapsed:hover .sidebar-link {
    justify-content: flex-start;
    padding-left: 1rem;
    padding-right: 1rem;
}

#sidebar.sidebar-collapsed:hover .sidebar-link i {
    margin-right: 0.75rem !important;
}

#sidebar.sidebar-collapsed:hover .p-6 {
    padding: 1.5rem;
    justify-content: flex-start;
}

#sidebar.sidebar-collapsed:hover .p-6 > div {
    justify-content: flex-start;
}

/* Main content adjustment - smooth transition */
.lg\:ml-64,
[class*="lg:ml-64"] {
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Adjust main content when sidebar collapsed */
body:has(#sidebar.sidebar-collapsed) .lg\:ml-64,
body:has(#sidebar.sidebar-collapsed) [class*="lg:ml-64"] {
    margin-left: 4rem !important;
}

/* Expand main content on hover */
body:has(#sidebar.sidebar-collapsed:hover) .lg\:ml-64,
body:has(#sidebar.sidebar-collapsed:hover) [class*="lg:ml-64"] {
    margin-left: 16rem !important;
}

/* Sidebar toggle button */
#sidebarToggle {
    position: fixed;
    left: 1rem;
    top: 1rem;
    z-index: 50;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    background: white;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: none; /* Hidden by default, shown via Layout.js */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#sidebarToggle.lg\:flex {
    display: flex;
}

#sidebarToggle:hover {
    background: #f3f4f6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
}

.dark #sidebarToggle {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

.dark #sidebarToggle:hover {
    background: #374151;
}

/* Adjust toggle position when sidebar collapsed */
#sidebar.sidebar-collapsed ~ #sidebarToggle,
body:has(#sidebar.sidebar-collapsed) #sidebarToggle {
    left: 5.5rem; /* 4rem sidebar + 1rem margin + 0.5rem */
}

#sidebar.sidebar-collapsed:hover ~ #sidebarToggle,
body:has(#sidebar.sidebar-collapsed:hover) #sidebarToggle {
    left: 17.5rem; /* 16rem sidebar + 1rem margin + 0.5rem */
}

/* Hide toggle on mobile */
@media (max-width: 1024px) {
    #sidebarToggle {
        display: none !important;
    }
}

/* ===== TAB NAVIGATION FIXES ===== */
/* Tab navigation container */
nav.flex.space-x-8 {
    min-width: 0;
}

/* Tab buttons - prevent truncation */
.tab-button {
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
}

/* Tab navigation scrollbar */
nav.overflow-x-auto {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

nav.overflow-x-auto::-webkit-scrollbar {
    height: 4px;
}

nav.overflow-x-auto::-webkit-scrollbar-track {
    background: transparent;
}

nav.overflow-x-auto::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.dark nav.overflow-x-auto::-webkit-scrollbar-thumb {
    background: #4b5563;
}

nav.overflow-x-auto::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark nav.overflow-x-auto::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Smooth transitions for all sidebar elements */
#sidebar * {
    transition: opacity 0.2s ease, width 0.2s ease, margin 0.2s ease;
}

/* Prevent text selection during transition */
#sidebar.sidebar-collapsed {
    user-select: none;
}

#sidebar.sidebar-collapsed:hover {
    user-select: auto;
}





