/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* General Layout */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: #111827;
    line-height: 1.6;
    color: #e5e7eb;
}

/* Container Styles */
.form-container {
    background: #1f2937;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
    border: 1px solid #374151;
}

/* Form Elements */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #e5e7eb;
    font-size: 14px;
}

input, select {
    width: 100%;
    padding: 12px;
    border: 1px solid #374151;
    border-radius: 6px;
    font-size: 16px; /* Prevents zoom on iOS */
    background-color: #1f2937;
    color: #e5e7eb;
    transition: all 0.2s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    background-color: #262f3f;
}

input::placeholder {
    color: #6b7280;
}

/* Button Styles */
button {
    background-color: #3b82f6;
    color: #ffffff;
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-right: 5px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px; /* Touch target size */
    white-space: nowrap;
}

button:hover {
    background-color: #2563eb;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background-color: #4b5563;
    cursor: not-allowed;
    opacity: 0.7;
}

.delete-btn {
    background-color: #dc2626;
}

.delete-btn:hover {
    background-color: #b91c1c;
}

.refresh-btn, .sync-btn {
    background-color: #3b82f6;
}

.refresh-btn:hover, .sync-btn:hover {
    background-color: #2563eb;
}

.install-btn {
    display: inline-block;
    text-decoration: none;
    background-color: #059669;
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-height: 44px;
}

.install-btn:hover {
    background-color: #047857;
}

/* Grid Layouts */
.addon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.users-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

/* Card Styles */
.addon-item, .user-item {
    background: #1f2937;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    border: 1px solid #374151;
}

.addon-item:hover, .user-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.3);
    border-color: #4b5563;
}

/* Addon Specific Styles */
.addon-item img {
    max-width: 100px;
    height: auto;
    margin-bottom: 10px;
    border-radius: 6px;
}

.addon-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.addon-title {
    margin: 0;
    font-size: 1.2em;
    color: #e5e7eb;
    font-weight: 600;
    word-break: break-word;
}

.addon-version {
    color: #9ca3af;
    font-size: 0.9em;
}

.addon-description {
    margin: 10px 0;
    color: #d1d5db;
    font-size: 0.95em;
    line-height: 1.5;
}

.addon-url {
    word-break: break-all;
    color: #9ca3af;
    font-size: 0.85em;
    padding: 8px;
    background: #262f3f;
    border-radius: 4px;
    border: 1px solid #374151;
}

/* Progress Bar Styles */
.sync-progress {
    margin: 15px 0;
    padding: 12px;
    background: #262f3f;
    border-radius: 6px;
    border: 1px solid #374151;
}

.sync-status {
    margin-bottom: 8px;
    font-size: 14px;
    color: #9ca3af;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #374151;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #3b82f6;
    width: 0;
    transition: width 0.3s ease;
}

/* Loading States */
.loading {
    text-align: center;
    padding: 20px;
    color: #9ca3af;
}

.loading i {
    color: #3b82f6;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Button Groups */
.button-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* File Input Styling */
input[type="file"] {
    display: none;
}

.file-input-label {
    display: inline-block;
    padding: 12px 16px;
    background-color: #4b5563;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
}

.file-input-label:hover {
    background-color: #374151;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
    background: #1f2937;
    border-radius: 8px;
    border: 2px dashed #374151;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: #4b5563;
}

/* Error States */
.error {
    background-color: #7f1d1d;
    color: #fecaca;
    padding: 12px;
    border-radius: 6px;
    margin: 10px 0;
    border: 1px solid #dc2626;
}

/* Modal Styles */
.modal {
    background: #1f2937;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    border: 1px solid #374151;
}

.modal-header {
    border-bottom: 1px solid #374151;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.modal-footer {
    border-top: 1px solid #374151;
    padding-top: 15px;
    margin-top: 15px;
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 1rem 0;
    background: #1f2937;
    border-radius: 6px;
    overflow-x: auto;
    display: block;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #374151;
    color: #e5e7eb;
    min-width: 100px;
}

th {
    background-color: #262f3f;
    font-weight: 600;
    color: #e5e7eb;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #262f3f;
}

/* Sidebar Specific Styles */
.sidebar {
    background-color: #1f2937;
    border-right: 1px solid #374151;
}

.sidebar-item {
    color: #e5e7eb;
    padding: 10px 15px;
    border-radius: 6px;
    margin: 2px 0;
    transition: all 0.2s ease;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.sidebar-item:hover {
    background-color: #262f3f;
}

.sidebar-item.active {
    background-color: #2563eb;
    color: white;
}

/* Notification Styles */
.notification {
    background-color: #1f2937;
    border-left: 4px solid #3b82f6;
    padding: 12px;
    margin: 10px 0;
    border-radius: 0 6px 6px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.notification.success {
    border-left-color: #059669;
}

.notification.error {
    border-left-color: #dc2626;
}

.notification.warning {
    border-left-color: #d97706;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1f2937;
}

::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* User Info Section - Mobile Optimized */
.user-info-section {
    flex: 1;
    min-width: 0; /* Allows text truncation */
}

.user-info-section h3 {
    word-break: break-word;
    font-size: 1rem;
}

/* Mobile-Specific Optimizations */
@media (max-width: 1024px) {
    body {
        padding: 10px;
    }
    
    /* Make top bar items stack better on tablets */
    .bg-gray-800.border-b {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    /* Single column grid for addons */
    .addon-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Full width buttons */
    .button-group {
        flex-direction: column;
        width: 100%;
    }
    
    button {
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
    }
    
    /* Compact form containers */
    .form-container {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    /* Better dashboard cards on mobile */
    .grid-cols-1.md\\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    
    /* Stack user item actions vertically */
    .user-item .flex.gap-2,
    .addon-item .flex.gap-2 {
        flex-direction: column;
        width: 100%;
    }
    
    .user-item button,
    .addon-item button {
        width: 100%;
    }
    
    /* Make addon headers stack on mobile */
    .addon-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    /* Responsive text sizes */
    .addon-title {
        font-size: 1.1em;
    }
    
    .addon-description {
        font-size: 0.9em;
    }
    
    .addon-url {
        font-size: 0.8em;
    }
    
    /* Improved table scrolling on mobile */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* CRITICAL MOBILE SIDEBAR FIX */
    /* Hide sidebar off-screen by default on mobile */
    .fixed.left-0.top-16 {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 40;
        width: 280px !important;
        max-width: 280px;
    }
    
    /* Show sidebar when it has w-64 class (open state) */
    .fixed.left-0.top-16.w-64 {
        transform: translateX(0);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.5);
    }
    
    /* Content always starts from left edge on mobile */
    .pt-16.transition-all {
        margin-left: 0 !important;
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Ensure content area has proper padding */
    .content-area {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Section content padding */
    .section-content {
        width: 100%;
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Top bar improvements */
    #headerCredits {
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    /* Better spacing for subscription info */
    .subscription-tier-select {
        flex-wrap: wrap;
    }
    
    /* Improve sync progress visibility */
    .sync-progress {
        position: sticky;
        top: 80px;
        z-index: 10;
    }
}

@media (max-width: 480px) {
    /* Extra small phones */
    .form-container {
        padding: 12px;
        border-radius: 6px;
    }
    
    .addon-item, .user-item {
        padding: 15px;
    }
    
    .notification {
        padding: 10px;
        font-size: 0.9em;
    }
    
    /* Smaller text for titles */
    h1 {
        font-size: 1.25rem !important;
    }
    
    h2 {
        font-size: 1.1rem !important;
    }
    
    h3 {
        font-size: 1rem !important;
    }
    
    /* Compact buttons on very small screens */
    button {
        padding: 10px 12px;
        font-size: 0.875rem;
    }
    
    /* Smaller icons */
    button i,
    .sidebar-item i {
        width: 18px !important;
        height: 18px !important;
    }
    
    /* Better credit display on small screens */
    #headerCredits {
        padding: 6px 10px;
    }
    
    #headerCredits i {
        width: 16px !important;
        height: 16px !important;
    }
    
    /* Stack login form better */
    .form-group input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Improve modal sizing on mobile */
    .modal {
        padding: 15px;
        margin: 10px;
    }
    
    /* Better empty state sizing */
    .empty-state {
        padding: 30px 15px;
    }
    
    .empty-state i {
        font-size: 36px;
    }
    
    /* Smaller sidebar on very small phones */
    .fixed.left-0.top-16 {
        width: 260px !important;
        max-width: 260px;
    }
}

/* Landscape orientation optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical padding in landscape mode */
    .form-container {
        padding: 10px 15px;
    }
    
    .addon-item, .user-item {
        padding: 12px;
    }
    
    /* Compact dashboard cards */
    .grid-cols-1 > div {
        padding: 12px !important;
    }
    
    /* Smaller top bar */
    .fixed.top-0 {
        height: 48px !important;
    }
    
    .pt-16 {
        padding-top: 48px !important;
    }
    
    .fixed.left-0.top-16 {
        top: 48px !important;
        height: calc(100vh - 48px) !important;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    button,
    .sidebar-item,
    input,
    select {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    button:hover,
    .sidebar-item:hover,
    .addon-item:hover,
    .user-item:hover {
        transform: none;
    }
    
    /* Add active states for better feedback */
    button:active {
        opacity: 0.8;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .form-container, .addon-item, .user-item {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .no-print,
    .sidebar,
    .fixed.top-0,
    button {
        display: none !important;
    }
    
    .pt-16 {
        padding-top: 0 !important;
        margin-left: 0 !important;
    }
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    button {
        border: 2px solid currentColor;
    }
    
    input,
    select {
        border: 2px solid #4b5563;
    }
    
    .addon-item,
    .user-item,
    .form-container {
        border: 2px solid #4b5563;
    }
}

/* Backdrop for mobile sidebar */
@media (max-width: 768px) {
    body::after {
        content: '';
        position: fixed;
        top: 64px;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
        z-index: 30;
        pointer-events: none;
    }
    
    body.sidebar-open::after {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    body.sidebar-open {
        overflow: hidden;
    }
}