/* ========================== Button System - Unified & Responsive ========================== */

/* Base Button Styles */
.btn-system {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 40px; /* Reduced from 44px */
    position: relative;
    overflow: hidden;
}

/* Button Sizes */
.btn-system-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    min-height: 32px;
}

.btn-system-lg {
    padding: 0.8rem 1.6rem;
    font-size: 1.05rem;
    min-height: 48px;
}

.btn-system-xl {
    padding: 1rem 2rem;
    font-size: 1.15rem;
    min-height: 56px;
}

/* Button Variants */
.btn-system-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: #fff;
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.2);
}

.btn-system-primary:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    border-color: #0056b3;
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
    transform: translateY(-1px);
}

.btn-system-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 123, 255, 0.2);
}

.btn-system-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #545b62 100%);
    color: #fff;
    border-color: #6c757d;
    box-shadow: 0 2px 4px rgba(108, 117, 125, 0.2);
}

.btn-system-secondary:hover {
    background: linear-gradient(135deg, #545b62 0%, #3d4449 100%);
    border-color: #545b62;
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.3);
    transform: translateY(-1px);
}

.btn-system-success {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    color: #fff;
    border-color: #28a745;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.2);
}

.btn-system-success:hover {
    background: linear-gradient(135deg, #1e7e34 0%, #155724 100%);
    border-color: #1e7e34;
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
    transform: translateY(-1px);
}

.btn-system-danger {
    background: linear-gradient(135deg, #dc3545 0%, #bd2130 100%);
    color: #fff;
    border-color: #dc3545;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.2);
}

.btn-system-danger:hover {
    background: linear-gradient(135deg, #bd2130 0%, #a71e2a 100%);
    border-color: #bd2130;
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
    transform: translateY(-1px);
}

.btn-system-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    color: #212529;
    border-color: #ffc107;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.2);
}

.btn-system-warning:hover {
    background: linear-gradient(135deg, #e0a800 0%, #d39e00 100%);
    border-color: #e0a800;
    box-shadow: 0 4px 8px rgba(255, 193, 7, 0.3);
    transform: translateY(-1px);
}

.btn-system-info {
    background: linear-gradient(135deg, #17a2b8 0%, #117a8b 100%);
    color: #fff;
    border-color: #17a2b8;
    box-shadow: 0 2px 4px rgba(23, 162, 184, 0.2);
}

.btn-system-info:hover {
    background: linear-gradient(135deg, #117a8b 0%, #0c5460 100%);
    border-color: #117a8b;
    box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
    transform: translateY(-1px);
}

/* Outline Variants */
.btn-system-outline-primary {
    background: transparent;
    color: #007bff;
    border-color: #007bff;
}

.btn-system-outline-primary:hover {
    background: #007bff;
    color: #fff;
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
    transform: translateY(-1px);
}

.btn-system-outline-secondary {
    background: transparent;
    color: #6c757d;
    border-color: #6c757d;
}

.btn-system-outline-secondary:hover {
    background: #6c757d;
    color: #fff;
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.2);
    transform: translateY(-1px);
}

/* Ghost/Text Variants */
.btn-system-ghost {
    background: transparent;
    color: #007bff;
    border: none;
    box-shadow: none;
}

.btn-system-ghost:hover {
    background: rgba(0, 123, 255, 0.1);
    color: #0056b3;
}

/* Button Shapes */
.btn-system-rounded {
    border-radius: 2rem;
}

.btn-system-pill {
    border-radius: 50px;
}

.btn-system-square {
    border-radius: 0;
}

/* Button States */
.btn-system:disabled,
.btn-system.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-system.loading {
    pointer-events: none;
    opacity: 0.8;
}

.btn-system.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: btn-loading-spin 1s linear infinite;
}

@keyframes btn-loading-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Button Groups */
.btn-system-group {
    display: inline-flex;
    vertical-align: middle;
}

.btn-system-group .btn-system {
    position: relative;
    flex: 1 1 auto;
    margin-right: -1px;
}

.btn-system-group .btn-system:not(:first-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.btn-system-group .btn-system:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

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

/* Full Width Buttons */
.btn-system-block {
    display: flex;
    width: 100%;
}

/* Icon Buttons */
.btn-system-icon-only {
    padding: 0.75rem;
    width: 44px;
    height: 44px;
}

.btn-system-icon-only.btn-system-sm {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
}

.btn-system-icon-only.btn-system-lg {
    padding: 1rem;
    width: 52px;
    height: 52px;
}

/* Floating Action Button */
.btn-system-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.btn-system-fab:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* ========================== Mobile Responsive ========================== */

/* Mobile optimizations */
@media (max-width: 767.98px) {
    .btn-system {
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
        min-height: 48px; /* Larger touch target on mobile */
    }
    
    .btn-system-sm {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 40px;
    }
    
    .btn-system-lg {
        padding: 1.125rem 1.75rem;
        font-size: 1.125rem;
        min-height: 56px;
    }
    
    .btn-system-xl {
        padding: 1.375rem 2rem;
        font-size: 1.25rem;
        min-height: 64px;
    }
    
    /* Mobile button groups stack vertically */
    .btn-system-group-mobile-stack {
        flex-direction: column;
    }
    
    .btn-system-group-mobile-stack .btn-system {
        margin-right: 0;
        margin-bottom: -1px;
        border-radius: 0.5rem;
    }
    
    .btn-system-group-mobile-stack .btn-system:not(:first-child) {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
    
    .btn-system-group-mobile-stack .btn-system:not(:last-child) {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
    
    /* Adjust FAB position on mobile */
    .btn-system-fab {
        bottom: 1rem;
        right: 1rem;
        width: 48px;
        height: 48px;
    }
}

/* Extra small devices */
@media (max-width: 575.98px) {
    .btn-system {
        font-size: 0.95rem;
    }
    
    .btn-system-block {
        margin-bottom: 0.75rem;
    }
    
    /* Stack buttons on very small screens */
    .btn-system-responsive-stack .btn-system {
        display: block;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-system-responsive-stack .btn-system:last-child {
        margin-bottom: 0;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn-system {
        min-height: 48px;
    }
    
    .btn-system-sm {
        min-height: 44px;
    }
    
    .btn-system-lg {
        min-height: 56px;
    }
    
    /* Remove hover effects on touch devices */
    .btn-system:hover {
        transform: none;
    }
    
    .btn-system:active {
        transform: scale(0.98);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-system {
        border-width: 2px;
    }
    
    .btn-system-ghost {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .btn-system {
        transition: none;
    }
    
    .btn-system.loading::after {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .btn-system-ghost {
        color: #66b3ff;
    }
    
    .btn-system-ghost:hover {
        background: rgba(102, 179, 255, 0.1);
        color: #99ccff;
    }
}

/* ========================== Utility Classes ========================== */

/* Spacing utilities for buttons */
.btn-system + .btn-system {
    margin-left: 0.5rem;
}

.btn-system-group .btn-system + .btn-system {
    margin-left: 0;
}

/* Focus styles for accessibility */
.btn-system:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.btn-system:focus:not(:focus-visible) {
    outline: none;
}

/* Animation classes */
.btn-system-bounce:hover {
    animation: btn-bounce 0.6s ease;
}

@keyframes btn-bounce {
    0%, 20%, 60%, 100% { transform: translateY(0); }
    40% { transform: translateY(-3px); }
    80% { transform: translateY(-1px); }
}

.btn-system-pulse:hover {
    animation: btn-pulse 1s ease-in-out;
}

@keyframes btn-pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(0, 123, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 123, 255, 0); }
}