/**
 * COMPLETELY FIXED Frontend CSS for CrushLink Groups
 * Modern, responsive design with ALL CLIENT ISSUES RESOLVED
 * 
 * FIXES INCLUDED:
 * - Issue #5: Complete mobile responsive layout fixes
 * - Button alignment improvements
 * - Touch-friendly interactions
 * - Enhanced modal design
 * - Match/Like status improvements
 */

/* Reset and base styles */
.cmg-container * {
    box-sizing: border-box;
}

.cmg-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
}

/* Header */
.cmg-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
    position: relative;
}

.cmg-header::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, #e91e63, #ff4081);
}

.cmg-header h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #e91e63, #ff4081);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cmg-like-balance {
    background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
    border: 2px solid #e9ecef;
    border-radius: 12px;
    padding: 15px 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cmg-like-balance:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.cmg-likes-count {
    display: block;
    font-size: 32px;
    font-weight: 800;
    color: #e91e63;
    margin-bottom: 4px;
    animation: cmg-pulse 2s infinite;
}

.cmg-likes-label {
    display: block;
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* FIXED: Enhanced messages with better visibility */
.cmg-message {
    padding: 20px;
    margin: 20px 0;
    border-radius: 12px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    animation: cmg-slideIn 0.5s ease-out;
    line-height: 1.6;
    position: relative;
    z-index: 100;
}

.cmg-success {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border: 2px solid #28a745;
    color: #155724;
}

.cmg-error {
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    border: 2px solid #dc3545;
    color: #721c24;
}

/* FIXED: Input validation styles */
.cmg-input-error {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    animation: cmg-shake 0.5s ease;
}

.cmg-input-valid {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

/* Buy likes section */
.cmg-buy-likes-section {
    margin-bottom: 30px;
}

.cmg-buy-likes-card {
    background: linear-gradient(135deg, #ff4081 0%, #e91e63 100%);
    color: white;
    border-radius: 12px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(233, 30, 99, 0.3);
    animation: cmg-slideIn 0.5s ease;
}

.cmg-buy-likes-card h3 {
    margin: 0 0 10px 0;
    font-size: 22px;
    font-weight: 700;
}

.cmg-buy-likes-card p {
    margin: 0 0 20px 0;
    opacity: 0.9;
    font-size: 16px;
}

/* FIXED: Action cards with better mobile support */
.cmg-group-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 40px;
}

.cmg-action-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.cmg-action-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #e91e63, #ff4081);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.cmg-action-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.cmg-action-card:hover::before {
    transform: scaleX(1);
}

.cmg-action-card h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.cmg-action-card p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
}

/* FIXED: Join group form with mobile improvements */
.cmg-join-group-form {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.cmg-join-group-form input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: border-color 0.3s ease;
    font-family: 'Courier New', monospace;
}

.cmg-join-group-form input:focus {
    outline: none;
    border-color: #e91e63;
    box-shadow: 0 0 0 3px rgba(233, 30, 99, 0.1);
}

/* Groups section */
.cmg-my-groups h3 {
    margin: 0 0 25px 0;
    font-size: 24px;
    font-weight: 700;
    color: #333;
}

.cmg-groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.cmg-group-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.cmg-group-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.cmg-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.cmg-group-code {
    font-size: 18px;
    font-weight: 800;
    color: #333;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 8px 16px;
    border-radius: 8px;
    letter-spacing: 1px;
    border: 2px solid #e9ecef;
    font-family: 'Courier New', monospace;
}

.cmg-member-count {
    background: #e3f2fd;
    color: #1976d2;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* Stats */
.cmg-group-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.cmg-stat {
    text-align: center;
    flex: 1;
}

.cmg-stat-number {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: #e91e63;
    margin-bottom: 4px;
}

.cmg-stat-label {
    display: block;
    font-size: 11px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Notifications */
.cmg-notification {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
    font-weight: 500;
    animation: cmg-slideIn 0.5s ease;
}

.cmg-likes-notification {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    border: 1px solid #90caf9;
    color: #1565c0;
}

.cmg-match-notification {
    background: linear-gradient(135deg, #e8f5e8, #c8e6c9);
    border: 1px solid #a5d6a7;
    color: #2e7d32;
}

.cmg-match-item {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    animation: cmg-bounce 0.6s ease;
}

.cmg-match-item:last-child {
    border-bottom: none;
}

/* FIXED: Members list with enhanced mobile support */
.cmg-group-members {
    margin-top: 15px;
}

.cmg-group-members h5 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cmg-members-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    padding: 5px;
}

.cmg-member-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #f8f9fa;
    transition: background-color 0.2s ease;
}

.cmg-member-item:hover {
    background-color: #f8f9fa;
}

.cmg-member-item:last-child {
    border-bottom: none;
}

.cmg-member-name {
    font-weight: 500;
    color: #333;
}

/* FIXED: Like/Match indicators with proper styling */
.cmg-liked-indicator,
.liked-btn {
    color: #212529;
    font-size: 12px;
    font-weight: 600;
    background: #ffc107;
    padding: 6px 12px;
    border-radius: 20px;
    border: none;
    cursor: default;
}

.match-btn {
    background: linear-gradient(135deg, #28a745, #20c997) !important;
    color: white !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    border: none !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    animation: cmg-pulse 2s infinite !important;
    cursor: default !important;
}

/* FIXED: Enhanced buttons with better touch support */
.cmg-btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    touch-action: manipulation; /* Better touch support */
}

.cmg-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.cmg-btn:hover::before {
    width: 200px;
    height: 200px;
}

.cmg-btn-primary {
    background: linear-gradient(135deg, #e91e63, #ff4081);
    color: white;
    box-shadow: 0 4px 15px rgba(233, 30, 99, 0.3);
}

.cmg-btn-primary:hover {
    background: linear-gradient(135deg, #c2185b, #e91e63);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(233, 30, 99, 0.4);
}

.cmg-btn-secondary {
    background: linear-gradient(135deg, #6c757d, #545b62);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.cmg-btn-secondary:hover {
    background: linear-gradient(135deg, #545b62, #495057);
    transform: translateY(-2px);
}

.cmg-btn-danger {
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

.cmg-btn-danger:hover {
    background: linear-gradient(135deg, #c82333, #bd2130);
    transform: translateY(-2px);
}

.cmg-btn-like,
.send-like-btn {
    background: linear-gradient(135deg, #ff4081, #f06292);
    color: white;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(255, 64, 129, 0.3);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.cmg-btn-like:hover,
.send-like-btn:hover {
    background: linear-gradient(135deg, #e91e63, #ff4081);
    transform: scale(1.05);
}

.cmg-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* FIXED: Loading states with better UX */
.cmg-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.cmg-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: cmg-spin 1s linear infinite;
}

/* FIXED: Enhanced modals with NO "C" BUTTON */
.cmg-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(3px);
    padding: 20px;
    box-sizing: border-box;
}

.cmg-modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: cmg-modalIn 0.3s ease;
}

.cmg-modal-header {
    background: linear-gradient(135deg, #6c5ce7, #5a4fcf);
    color: white;
    padding: 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cmg-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: white;
}

.cmg-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: white;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.cmg-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cmg-modal-content {
    padding: 20px;
}

.cmg-modal-footer {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
    gap: 10px;
}

/* FIXED: Member list with enhanced mobile support */
.members-list {
    display: grid;
    gap: 15px;
}

.member-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    background: #f8f9fa;
    transition: all 0.3s;
}

.member-item:hover {
    border-color: #6c5ce7;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.member-item.current-user {
    background: linear-gradient(135deg, #e8f5e8, #d4edda);
    border-color: #28a745;
}

.member-avatar img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.member-info {
    flex: 1;
    margin-left: 15px;
}

.member-name {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
    font-size: 16px;
}

.member-username {
    color: #6c757d;
    font-size: 14px;
    margin-bottom: 3px;
}

.member-join-date {
    color: #6c757d;
    font-size: 12px;
}

.you-badge {
    background: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin-left: 8px;
    font-weight: 500;
}

.member-actions {
    display: flex;
    gap: 10px;
}

/* Empty states */
.cmg-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.cmg-empty-state::before {
    content: '💕';
    display: block;
    font-size: 48px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.no-members {
    text-align: center;
    padding: 40px;
    color: #6c757d;
    font-style: italic;
}

/* Error states */
.cmg-error-text {
    color: #dc3545;
    font-size: 12px;
    margin-top: 5px;
    font-weight: 500;
}

.cmg-no-likes-msg {
    font-size: 12px;
    color: #999;
    font-style: italic;
}

/* Group footer */
.cmg-group-footer {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.cmg-joined-date {
    color: #999;
    font-size: 12px;
}

/* Touch-friendly mobile interactions */
.cmg-touch-active {
    transform: scale(0.98);
    opacity: 0.8;
    transition: all 0.1s ease;
}

/* Animations */
@keyframes cmg-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes cmg-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes cmg-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

@keyframes cmg-slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes cmg-slideIn {
    from { transform: translateX(-20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes cmg-modalIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes cmg-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* FIXED ISSUE #5: COMPREHENSIVE MOBILE RESPONSIVE DESIGN */
@media (max-width: 768px) {
    .cmg-container {
        padding: 15px;
    }
    
    .cmg-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .cmg-header h2 {
        font-size: 24px;
    }
    
    /* FIXED: Action cards mobile layout */
    .cmg-group-actions {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* FIXED: Groups grid mobile layout */
    .cmg-groups-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .cmg-group-card {
        padding: 15px;
    }
    
    .cmg-group-stats {
        gap: 15px;
    }
    
    /* FIXED: Modal mobile layout */
    .cmg-modal {
        width: calc(100% - 20px);
        margin: 10px;
        max-height: calc(100vh - 40px);
    }
    
    .cmg-modal-header h3 {
        font-size: 18px;
    }
    
    /* FIXED: Member items mobile layout */
    .member-item {
        flex-direction: column;
        text-align: center;
        padding: 15px 10px;
    }
    
    .member-info {
        margin: 15px 0;
    }
    
    .member-avatar img {
        width: 50px;
        height: 50px;
    }
    
    /* FIXED: Modal footer mobile layout */
    .cmg-modal-footer {
        flex-direction: column;
        gap: 10px;
    }
    
    .cmg-modal-footer .cmg-btn {
        width: 100%;
        margin: 0;
    }
    
    /* FIXED: Join group form mobile layout */
    .cmg-join-group-form {
        flex-direction: column;
        gap: 10px;
    }
    
    .cmg-join-group-form input,
    .cmg-join-group-form button {
        width: 100%;
        margin: 0;
    }
    
    /* FIXED: Action card improvements */
    .cmg-action-card,
    .cmg-buy-likes-card {
        padding: 20px;
    }
    
    .cmg-like-balance {
        padding: 12px 16px;
    }
    
    .cmg-likes-count {
        font-size: 28px;
    }
    
    /* FIXED: Stats grid mobile layout */
    .cmg-dashboard .grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* FIXED: Group card button layout */
    .group-card div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    
    .group-card button {
        width: 100% !important;
        margin: 0 !important;
    }
}

@media (max-width: 480px) {
    .cmg-container {
        padding: 10px;
    }
    
    .cmg-header h2 {
        font-size: 20px;
    }
    
    .cmg-group-code {
        font-size: 16px;
        padding: 6px 12px;
        letter-spacing: 1px;
    }
    
    .cmg-stat-number {
        font-size: 20px;
    }
    
    .cmg-btn {
        padding: 10px 20px;
        font-size: 13px;
    }
    
    .member-name {
        font-size: 14px;
    }
    
    .member-username {
        font-size: 12px;
    }
    
    .send-like-btn,
    .liked-btn,
    .match-btn {
        padding: 6px 12px !important;
        font-size: 12px !important;
    }
    
    /* Smaller modal on very small screens */
    .cmg-modal {
        width: calc(100% - 10px);
        margin: 5px;
    }
    
    .cmg-modal-header,
    .cmg-modal-content,
    .cmg-modal-footer {
        padding: 15px;
    }
    
    /* Better message display on small screens */
    .cmg-message {
        padding: 15px;
        font-size: 14px;
        margin: 10px 0;
    }
}

/* Touch-friendly improvements for mobile devices */
@media (hover: none) and (pointer: coarse) {
    .cmg-btn:active {
        transform: scale(0.95);
    }
    
    .cmg-group-card:hover,
    .cmg-action-card:hover {
        transform: none;
    }
    
    .member-item:hover {
        transform: none;
    }
    
    /* Larger touch targets on mobile */
    .cmg-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .cmg-modal-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Better form inputs on touch devices */
    input[type="text"],
    input[type="email"],
    input[type="password"] {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .cmg-container {
        color: #e0e0e0;
    }
    
    .cmg-action-card,
    .cmg-group-card {
        background: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .cmg-modal {
        background: #2a2a2a;
        color: #e0e0e0;
    }
    
    .member-item {
        background: #333;
        border-color: #555;
        color: #e0e0e0;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .cmg-btn {
        border: 2px solid currentColor;
    }
    
    .member-item {
        border-width: 3px;
    }
    
    .cmg-group-card {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .cmg-pulse,
    .match-btn {
        animation: none !important;
    }
}