/**
 * Responsive Design Enhancements for Account Page
 * Mobile-first approach with progressive enhancement
 */

/* ============================================================================
   Base Responsive Utilities
   ============================================================================ */

/* Improved container behavior */
.container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

@media (min-width: 640px) {
    .container {
        max-width: 640px;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

/* ============================================================================
   Authentication and Dashboard Containers
   ============================================================================ */

.auth-container,
.dashboard-container {
    width: 100%;
    margin: 1rem auto;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

@media (min-width: 640px) {
    .auth-container,
    .dashboard-container {
        margin: 1.5rem auto;
        padding: 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }
}

@media (min-width: 768px) {
    .auth-container {
        max-width: 500px;
        margin: 2rem auto;
        padding: 2rem;
    }
    
    .dashboard-container {
        max-width: 900px;
        margin: 2rem auto;
        padding: 2rem;
    }
}

@media (min-width: 1024px) {
    .dashboard-container {
        max-width: 1200px;
    }
}

/* ============================================================================
   Tab Navigation Responsive Design
   ============================================================================ */

.tab-container {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tab-container::-webkit-scrollbar {
    display: none;
}

.tab-container.can-scroll-left::before,
.tab-container.can-scroll-right::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px;
    pointer-events: none;
    z-index: 10;
}

.tab-container.can-scroll-left::before {
    left: 0;
    background: linear-gradient(to right, white, transparent);
}

.tab-container.can-scroll-right::after {
    right: 0;
    background: linear-gradient(to left, white, transparent);
}

.tab-btn {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: #6b7280;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: fit-content;
    font-size: 0.875rem;
}

@media (min-width: 640px) {
    .tab-btn {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

@media (min-width: 768px) {
    .tab-btn {
        padding: 0.75rem 1.5rem;
    }
}

.tab-btn:hover {
    color: #374151;
    background-color: #f9fafb;
}

.tab-btn.active {
    border-bottom-color: #3b82f6;
    color: #3b82f6;
    background-color: #eff6ff;
}

.tab-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ============================================================================
   Form Responsive Design
   ============================================================================ */

.form-group {
    margin-bottom: 1rem;
}

@media (min-width: 768px) {
    .form-group {
        margin-bottom: 1.5rem;
    }
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.5rem;
}

@media (min-width: 768px) {
    .form-label {
        font-size: 1rem;
    }
}

/* ============================================================================
   Button Responsive Design
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* Touch target minimum */
    min-width: 44px;
}

@media (min-width: 768px) {
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        min-height: auto;
        min-width: auto;
    }
}

.btn-primary {
    background-color: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-secondary {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background-color: #e5e7eb;
}

.btn-full {
    width: 100%;
}

@media (min-width: 768px) {
    .btn-full {
        width: auto;
    }
}

/* ============================================================================
   OAuth Buttons Responsive Design
   ============================================================================ */

.oauth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    color: #374151;
    text-decoration: none;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
    width: 100%;
    min-height: 48px; /* Better touch target */
    font-size: 0.875rem;
}

@media (min-width: 768px) {
    .oauth-btn {
        font-size: 1rem;
        min-height: auto;
    }
}

.oauth-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.oauth-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ============================================================================
   Card and Grid Responsive Design
   ============================================================================ */

.card-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1280px) {
    .card-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

.info-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    transition: box-shadow 0.2s ease;
}

@media (min-width: 768px) {
    .info-card {
        padding: 1.5rem;
        border-radius: 12px;
    }
}

.info-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   User Profile Responsive Design
   ============================================================================ */

.user-profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

@media (min-width: 640px) {
    .user-profile-header {
        flex-direction: row;
        text-align: left;
        align-items: flex-start;
    }
}

.user-avatar {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: #3b82f6;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .user-avatar {
        width: 5rem;
        height: 5rem;
        font-size: 2rem;
    }
}

.user-info {
    min-width: 0; /* Allow text truncation */
}

.user-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 0.25rem;
    word-break: break-word;
}

@media (min-width: 768px) {
    .user-name {
        font-size: 1.5rem;
    }
}

.user-email {
    font-size: 0.875rem;
    color: #6b7280;
    word-break: break-all;
}

@media (min-width: 768px) {
    .user-email {
        font-size: 1rem;
    }
}

/* ============================================================================
   Credit Balance Responsive Design
   ============================================================================ */

.credit-balance-card {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
}

@media (min-width: 768px) {
    .credit-balance-card {
        padding: 2rem;
        text-align: left;
    }
}

.credit-amount {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

@media (min-width: 768px) {
    .credit-amount {
        font-size: 3rem;
    }
}

.credit-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

@media (min-width: 768px) {
    .credit-label {
        font-size: 1rem;
    }
}

/* ============================================================================
   Toast Notifications Responsive Design
   ============================================================================ */

#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 50;
    max-width: calc(100vw - 2rem);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    #toast-container {
        max-width: 400px;
    }
}

.toast {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-left: 4px solid #3b82f6;
    font-size: 0.875rem;
    line-height: 1.4;
    word-break: break-word;
}

@media (min-width: 768px) {
    .toast {
        font-size: 1rem;
        padding: 1.25rem;
    }
}

/* ============================================================================
   Loading States and Skeletons
   ============================================================================ */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
}

.animate-pulse .skeleton {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ============================================================================
   Accessibility Enhancements
   ============================================================================ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.focus-visible:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 1rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 1rem;
}

/* ============================================================================
   Dark Theme Support Preparation
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    .auto-theme .auth-container,
    .auto-theme .dashboard-container {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .auto-theme .form-input {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
    
    .auto-theme .info-card {
        background: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }
}

/* ============================================================================
   High Contrast Support
   ============================================================================ */

@media (prefers-contrast: high) {
    .tab-btn {
        border: 1px solid currentColor;
    }
    
    .tab-btn.active {
        background: #3b82f6;
        color: white;
    }
    
    .form-input {
        border-width: 2px;
    }
    
    .btn {
        border: 2px 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;
    }
    
    .animate-pulse {
        animation: none;
    }
}

/* ============================================================================
   Print Styles
   ============================================================================ */

@media print {
    .tab-container,
    .oauth-btn,
    .btn,
    #toast-container {
        display: none !important;
    }
    
    .dashboard-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .user-profile-header {
        page-break-inside: avoid;
    }
    
    .info-card {
        page-break-inside: avoid;
        border: 1px solid #000;
        margin-bottom: 1rem;
    }
}

/* ============================================================================
   Ultra-wide Screen Support
   ============================================================================ */

@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }
    
    .dashboard-container {
        max-width: 1400px;
    }
    
    .card-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .card-grid-4 {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ============================================================================
   Touch Device Optimizations
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {
    /* Touch device styles */
    .tab-btn,
    .btn,
    .oauth-btn {
        min-height: 48px;
        touch-action: manipulation;
    }
    
    .form-input {
        min-height: 48px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Remove hover states on touch devices */
    .tab-btn:hover,
    .btn:hover,
    .oauth-btn:hover,
    .info-card:hover {
        background-color: initial;
        border-color: initial;
        box-shadow: initial;
    }
}

/* ============================================================================
   Landscape Orientation on Mobile
   ============================================================================ */

@media (max-height: 640px) and (orientation: landscape) {
    .auth-container,
    .dashboard-container {
        margin: 0.5rem auto;
        padding: 1rem;
    }
    
    .user-profile-header {
        margin-bottom: 1rem;
    }
    
    .tab-container {
        margin-bottom: 1rem;
    }
}

/* ============================================================================
   Error and Warning States
   ============================================================================ */

.error-state {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.warning-state {
    border-color: #f59e0b !important;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1) !important;
}

.success-state {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

/* ============================================================================
   Offline Indicator
   ============================================================================ */

#offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 100;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}