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

@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&display=swap');

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    overflow-x: hidden;
    word-wrap: break-word;
}

.connection-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0.7;
}

.connection-status:hover {
    opacity: 1;
    transform: scale(1.05);
}

.connection-status.connected {
    background: #28a745;
    color: white;
}

.connection-status.disconnected {
    background: #dc3545;
    color: white;
}

.connection-status.connecting {
    background: #ffc107;
    color: #212529;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px 15px 0 0;
    overflow: hidden;
    margin-bottom: 0;
    backdrop-filter: blur(10px);
}

.tab-btn {
    flex: 1;
    padding: 15px 10px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    font-weight: 600;
}

.tab-icon {
    font-size: 1.2rem;
}

/* Main Content */
main {
    background: white;
    border-radius: 0 0 15px 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
    min-height: 400px;
    max-width: 100%;
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 30px;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f1f3f4;
}

.tab-header h2 {
    margin: 0;
    color: #444;
    font-size: 1.8rem;
}

/* Search Tab */
#search-tab {
    background: #f8f9fa;
}

.search-form, .magnet-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-form input, .magnet-form input {
    flex: 1;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.search-form input:focus, .magnet-form input:focus {
    outline: none;
    border-color: #667eea;
}

.search-form button, .magnet-form button {
    padding: 15px 30px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

.search-form button:hover, .magnet-form button:hover {
    background: #5a6fd8;
}

.search-form button:disabled, .magnet-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* HTMX Indicators */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline;
}

.htmx-request.htmx-indicator {
    display: inline;
}

/* Loading animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.htmx-request #refresh-indicator {
    animation: spin 1s linear infinite;
}

/* Error state */
.error {
    color: #dc3545;
    font-style: italic;
}

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    font-style: italic;
    color: #666;
}

.hidden {
    display: none;
}

/* Results */
.results-container, .downloads-container {
    max-height: calc(100vh - 350px);
    min-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
    -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling */
.results-container::-webkit-scrollbar, .downloads-container::-webkit-scrollbar {
    width: 8px;
}

.results-container::-webkit-scrollbar-track, .downloads-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb, .downloads-container::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb:hover, .downloads-container::-webkit-scrollbar-thumb:hover {
    background: #5a6fd8;
}

.torrent-item {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    max-width: 100%;
}

.torrent-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.torrent-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 10px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    line-height: 1.4;
}

.torrent-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #666;
    overflow: hidden;
}

.detail-item {
    display: flex;
    flex-direction: column;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.detail-label {
    font-weight: 600;
    color: #444;
    margin-bottom: 2px;
}

.torrent-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.3s ease;
}

.btn-primary {
    background: #28a745;
    color: white;
}

.btn-primary:hover {
    background: #218838;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-warning {
    background: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background: #e0a800;
}

.btn-outline-danger {
    background: transparent;
    color: #dc3545;
    border: 1px solid #dc3545;
}

.btn-outline-danger:hover {
    background: #dc3545;
    color: white;
}

/* Download Items */
.download-item {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    overflow: hidden;
    max-width: 100%;
}

.download-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 10px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    line-height: 1.4;
}

.download-progress {
    margin-bottom: 15px;
}

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

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.9rem;
    color: #666;
}

.download-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #666;
    overflow: hidden;
}

.download-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Status Indicators */
.status-downloading {
    border-left: 4px solid #28a745;
}

.status-paused {
    border-left: 4px solid #ffc107;
}

.status-completed {
    border-left: 4px solid #007bff;
}

.status-error {
    border-left: 4px solid #dc3545;
}

/* No Results/Downloads */
.no-results, .no-downloads {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 40px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    .container {
        padding: 10px;
        margin-bottom: 60px; /* Add space for fixed connection status */
    }
    
    .tab-nav {
        border-radius: 10px 10px 0 0;
    }
    
    .tab-btn {
        padding: 12px 8px;
        font-size: 0.8rem;
        gap: 3px;
    }
    
    .tab-icon {
        font-size: 1rem;
    }
    
    .tab-content {
        padding: 15px;
    }
    
    .tab-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        text-align: center;
    }
    
    .tab-header h2 {
        font-size: 1.5rem;
    }
    
    .search-form, .magnet-form {
        flex-direction: column;
        gap: 15px;
    }
    
    .search-form input, .magnet-form input {
        padding: 14px;
        font-size: 16px; /* Prevent zoom on iOS */
        border-radius: 10px;
    }
    
    .search-form button, .magnet-form button {
        padding: 14px 20px;
        font-size: 16px;
        border-radius: 10px;
    }
    
    .torrent-details, .download-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .download-controls {
        justify-content: center;
        gap: 8px;
    }
    
    .btn {
        padding: 12px 16px;
        font-size: 14px;
        min-width: 80px;
        border-radius: 8px;
    }
    
    .connection-status {
        bottom: 10px;
        right: 10px;
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .results-container, .downloads-container {
        max-height: calc(100vh - 280px);
        min-height: 250px;
    }
    
    main {
        border-radius: 0 0 10px 10px;
        margin-bottom: 20px;
    }
    
    .torrent-item, .download-item {
        padding: 15px;
        margin-bottom: 10px;
        border-radius: 10px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    section {
        padding: 10px;
    }
    
    .search-form input, .magnet-form input {
        padding: 10px;
    }
    
    .search-form button, .magnet-form button {
        padding: 10px 15px;
    }
    
    .download-controls {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 5px;
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.mb-10 {
    margin-bottom: 10px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.2s ease;
}

/* Smooth transitions for HTMX */
.download-item {
    transition: all 0.3s ease;
}

.downloads-container {
    transition: opacity 0.2s ease;
}

/* Reduce jitter during updates */
.htmx-settling {
    transition: all 0.3s ease;
}

.htmx-swapping {
    opacity: 0.95;
    transition: opacity 0.2s ease;
}

/* Smooth progress bar updates */
.progress-fill {
    transition: width 0.5s ease;
}

/* Stable positioning */
.download-item {
    min-height: 200px;
    position: relative;
}

/* Prevent layout shifts */
.download-stats {
    min-height: 120px;
}

.download-controls {
    min-height: 40px;
}