/* ==== API Key Table Custom Styles ==== */
.api-key-card {
    border-radius: 1.25rem;
    box-shadow: 0 4px 24px 0 rgba(0,0,0,0.18);
    background: var(--bs-dark-bg, #181b26);
    border: none;
}
.api-key-table {
    border-radius: 1.25rem;
    overflow: hidden;
    font-size: 1.04rem;
    background: transparent;
}
.api-key-table th, .api-key-table td {
    border: none !important;
    padding: 0.85rem 1.1rem;
    vertical-align: middle;
}
.api-key-table thead th {
    background: var(--bs-dark-bg-subtle, #232736) !important;
    color: #fff;
    font-weight: 600;
    font-size: 1.07rem;
    letter-spacing: 0.2px;
    border: none;
}
.api-key-table tbody tr {
    transition: background 0.2s;
}
.api-key-table tbody tr:hover {
    background: #232736 !important;
}
.api-badge-active {
    background: linear-gradient(90deg, #4f8cff 0%, #6edbff 100%);
    color: #fff;
    border-radius: 1.5rem;
    font-weight: 600;
    font-size: 0.98rem;
    padding: 0.45em 1.2em;
    box-shadow: 0 2px 8px 0 rgba(79,140,255,0.10);
    letter-spacing: 0.5px;
}
.api-badge-inactive {
    background: #444a5a;
    color: #c0c0c0;
    border-radius: 1.5rem;
    font-weight: 600;
    font-size: 0.98rem;
    padding: 0.45em 1.2em;
    letter-spacing: 0.5px;
}
@media (max-width: 600px) {
    .api-key-table th, .api-key-table td {
        padding: 0.6rem 0.5rem;
        font-size: 0.97rem;
    }
    .api-key-card {
        border-radius: 0.7rem;
    }
}
/* Fix màu chữ chú thích biểu đồ ở dark mode */
body.dark-mode .chart-legend,
body.dark-mode .chart-label,
body.dark-mode .legend,
body.dark-mode .label,
body.dark-mode .chartjs-legend,
body.dark-mode .apexcharts-legend,
body.dark-mode .apexcharts-legend-text {
    color: var(--text-primary) !important;
}
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
    color: var(--text-muted) !important;
    opacity: 1;
}
/* Fix feature card text color in dark mode */
body.dark-mode .feature-card,
body.dark-mode .feature-card h2,
body.dark-mode .feature-card p {
    color: var(--text-primary) !important;
}
body.dark-mode .feature-card .feature-icon {
    background: var(--primary-color) !important;
    color: #fff !important;
}
/* --- Bootstrap Color Class Overrides for Dark Mode --- */
body.dark-mode .bg-light {
    background-color: var(--bg-surface-secondary) !important;
}
body.dark-mode .bg-primary {
    background-color: var(--primary-color) !important;
}
body.dark-mode .bg-success {
    background-color: var(--success-color) !important;
}
body.dark-mode .bg-warning {
    background-color: var(--warning-color) !important;
}
body.dark-mode .bg-gradient {
    background-image: none !important;
}
body.dark-mode .text-primary {
    color: var(--primary-color) !important;
}
body.dark-mode .text-muted {
    color: var(--text-muted) !important;
}
body.dark-mode .text-white {
    color: #fff !important;
}
body.dark-mode .border-primary {
    border-color: var(--primary-color) !important;
}
body.dark-mode .btn-outline-secondary {
    color: var(--secondary-color) !important;
    border-color: var(--secondary-color) !important;
    background: transparent !important;
}
body.dark-mode .btn-outline-secondary:hover {
    background: var(--secondary-color) !important;
    color: #fff !important;
}
:root {
    /* Soft Color Palette - Light Mode */
    --primary-color: #4e73df;
    --primary-hover: #2e59d9;
    --secondary-color: #858796;
    --success-color: #1cc88a;
    --info-color: #36b9cc;
    --warning-color: #f6c23e;
    --danger-color: #e74a3b;

    --bg-body: #f4f6f9;
    --bg-surface: #ffffff;
    --bg-surface-secondary: #f8f9fa;

    --text-primary: #2e384d;
    --text-secondary: #6c757d;
    --text-muted: #858796;

    --border-color: #e3e6f0;

    /* Soft Design System */
    --border-radius-sm: 8px;
    --border-radius: 12px;
    --border-radius-lg: 16px;

    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    /* Softer, broader shadow */
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08);

    --transition-speed: 0.3s;
}

/* Dark Mode Palette - Deep Premium */
body.dark-mode {
    --bg-body: #101624;
    --bg-surface: #181c2a;
    --bg-surface-secondary: #23263a;

    --text-primary: #e6eaf3;
    --text-secondary: #b5b9c9;
    --text-muted: #7c8196;

    --border-color: #2d3144;

    --primary-color: #7b9fff;
    --primary-hover: #a78bfa;
    --secondary-color: #b0b0b0;
    --success-color: #4ade80;
    --info-color: #38bdf8;
    --warning-color: #fde047;
    --danger-color: #fb7185;

    --shadow: 0 4px 24px rgba(0,0,0,0.85);
}
body.dark-mode,
body.dark-mode .card,
body.dark-mode .feature-card,
body.dark-mode .table,
body.dark-mode .form-control,
body.dark-mode .form-select,
body.dark-mode .dropdown-menu,
body.dark-mode .navbar,
body.dark-mode .navbar-brand,
body.dark-mode .nav-link,
body.dark-mode .dropdown-item {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
    box-shadow: var(--shadow) !important;
}
body.dark-mode .card-header,
body.dark-mode .card-body {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
}
body.dark-mode .input-group .form-control,
body.dark-mode .form-control {
    background: var(--bg-surface-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
body.dark-mode .input-group .btn,
body.dark-mode .btn {
    background: var(--bg-surface-secondary) !important;
    color: var(--primary-color) !important;
    border-color: var(--border-color) !important;
}
body.dark-mode .input-group .btn:hover,
body.dark-mode .btn:hover {
    background: var(--primary-hover) !important;
    color: #fff !important;
}
body.dark-mode .progress {
    background: var(--bg-surface-secondary) !important;
}
body.dark-mode .progress-bar {
    background: linear-gradient(90deg,#7b9fff,#a78bfa,#f472b6) !important;
}
body.dark-mode .badge {
    background: var(--bg-surface-secondary) !important;
    color: var(--primary-color) !important;
    border: 1px solid var(--primary-color) !important;
}
body.dark-mode .shadow,
body.dark-mode .shadow-lg {
    box-shadow: var(--shadow) !important;
}
}
body.dark-mode .text-secondary {
    color: var(--text-secondary) !important;
}
body.dark-mode .text-muted {
    color: var(--text-muted) !important;
}
body.dark-mode .feature-card {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1.5px solid var(--border-color) !important;
}
body.dark-mode .feature-card h2,
body.dark-mode .feature-card p {
    color: var(--text-primary) !important;
}
body.dark-mode .feature-card .feature-icon {
    background: var(--primary-color) !important;
    color: #23272f !important;
    /* Icon sáng trên nền tối */
}

html, body {
    background-color: var(--bg-body) !important;
    color: var(--text-primary);
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* Smooth transition for all elements */
* {
    transition: background-color var(--transition-speed), color var(--transition-speed), border-color var(--transition-speed);
}
}

/* Typography & Links */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: 600;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Card Styling - The Core of "Soft" Design */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    /* Subtle border */
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s, border-color var(--transition-speed), background-color var(--transition-speed);
}

.card:hover {
    transform: translateY(-2px);
    /* Subtle lift */
    box-shadow: var(--shadow-lg);
}

.card-header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
    border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
    padding: 1rem 1.5rem;
}

.card-body {
    padding: 1.5rem;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    border-radius: var(--border-radius-sm);
    padding: 0.5rem 1rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(78, 115, 223, 0.3);
}

/* Rounded pills for specific actions */
.rounded-pill {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

/* Inputs & Forms */
.form-control,
.form-select {
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    /* Softer inputs */
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--bg-surface);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(78, 115, 223, 0.1);
    /* Soft focus ring */
    color: var(--text-primary);
}


/* Navbar */
.navbar {
    background-color: var(--bg-surface) !important;
    box-shadow: var(--shadow);
    transition: background-color var(--transition-speed);
}
.navbar-light .navbar-brand {
    color: var(--primary-color) !important;
    font-weight: 700;
}
.navbar-light .nav-link {
    color: var(--text-secondary);
    font-weight: 500;
}
.navbar-light .nav-link:hover,
.navbar-light .nav-link.active {
    color: var(--primary-color);
}
/* Fix: Đừng override .navbar-toggler background/border để Bootstrap JS hoạt động đúng */
.navbar-light .navbar-toggler {
    /* Không override background hoặc border ở đây */
}

/* Tables */
.table {
    border-color: var(--border-color);
    color: var(--text-primary);
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    background-color: var(--bg-body);
    /* Subtle header bg */
}

/* Dark Mode Overrides (Specific Details) */
body.dark-mode .navbar-light {
    background-color: var(--bg-surface) !important;
}

body.dark-mode .navbar-light .navbar-brand {
    color: var(--text-primary) !important;
    /* White in dark mode, or keep primary? */
}

body.dark-mode .navbar-light .nav-link {
    color: var(--text-secondary);
}

body.dark-mode .navbar-light .nav-link:hover {
    color: var(--primary-color);
}

body.dark-mode .dropdown-menu {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
}

body.dark-mode .dropdown-item {
    color: var(--text-primary);
}

body.dark-mode .dropdown-item:hover {
    background-color: var(--bg-surface-secondary);
    color: var(--primary-color);
}

/* Badges */
.badge {
    border-radius: 6px;
    padding: 0.5em 0.8em;
    font-weight: 600;
}

/* Utility */
.text-muted {
    color: var(--text-muted) !important;
}

.shadow-sm {
    box-shadow: var(--shadow) !important;
    /* Override bootstrap shadow with our soft one */
}

/* Custom Animation classes */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container {
    background: transparent;
    animation: fadeIn 0.4s ease-out;
}

/* ========== Dark Mode Support ========== */
body.dark-mode {
    background: #0f172a !important;
    color: #e5e7eb;
}

body.dark-mode .navbar {
    background: rgba(15, 23, 42, 0.95) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
}

body.dark-mode .card-header {
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
}

body.dark-mode .form-control,
body.dark-mode .form-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(139, 92, 246, 0.5);
    color: white;
}

body.dark-mode .table {
    color: white;
}

body.dark-mode .table thead th {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .table tbody td {
    border-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    border: none;
}

body.dark-mode .btn-outline-primary {
    color: #8b5cf6;
    border-color: #8b5cf6;
}

body.dark-mode .btn-outline-primary:hover {
    background: #8b5cf6;
    color: white;
}

body.dark-mode .nav-link {
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode .nav-link:hover {
    color: white;
}

body.dark-mode .modal-content {
    background: #1e293b;
    color: white;
}

body.dark-mode .modal-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .modal-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .close {
    color: white;
}

body.dark-mode .text-muted {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Dark mode navbar brand */
body.dark-mode .navbar-brand {
    color: white !important;
}

body.dark-mode .dropdown-menu {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .dropdown-item {
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Footer dark mode */
body.dark-mode footer {
    background: rgba(15, 23, 42, 0.95) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode footer a {
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode footer a:hover {
    color: white;
}

/* ==========================================================================
   PREMIUM MOBILE RESPONSIVE OVERRIDES
   Ensures ultra-smooth and beautiful layout transitions on mobile devices
   ========================================================================== */

@media (max-width: 768px) {
    /* Fluid Container Adjustments */
    .container, .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    /* Global Typography Scale for Mobile */
    h1, .h1 { font-size: 1.75rem !important; }
    h2, .h2 { font-size: 1.45rem !important; }
    h3, .h3 { font-size: 1.25rem !important; }
    h4, .h4 { font-size: 1.15rem !important; }
    
    /* Smooth Table Touch Scrolling */
    .table-responsive {
        border: 0;
        margin-bottom: 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Momentum scrolling for iOS */
        border-radius: 12px;
    }
    .table-responsive table {
        margin-bottom: 0 !important;
    }
    .table th, .table td {
        white-space: nowrap; /* Prevent content clipping and ugly wraps */
        padding: 0.75rem 0.85rem !important;
        font-size: 0.85rem !important;
    }

    /* Card Padding Optimizations */
    .card, .premium-card {
        border-radius: 14px !important;
        margin-bottom: 1rem !important;
        transform: none !important; /* Disable hover translate on mobile for performance */
    }
    .card:hover {
        transform: none !important;
        box-shadow: var(--shadow) !important;
    }
    .card-header, .card-header-custom {
        padding: 0.85rem 1rem !important;
    }
    .card-body, .card-body-custom {
        padding: 1rem !important;
    }

    /* Mobile Inputs and Form Optimization */
    .form-control, .form-select, .input-group-text {
        font-size: 16px !important; /* Prevents auto-zoom on iOS */
        padding: 0.55rem 0.85rem !important;
        border-radius: 10px !important;
        height: auto !important;
    }
    
    .btn {
        padding: 0.55rem 1rem !important;
        font-size: 0.9rem !important;
        border-radius: 10px !important;
    }

    /* Quick Action Grid Adjustments */
    .quick-actions, .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    /* Header & Navigation Bar Styling */
    .navbar {
        padding: 0.5rem 0 !important;
    }
    .navbar-collapse {
        background: var(--bg-surface, #ffffff);
        border-radius: 16px;
        padding: 15px;
        margin-top: 8px;
        border: 1px solid var(--border-color, #e2e8f0);
        box-shadow: 0 10px 25px rgba(0,0,0,0.15) !important;
    }
    body.dark-mode .navbar-collapse {
        background: #1e293b !important;
        border-color: rgba(255, 255, 255, 0.1) !important;
    }
    .navbar-nav {
        gap: 8px;
    }
    .nav-link {
        padding: 10px 14px !important;
        border-radius: 10px;
        background: var(--bg-surface-secondary, #f8fafc);
        display: flex;
        align-items: center;
        width: 100%;
        color: var(--text-primary) !important;
    }
    body.dark-mode .nav-link {
        background: #0f172a !important;
        color: #e2e8f0 !important;
    }
    .nav-link:hover, .nav-link.active {
        background: var(--primary-color, #3b82f6) !important;
        color: #ffffff !important;
    }
    .navbar-nav.ms-auto {
        margin-top: 10px;
        border-top: 1px solid var(--border-color, #e2e8f0);
        padding-top: 10px;
    }
    body.dark-mode .navbar-nav.ms-auto {
        border-top-color: rgba(255, 255, 255, 0.1);
    }
    
    /* Dropdown Menus on Mobile Navigation */
    .dropdown-menu {
        position: static !important;
        float: none !important;
        width: 100% !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        padding-left: 15px !important;
    }
    .dropdown-item {
        border-radius: 8px;
        padding: 8px 12px !important;
    }

    /* Modal dialog fixes */
    .modal-dialog {
        margin: 10px !important;
        max-width: calc(100% - 20px) !important;
    }
    
    /* Top Banner Layout for Mobile Dashboard */
    .top-banner {
        padding: 20px 16px !important;
        margin-bottom: 24px !important;
        border-radius: 16px !important;
    }
    .top-banner-content {
        flex-direction: column !important;
        text-align: center !important;
        gap: 12px !important;
    }
    .user-welcome {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .balance-display {
        text-align: center !important;
    }
    
    /* Notification popup styling */
    #notificationPopup {
        top: 60px !important;
        right: 10px !important;
        width: calc(100vw - 20px) !important;
    }
    
    /* Responsive Floating Chat Widgets and Overlays */
    #chat-widget-popup, .chat-widget-overlay, .ai-widget-overlay {
        width: calc(100% - 24px) !important;
        max-width: none !important;
        height: 78vh !important;
        max-height: 650px !important;
        right: 12px !important;
        left: 12px !important;
        bottom: 80px !important;
        border-radius: 20px !important;
        box-shadow: 0 8px 32px rgba(0,0,0,0.25) !important;
    }
    
    /* Ensure internal iframe uses full height and inherits border-radius */
    #chat-widget-popup iframe, .chat-widget-overlay iframe, .ai-widget-overlay iframe {
        border-radius: 0 0 20px 20px !important;
    }
    
    /* Match border radius of chat header container */
    #chat-widget-popup > div:first-child {
        border-radius: 20px 20px 0 0 !important;
    }
}