/* Basic Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    padding: 0;
    margin: 0;
    padding-bottom: 70px;
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    background: #f5f7fa;
    min-height: 100vh;
}

/* Status Bar */
.status-bar {
    padding: 12px 20px 4px;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

/* Header */
.app-header {
    padding: 8px 20px 16px;
}

.app-header h1 {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, #1a73e8, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.5px;
}

.app-header p {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
}

/* Stats Row */
.stats-row {
    display: flex;
    gap: 10px;
    padding: 0 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    background: white;
    border-radius: 20px;
    padding: 12px;
    text-align: center;
    border: 1px solid #eef2f6;
    cursor: pointer;
    transition: all 0.2s;
}

.stat-card.active {
    border: 2px solid #1a73e8;
    background: #e8f0fe;
}

.stat-number {
    font-size: 22px;
    font-weight: 700;
    color: #1a73e8;
}

.stat-label {
    font-size: 10px;
    color: #888;
    margin-top: 4px;
}

/* Sort Dropdown */
.sort-bar {
    display: flex;
    justify-content: flex-end;
    padding: 0 20px;
    margin-bottom: 12px;
}

.sort-select {
    background: #f0f2f5;
    border: none;
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

/* Search Bar */
.search-card {
    background: white;
    margin: 0 20px 16px;
    border-radius: 30px;
    padding: 6px 16px;
    border: 1px solid #eef2f6;
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: #aaa;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border: none;
    border-radius: 30px;
    font-size: 14px;
    background: #f8f9fa;
}

.search-input:focus {
    outline: none;
    background: white;
}

.search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    text-decoration: none;
    color: #aaa;
    font-size: 14px;
}

/* Alert */
.alert {
    margin: 0 20px 16px;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
}

.alert.success {
    background: #e6f4ea;
    color: #1e7e34;
    border-left: 4px solid #34a853;
}

.alert.error {
    background: #fce8e6;
    color: #c5221f;
    border-left: 4px solid #ea4335;
}

/* Section Header */
.section-header {
    padding: 0 20px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
}

.section-count {
    font-size: 12px;
    color: #888;
    background: #f0f2f5;
    padding: 4px 10px;
    border-radius: 20px;
}

/* Torrent List */
.torrent-list {
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Torrent Card */
.torrent-card {
    background: white;
    border-radius: 20px;
    padding: 14px;
    border: 1px solid #eef2f6;
    transition: all 0.2s;
}

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

.torrent-title {
    font-weight: 600;
    font-size: 14px;
    word-break: break-word;
    flex: 1;
    line-height: 1.4;
}

.status-chip {
    font-size: 10px;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    white-space: nowrap;
}

.status-ready {
    background: #e6f4ea;
    color: #1e7e34;
}

.status-downloading {
    background: #fef7e0;
    color: #e37400;
}

.status-pending {
    background: #f0f2f5;
    color: #666;
}

/* Progress Bar */
.progress-bar {
    background: #e8eaed;
    border-radius: 10px;
    height: 4px;
    margin: 10px 0;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #1a73e8, #8b5cf6);
    width: 0%;
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 10px;
    color: #666;
    margin-top: 5px;
    text-align: right;
}

/* Meta Info */
.meta-info {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 10px 0;
    font-size: 11px;
    color: #888;
}

.meta-info span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.action-btn {
    flex: 1;
    padding: 8px;
    border-radius: 30px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    background: #f0f2f5;
    color: #1a73e8;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.action-btn:active {
    transform: scale(0.96);
}

.btn-zip {
    background: #e8eefa;
    color: #1a73e8;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 20px;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 36px;
    padding: 6px 0;
    background: white;
    border: 1px solid #e0e4e8;
    border-radius: 18px;
    text-decoration: none;
    color: #1a73e8;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
}

.page-btn.active {
    background: #1a73e8;
    border-color: #1a73e8;
    color: white;
}

.page-btn.disabled {
    color: #ccc;
    pointer-events: none;
}

/* File Browser */
.file-list {
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-card {
    background: white;
    border-radius: 16px;
    padding: 12px;
    border: 1px solid #eef2f6;
}

.file-name {
    font-weight: 500;
    font-size: 13px;
    word-break: break-all;
}

.file-size {
    font-size: 11px;
    color: #888;
    margin: 5px 0 10px;
}

.download-link {
    background: #e6f4ea;
    color: #1e7e34;
    display: inline-block;
    padding: 8px 16px;
    border-radius: 30px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}

.zip-all {
    background: #e8eefa;
    color: #1a73e8;
    display: inline-block;
    padding: 8px 16px;
    border-radius: 30px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    margin-top: 10px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid #eef2f6;
    display: flex;
    justify-content: space-around;
    padding: 8px 20px 20px;
    max-width: 500px;
    margin: 0 auto;
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    font-size: 10px;
    color: #888;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
}

.nav-icon {
    font-size: 22px;
}

/* Add Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 28px 28px 0 0;
    width: 100%;
    max-width: 500px;
    padding: 24px 20px 32px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
}

.add-input {
    width: 100%;
    padding: 16px;
    border: 1px solid #e0e4e8;
    border-radius: 16px;
    font-size: 14px;
    margin-bottom: 16px;
    font-family: inherit;
}

.add-submit {
    width: 100%;
    padding: 16px;
    background: #1a73e8;
    color: white;
    border: none;
    border-radius: 16px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #888;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    margin: 8px 20px 16px;
    background: white;
    border-radius: 30px;
    text-decoration: none;
    color: #1a73e8;
    font-weight: 500;
    font-size: 14px;
    width: fit-content;
    border: 1px solid #eef2f6;
}

.footer {
    text-align: center;
    padding: 16px;
    font-size: 10px;
    color: #aaa;
}

mark {
    background: #fef7e0;
    padding: 0 2px;
    border-radius: 3px;
    color: #e37400;
}

/* Pending temporary card (optimistic) */
.pending-card-temp {
    background: #fff8e7;
    border: 1px solid #ffd966;
    opacity: 0.9;
}

.pending-card-temp .status-chip {
    background: #fef7e0;
    color: #e37400;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    body,
    .app-container {
        background: #121212;
    }

    .stat-card,
    .search-card,
    .torrent-card,
    .file-card,
    .page-btn,
    .modal-content,
    .back-btn {
        background: #1e1e1e;
        border-color: #2d2d30;
    }

    .torrent-title,
    .section-title,
    .modal-header h3 {
        color: #e8eaed;
    }

    .stat-number {
        color: #8b9eff;
    }

    .sort-select {
        background: #2d2d30;
        color: #9aa0a6;
    }

    .search-input {
        background: #2d2d30;
        color: #e8eaed;
    }

    .meta-info,
    .stat-label,
    .section-count,
    .progress-text,
    .file-size,
    .empty-state {
        color: #9aa0a6;
    }

    .action-btn {
        background: #2d2d30;
        color: #9aa0a6;
    }

    .btn-zip {
        background: #1a2a3a;
        color: #8b9eff;
    }

    .bottom-nav {
        background: rgba(30, 30, 30, 0.96);
        border-top-color: #2d2d30;
    }

    .alert.success {
        background: #1a3a2a;
        color: #81c995;
    }

    .alert.error {
        background: #3a1a1a;
        color: #f28b82;
    }

    .pending-card-temp {
        background: #2a2a2a;
        border-color: #8b6914;
    }

    mark {
        background: #3a2a1a;
        color: #ff9f0a;
    }
}