/**
 * Admin Panel Visual Polish CSS
 * ==============================
 * Comprehensive styling improvements for a polished, professional admin interface
 *
 * Sections:
 * 1. CSS Design Tokens (Variables)
 * 2. Focus & Accessibility
 * 3. Button Enhancements
 * 4. Table Improvements
 * 5. Card Enhancements
 * 6. Empty States
 * 7. Loading States
 * 8. Form Enhancements
 * 9. Modal Improvements
 * 10. Toggle Switch (Standardized)
 * 11. Badge System
 * 12. Animations & Transitions
 * 13. Utility Classes
 */

/* ==========================================================================
   1. CSS DESIGN TOKENS (Variables)
   ========================================================================== */
:root {
    /* Primary Colors */
    --hd-primary: #4634ff;
    --hd-primary-rgb: 70, 52, 255;
    --hd-primary-hover: #3525d9;
    --hd-primary-light: rgba(70, 52, 255, 0.1);

    /* Status Colors */
    --hd-success: #28c76f;
    --hd-success-rgb: 40, 199, 111;
    --hd-success-light: rgba(40, 199, 111, 0.12);

    --hd-danger: #ea5455;
    --hd-danger-rgb: 234, 84, 85;
    --hd-danger-light: rgba(234, 84, 85, 0.12);

    --hd-warning: #ff9f43;
    --hd-warning-rgb: 255, 159, 67;
    --hd-warning-light: rgba(255, 159, 67, 0.12);

    --hd-info: #00cfe8;
    --hd-info-rgb: 0, 207, 232;
    --hd-info-light: rgba(0, 207, 232, 0.12);

    /* Neutral Colors */
    --hd-gray-50: #f8f9fa;
    --hd-gray-100: #f1f3f5;
    --hd-gray-200: #e9ecef;
    --hd-gray-300: #dee2e6;
    --hd-gray-400: #ced4da;
    --hd-gray-500: #adb5bd;
    --hd-gray-600: #6c757d;
    --hd-gray-700: #495057;
    --hd-gray-800: #343a40;
    --hd-gray-900: #212529;

    /* Spacing Scale */
    --hd-space-xs: 4px;
    --hd-space-sm: 8px;
    --hd-space-md: 12px;
    --hd-space-lg: 16px;
    --hd-space-xl: 20px;
    --hd-space-2xl: 24px;
    --hd-space-3xl: 32px;

    /* Shadow Scale */
    --hd-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --hd-shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --hd-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --hd-shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.16);

    /* Border Radius */
    --hd-radius-sm: 4px;
    --hd-radius-md: 6px;
    --hd-radius-lg: 8px;
    --hd-radius-xl: 12px;
    --hd-radius-full: 9999px;

    /* Transitions */
    --hd-transition-fast: 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    --hd-transition-base: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --hd-transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   2. FOCUS & ACCESSIBILITY
   ========================================================================== */

/* Universal focus ring for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--hd-primary);
    outline-offset: 2px;
}

/* Remove default outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Focus ring for buttons */
.btn:focus-visible,
button:focus-visible {
    outline: 2px solid var(--hd-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(var(--hd-primary-rgb), 0.15);
}

/* Focus ring for form controls */
.form-control:focus,
.form-select:focus {
    border-color: var(--hd-primary);
    box-shadow: 0 0 0 3px rgba(var(--hd-primary-rgb), 0.15);
}

/* Focus ring for checkboxes and radios */
.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(var(--hd-primary-rgb), 0.2);
}

/* High contrast mode support */
@media (prefers-contrast: more) {
    *:focus-visible {
        outline-width: 3px;
    }

    .badge, .hd-badge {
        border: 1px solid currentColor;
    }
}

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

/* ==========================================================================
   3. BUTTON ENHANCEMENTS
   ========================================================================== */

/* Base button transitions */
.btn {
    transition: all var(--hd-transition-base);
    position: relative;
    overflow: hidden;
}

/* Button hover lift effect */
.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

/* Button active/press effect */
.btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

/* Primary button enhancements */
.btn--primary:hover:not(:disabled) {
    background-color: var(--hd-primary-hover);
    border-color: var(--hd-primary-hover);
    box-shadow: 0 4px 12px rgba(var(--hd-primary-rgb), 0.35);
}

/* Outline button hover states */
.btn-outline--primary:hover:not(:disabled) {
    background-color: var(--hd-primary);
    border-color: var(--hd-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(var(--hd-primary-rgb), 0.25);
}

.btn-outline--success:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(var(--hd-success-rgb), 0.25);
}

.btn-outline--danger:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(var(--hd-danger-rgb), 0.25);
}

.btn-outline--warning:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(var(--hd-warning-rgb), 0.25);
}

/* Disabled button styling */
.btn:disabled,
.btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Icon-only button improvements */
.btn--sm {
    transition: all var(--hd-transition-base);
}

.btn--sm:hover:not(:disabled) {
    transform: scale(1.05);
}

.btn--sm:active:not(:disabled) {
    transform: scale(0.95);
}

/* Button group spacing */
.button--group {
    display: flex;
    gap: var(--hd-space-sm);
    flex-wrap: wrap;
}

.button--group .btn {
    margin: 0;
}

/* ==========================================================================
   4. TABLE IMPROVEMENTS
   ========================================================================== */

/* Table base styling */
.table {
    --table-hover-bg: var(--hd-gray-50);
    --table-selected-bg: rgba(var(--hd-primary-rgb), 0.05);
    --table-border-color: var(--hd-gray-200);
}

/* Table row hover effect */
.table tbody tr {
    transition: background-color var(--hd-transition-fast),
                box-shadow var(--hd-transition-fast);
}

.table tbody tr:hover {
    background-color: var(--table-hover-bg) !important;
}

/* Table row selection effect */
.table tbody tr.selected,
.table tbody tr:has(.form-check-input:checked) {
    background-color: var(--table-selected-bg) !important;
    box-shadow: inset 3px 0 0 var(--hd-primary);
}

/* Table row with checkbox - highlight on selection */
.table tbody tr:has(.row-select:checked),
.table tbody tr:has(.category-checkbox:checked) {
    background-color: var(--table-selected-bg) !important;
    box-shadow: inset 3px 0 0 var(--hd-primary);
}

/* Table header styling */
.table thead th {
    background-color: var(--hd-gray-50);
    border-bottom: 2px solid var(--hd-gray-200);
    font-weight: 600;
    color: var(--hd-gray-700);
    white-space: nowrap;
}

/* Sortable column hover */
.table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color var(--hd-transition-fast);
}

.table th.sortable:hover {
    background-color: var(--hd-gray-100);
}

/* Table cell vertical alignment */
.table td,
.table th {
    vertical-align: middle;
}

/* Improved checkbox styling in tables */
.table .form-check-input {
    cursor: pointer;
    transition: transform var(--hd-transition-fast);
}

.table .form-check-input:hover {
    transform: scale(1.15);
}

/* ==========================================================================
   5. CARD ENHANCEMENTS
   ========================================================================== */

/* Card base improvements */
.card {
    border: none;
    border-radius: var(--hd-radius-lg);
    box-shadow: var(--hd-shadow-sm);
    transition: box-shadow var(--hd-transition-base),
                transform var(--hd-transition-base);
    overflow: hidden;
}

/* Card hover effect (subtle) */
.card:hover {
    box-shadow: var(--hd-shadow-md);
}

/* Card header styling */
.card-header {
    background-color: var(--hd-gray-50);
    border-bottom: 1px solid var(--hd-gray-200);
    padding: var(--hd-space-lg);
}

/* Card footer styling */
.card-footer {
    background-color: var(--hd-gray-50);
    border-top: 1px solid var(--hd-gray-200);
}

/* Consistent card border radius */
.card,
.card .table-responsive,
.card .table {
    border-radius: var(--hd-radius-lg);
}

/* ==========================================================================
   6. EMPTY STATES
   ========================================================================== */

/* Empty state container */
.empty-state {
    text-align: center;
    padding: var(--hd-space-3xl) var(--hd-space-xl);
}

.empty-state--compact {
    padding: var(--hd-space-2xl) var(--hd-space-lg);
}

/* Empty state icon */
.empty-state__icon {
    font-size: 4rem;
    color: var(--hd-gray-300);
    margin-bottom: var(--hd-space-lg);
    opacity: 0.6;
}

.empty-state__icon i {
    display: block;
}

/* Empty state title */
.empty-state__title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--hd-gray-700);
    margin-bottom: var(--hd-space-sm);
}

/* Empty state description */
.empty-state__description {
    color: var(--hd-gray-600);
    margin-bottom: var(--hd-space-lg);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

/* Empty state action button */
.empty-state__action {
    margin-top: var(--hd-space-lg);
}

/* Table empty state (for use inside tables) */
.table-empty-state {
    padding: var(--hd-space-3xl) var(--hd-space-lg);
    text-align: center;
}

.table-empty-state__icon {
    font-size: 3.5rem;
    color: var(--hd-gray-300);
    margin-bottom: var(--hd-space-md);
}

.table-empty-state__text {
    color: var(--hd-gray-600);
    font-size: 0.9375rem;
    margin-bottom: var(--hd-space-md);
}

.table-empty-state__action {
    display: inline-block;
}

/* ==========================================================================
   7. LOADING STATES
   ========================================================================== */

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.loading-spinner--sm {
    width: 0.875em;
    height: 0.875em;
    border-width: 1.5px;
}

.loading-spinner--lg {
    width: 1.5em;
    height: 1.5em;
    border-width: 3px;
}

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

/* Button loading state */
.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1em;
    height: 1em;
    margin-top: -0.5em;
    margin-left: -0.5em;
    border: 2px solid white;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.btn-outline--primary.is-loading::after,
.btn-outline--secondary.is-loading::after {
    border-color: var(--hd-primary);
    border-right-color: transparent;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--hd-gray-100) 25%,
        var(--hd-gray-200) 50%,
        var(--hd-gray-100) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: var(--hd-radius-sm);
}

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

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

.skeleton-text:last-child {
    width: 70%;
}

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

.skeleton-thumbnail {
    width: 60px;
    height: 80px;
    border-radius: var(--hd-radius-sm);
}

/* Page loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--hd-transition-base), visibility var(--hd-transition-base);
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-overlay__content {
    text-align: center;
}

.loading-overlay__spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--hd-gray-200);
    border-top-color: var(--hd-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--hd-space-md);
}

.loading-overlay__text {
    color: var(--hd-gray-600);
    font-size: 0.9375rem;
}

/* ==========================================================================
   8. FORM ENHANCEMENTS
   ========================================================================== */

/* Form control improvements */
.form-control,
.form-select {
    transition: border-color var(--hd-transition-fast),
                box-shadow var(--hd-transition-fast);
    border-radius: var(--hd-radius-md);
}

/* Form validation states */
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--hd-danger);
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.form-control.is-valid,
.form-select.is-valid {
    border-color: var(--hd-success);
}

/* Required field indicator */
.form-label.required::after {
    content: '*';
    color: var(--hd-danger);
    margin-left: 4px;
}

/* Form group spacing */
.form-group {
    margin-bottom: var(--hd-space-lg);
}

/* Input group improvements */
.input-group .btn {
    border-radius: 0 var(--hd-radius-md) var(--hd-radius-md) 0;
}

.input-group .form-control {
    border-radius: var(--hd-radius-md) 0 0 var(--hd-radius-md);
}

/* ==========================================================================
   9. MODAL IMPROVEMENTS
   ========================================================================== */

/* Modal backdrop blur */
.modal-backdrop {
    backdrop-filter: blur(4px);
}

/* Modal content improvements */
.modal-content {
    border: none;
    border-radius: var(--hd-radius-xl);
    box-shadow: var(--hd-shadow-xl);
}

/* Modal header */
.modal-header {
    border-bottom: 1px solid var(--hd-gray-200);
    padding: var(--hd-space-lg) var(--hd-space-xl);
}

/* Modal body */
.modal-body {
    padding: var(--hd-space-xl);
}

/* Modal footer */
.modal-footer {
    border-top: 1px solid var(--hd-gray-200);
    padding: var(--hd-space-lg) var(--hd-space-xl);
}

/* Modal close button */
.modal-header .close,
.modal-header .btn-close {
    opacity: 0.5;
    transition: opacity var(--hd-transition-fast), transform var(--hd-transition-fast);
}

.modal-header .close:hover,
.modal-header .btn-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Modal animation enhancement */
.modal.fade .modal-dialog {
    transform: scale(0.95) translateY(-20px);
    transition: transform var(--hd-transition-slow);
}

.modal.show .modal-dialog {
    transform: scale(1) translateY(0);
}

/* ==========================================================================
   10. TOGGLE SWITCH (Standardized)
   ========================================================================== */

/* Standardized toggle switch - used across all pages */
.form-switch .form-check-input {
    width: 3rem !important;
    height: 1.5rem !important;
    cursor: pointer;
    transition: background-color var(--hd-transition-base),
                border-color var(--hd-transition-base);
}

.form-switch .form-check-input:checked {
    background-color: var(--hd-primary);
    border-color: var(--hd-primary);
}

.form-switch .form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(var(--hd-primary-rgb), 0.2);
}

.form-switch .form-check-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--hd-gray-700);
    margin-left: var(--hd-space-sm);
    cursor: pointer;
}

/* ==========================================================================
   11. BADGE SYSTEM
   ========================================================================== */

/* Badge base */
.badge,
.hd-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    border-radius: var(--hd-radius-md);
    transition: transform var(--hd-transition-fast),
                box-shadow var(--hd-transition-fast);
}

/* Badge hover effect */
.badge:hover,
.hd-badge:hover {
    transform: scale(1.05);
}

/* Badge sizes */
.badge--sm,
.hd-badge--sm {
    padding: 2px 6px;
    font-size: 10px;
}

.badge--md,
.hd-badge--md {
    padding: 4px 10px;
    font-size: 12px;
}

.badge--lg,
.hd-badge--lg {
    padding: 6px 14px;
    font-size: 14px;
}

/* Badge colors */
.badge--primary,
.hd-badge--primary {
    background-color: var(--hd-primary-light);
    color: var(--hd-primary);
}

.badge--success,
.hd-badge--success {
    background-color: var(--hd-success-light);
    color: #1e7e34;
}

.badge--danger,
.hd-badge--danger {
    background-color: var(--hd-danger-light);
    color: #bd2130;
}

.badge--warning,
.hd-badge--warning {
    background-color: var(--hd-warning-light);
    color: #856404;
}

.badge--info,
.hd-badge--info {
    background-color: var(--hd-info-light);
    color: #117a8b;
}

.badge--secondary,
.hd-badge--secondary {
    background-color: var(--hd-gray-100);
    color: var(--hd-gray-600);
}

/* Status indicator dot */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot--success { background-color: var(--hd-success); }
.status-dot--danger { background-color: var(--hd-danger); }
.status-dot--warning { background-color: var(--hd-warning); }
.status-dot--info { background-color: var(--hd-info); }

/* Pulse animation for processing status */
.status-dot--pulse {
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* ==========================================================================
   12. ANIMATIONS & TRANSITIONS
   ========================================================================== */

/* Fade in animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fadeIn {
    animation: fadeIn var(--hd-transition-base) ease;
}

/* Slide down animation */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-slideDown {
    animation: slideDown var(--hd-transition-slow) ease;
}

/* Slide up animation */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-slideUp {
    animation: slideUp var(--hd-transition-slow) ease;
}

/* Scale in animation */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animate-scaleIn {
    animation: scaleIn var(--hd-transition-base) ease;
}

/* Pulse animation for notifications */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

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

/* ==========================================================================
   13. UTILITY CLASSES
   ========================================================================== */

/* Spacing utilities */
.gap-xs { gap: var(--hd-space-xs); }
.gap-sm { gap: var(--hd-space-sm); }
.gap-md { gap: var(--hd-space-md); }
.gap-lg { gap: var(--hd-space-lg); }
.gap-xl { gap: var(--hd-space-xl); }

/* Shadow utilities */
.shadow-sm { box-shadow: var(--hd-shadow-sm); }
.shadow-md { box-shadow: var(--hd-shadow-md); }
.shadow-lg { box-shadow: var(--hd-shadow-lg); }
.shadow-xl { box-shadow: var(--hd-shadow-xl); }
.shadow-none { box-shadow: none; }

/* Border radius utilities */
.rounded-sm { border-radius: var(--hd-radius-sm); }
.rounded-md { border-radius: var(--hd-radius-md); }
.rounded-lg { border-radius: var(--hd-radius-lg); }
.rounded-xl { border-radius: var(--hd-radius-xl); }
.rounded-full { border-radius: var(--hd-radius-full); }

/* Text truncate */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Transition utilities */
.transition-none { transition: none !important; }
.transition-fast { transition: all var(--hd-transition-fast); }
.transition-base { transition: all var(--hd-transition-base); }
.transition-slow { transition: all var(--hd-transition-slow); }

/* Cursor utilities */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }
.cursor-grab { cursor: grab; }

/* Interactive state - clickable rows */
.clickable-row {
    cursor: pointer;
    transition: background-color var(--hd-transition-fast);
}

.clickable-row:hover {
    background-color: var(--hd-gray-50);
}

/* Visually hidden (for accessibility) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   14. RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 768px) {
    /* Smaller buttons on mobile */
    .btn--sm {
        padding: 0.25rem 0.5rem;
    }

    /* Stack button groups vertically on small screens */
    .button--group {
        flex-direction: column;
    }

    /* Reduce card padding on mobile */
    .card-body {
        padding: var(--hd-space-md);
    }

    /* Adjust empty state for mobile */
    .empty-state {
        padding: var(--hd-space-xl) var(--hd-space-md);
    }

    .empty-state__icon {
        font-size: 3rem;
    }
}

@media (max-width: 576px) {
    /* Even smaller adjustments for extra small screens */
    .empty-state__icon {
        font-size: 2.5rem;
    }

    .table-empty-state {
        padding: var(--hd-space-xl) var(--hd-space-sm);
    }
}
