/**
 * Bactizad Formulator - UI Components & Enhancements (Consolidated)
 * 
 * This file combines components.css and enhancements.css for better performance.
 * Includes all component styles, animations, micro-interactions, and visual feedback.
 * 
 * @version 2.3.0 - Consolidated for optimization
 * @author Bactizad Development Team
 */

/* ========================================================================== */
/* COMPONENT STYLES                                                           */
/* ========================================================================== */

/* Wizard Progress */
.wizard-progress {
    background: #eef2ff;
    color: #3730a3;
    border: 1px solid #e0e7ff;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Users Page Cards */
.user-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.user-card { background:#fff; border:1px solid #e5e7eb; border-radius:12px; padding:1rem; box-shadow:0 2px 8px rgba(0,0,0,0.06); display:flex; flex-direction:column; gap:0.5rem; }
.user-card .name { font-weight:700; color:#111827; }
.user-card .meta { color:#6b7280; font-size:0.85rem; }
.user-card .actions { display:flex; gap:0.5rem; }

/* Data Table Enhancements */
.data-table {
    position: relative;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.data-table tbody tr {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.data-table tbody tr:hover {
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
    transform: scale(1.01);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* Action Buttons in Tables */
.action-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.action-btn {
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.action-btn-edit {
    background: #f3f4f6;
    color: #111827;
    border: 1px solid #e5e7eb;
}

.action-btn-edit:hover {
    background: #e5e7eb;
    color: #111827;
}

.action-btn-delete {
    background: #fff7f7;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.action-btn-delete:hover {
    background: #fee2e2;
    color: #991b1b;
}

/* Formulation Row Component */
.formulation-row {
    position: relative;
    transition: all 0.3s ease;
}

.formulation-row:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

.formulation-row .form-group {
    margin-bottom: 0;
}

.formulation-row .remove-btn {
    position: static;
    background: transparent;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.remove-btn:hover,
.remove-btn:focus-visible {
    background: #fee2e2;
    transform: translateY(-1px);
    outline: none;
}

/* Optimization Bounds Editor */
.bounds-editor {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    border: 1px solid #e9ecef;
}

/* Ingredient Checklist */
.ingredient-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    padding: 0.5rem;
}

.ingredient-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #f3f4f6;
}

.ingredient-list-item:last-child {
    border-bottom: none;
}

.ingredient-name {
    color: #111827;
    font-weight: 500;
}

.ingredient-meta {
    color: #6b7280;
    font-size: 0.8rem;
}

.bounds-editor h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

/* Optimization Results */
.optimization-results {
    background: linear-gradient(135deg, #e8f5e8, #f0f8f0);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
    border: 1px solid #d4edda;
}

.optimization-results h3 {
    color: #155724;
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.optimization-results h3::before {
    content: '✓';
    background: #28a745;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Cost Display */
.cost-display {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    text-align: center;
}

.cost-display .cost-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #856404;
    margin-bottom: 0.25rem;
}

.cost-display .cost-label {
    font-size: 0.9rem;
    color: #856404;
    font-weight: 500;
}

/* Constraint Status Indicators */
.constraint-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.constraint-met {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.constraint-violated {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.constraint-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Progress Indicators */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2980b9);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-active {
    background: #d4edda;
    color: #155724;
}

.status-inactive {
    background: #f8d7da;
    color: #721c24;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

/* Input Groups */
.input-group {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e9ecef;
    transition: all 0.3s ease;
}

.input-group:focus-within {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.input-group .form-control {
    border: none;
    border-radius: 0;
    flex: 1;
}

.input-group .input-addon {
    background: #f8f9fa;
    padding: 0.75rem;
    border-left: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    color: #6c757d;
    font-weight: 500;
    white-space: nowrap;
}

/* Card Components */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    overflow: hidden;
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.card-header {
    background: #f8f9fa;
    padding: 1.5rem;
    border-bottom: 1px solid #e9ecef;
}

.card-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.2rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    background: #f8f9fa;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Alert Components */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeaa7;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}

.alert i {
    font-size: 1.2rem;
    margin-top: 0.1rem;
}

/* Dropdown Enhancements */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    transition: all 0.3s ease;
    width: 100%;
}

.dropdown-toggle:hover {
    border-color: #3498db;
}

.dropdown-toggle:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
    border-bottom: 1px solid #f8f9fa;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: #f8f9fa;
}

.dropdown-item.selected {
    background: #e3f2fd;
    color: #1976d2;
    font-weight: 500;
}

/* ========================================================================== */
/* LOADING STATES                                                             */
/* ========================================================================== */

/* Skeleton Loader for Tables */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeletonLoading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

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

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

.skeleton-heading {
    height: 1.5em;
    width: 40%;
    margin-bottom: 1em;
}

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

.btn.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-secondary.loading::before,
.btn-outline.loading::before {
    border-color: rgba(37, 99, 235, 0.3);
    border-top-color: #2563eb;
}

/* General Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Progress Indicator */
.progress-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    z-index: 9999;
    overflow: hidden;
}

.progress-indicator.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, #2563eb, transparent);
    animation: progressSlide 1.5s ease-in-out infinite;
}

@keyframes progressSlide {
    to { left: 100%; }
}

/* ========================================================================== */
/* MICRO-INTERACTIONS                                                         */
/* ========================================================================== */

/* Ripple Effect for Buttons */
.btn {
    position: relative;
    overflow: hidden;
}

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

.btn:active::after {
    width: 300px;
    height: 300px;
}

/* Input Focus Glow */
.form-control {
    position: relative;
}

.form-control:focus {
    animation: inputGlow 0.3s ease-out;
}

@keyframes inputGlow {
    0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4); }
    100% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1); }
}

/* Checkbox Animation */
input[type="checkbox"] {
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
}

input[type="checkbox"]:checked {
    animation: checkboxPop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes checkboxPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ========================================================================== */
/* SUCCESS/ERROR ANIMATIONS                                                   */
/* ========================================================================== */

/* Success Checkmark Animation */
@keyframes successCheckmark {
    0% {
        opacity: 0;
        transform: scale(0) rotate(45deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.2) rotate(45deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(45deg);
    }
}

.success-checkmark {
    animation: successCheckmark 0.5s ease-out;
}

/* Error Shake Animation */
@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.error-shake {
    animation: errorShake 0.5s ease;
}

/* ========================================================================== */
/* NOTIFICATION ANIMATIONS                                                    */
/* ========================================================================== */

.notification-enter {
    animation: notificationSlideIn 0.3s ease-out;
}

.notification-exit {
    animation: notificationSlideOut 0.3s ease-in;
}

@keyframes notificationSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes notificationSlideOut {
    from {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
}

/* ========================================================================== */
/* MODAL ANIMATIONS                                                           */
/* ========================================================================== */

.modal {
    animation: modalFadeIn 0.3s ease-out;
}

.modal.closing {
    animation: modalFadeOut 0.3s ease-in;
}

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

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

.modal-content {
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.closing .modal-content {
    animation: modalSlideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalSlideDown {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
}

/* ========================================================================== */
/* TABLE ENHANCEMENTS                                                         */
/* ========================================================================== */

/* Row Highlight on Add/Update */
@keyframes rowHighlight {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(16, 185, 129, 0.1);
    }
}

.data-table tbody tr.just-added {
    animation: rowHighlight 2s ease;
}

.data-table tbody tr.just-updated {
    animation: rowHighlight 1.5s ease;
}

/* Smooth Row Removal */
@keyframes rowFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

.data-table tbody tr.removing {
    animation: rowFadeOut 0.3s ease-out forwards;
}

/* ========================================================================== */
/* TOOLTIP ENHANCEMENTS                                                       */
/* ========================================================================== */

.tooltip {
    position: relative;
    cursor: help;
}

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

.tooltip::after {
    content: '';
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    border: 5px solid transparent;
    border-top-color: #1f2937;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tooltip:hover::before,
.tooltip:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ========================================================================== */
/* BADGE ANIMATIONS                                                           */
/* ========================================================================== */

/* Badge animations removed - badges display statically for better readability */

/* ========================================================================== */
/* EMPTY STATES                                                               */
/* ========================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    animation: emptyStateFadeIn 0.5s ease-out;
}

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

.empty-state-icon {
    font-size: 4rem;
    color: #d1d5db;
    margin-bottom: 1rem;
    animation: emptyStateIconFloat 3s ease-in-out infinite;
}

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

/* ========================================================================== */
/* METRIC CARDS PULSE                                                         */
/* ========================================================================== */

.metric-card.updating {
    animation: metricPulse 0.5s ease;
}

@keyframes metricPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 6px 16px rgba(37, 99, 235, 0.2);
    }
}

/* ========================================================================== */
/* BUTTON GROUPS                                                              */
/* ========================================================================== */

.btn-group {
    display: inline-flex;
    gap: 0;
}

.btn-group .btn {
    border-radius: 0;
    margin-left: -1px;
}

.btn-group .btn:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    margin-left: 0;
}

.btn-group .btn:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

.btn-group .btn:hover,
.btn-group .btn:focus {
    z-index: 1;
}

/* ========================================================================== */
/* SCROLL INDICATORS                                                          */
/* ========================================================================== */

.scroll-indicator {
    position: relative;
}

.scroll-indicator::after {
    content: '→';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.5rem 1rem;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95));
    color: #6b7280;
    font-size: 1.5rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.scroll-indicator.has-overflow::after {
    opacity: 1;
}

/* ========================================================================== */
/* FOCUS RING ENHANCEMENT                                                     */
/* ========================================================================== */

*:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.5);
    outline-offset: 2px;
    transition: outline-offset 0.2s ease;
}

/* ========================================================================== */
/* ACCESSIBILITY & RESPONSIVENESS                                             */
/* ========================================================================== */

/* 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;
    }
}

/* Dark Mode Transitions */
@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    }
    
    .tooltip::before {
        background: #f3f4f6;
        color: #111827;
    }
    
    .tooltip::after {
        border-top-color: #f3f4f6;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .tab-nav,
    .panel-actions,
    .btn,
    .modal {
        display: none !important;
    }
    
    .layout {
        grid-template-columns: 1fr;
    }
    
    .content {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .data-table {
        font-size: 0.8rem;
    }
    
    .metric-card {
        break-inside: avoid;
    }
}

