/* ============================================
   Pikpak2TelDrive - 暗色主题 UI
   ============================================ */

:root {
    /* 颜色系统 */
    --bg-primary: #0f0f14;
    --bg-secondary: #16161e;
    --bg-card: #1a1a24;
    --bg-hover: #22222e;
    --bg-input: #12121a;

    --border-color: #2a2a3a;
    --border-focus: #6366f1;

    --text-primary: #e4e4eb;
    --text-secondary: #9898ab;
    --text-muted: #5e5e72;

    --accent: #6366f1;
    --accent-hover: #5558e6;
    --accent-glow: rgba(99, 102, 241, 0.15);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);

    --download-color: #3b82f6;
    --upload-color: #8b5cf6;

    /* 间距 */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    /* 过渡 */
    --transition: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* 阴影 */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* Reset */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================
   登录遮罩层
   ============================================ */

.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-overlay.hidden {
    display: none;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-card .logo {
    justify-content: center;
    margin-bottom: 8px;
    font-size: 20px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}

.login-error {
    display: none;
    padding: 10px 14px;
    border-radius: var(--radius-xs);
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-size: 13px;
    margin-bottom: 16px;
}

.login-error.show {
    display: block;
}

.login-card .form-group {
    margin-bottom: 16px;
}

.login-card .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    margin-top: 8px;
}

/* 退出登录按钮 */
.btn-logout {
    width: 100%;
    margin-top: 10px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-logout:hover {
    border-color: var(--error);
    color: var(--error);
    background: var(--error-bg);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

.app {
    display: flex;
    height: 100vh;
}

/* ============================================
   侧边栏
   ============================================ */

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.logo svg {
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-item.active svg {
    color: var(--accent);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
    transition: background var(--transition);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

/* ============================================
   主内容区
   ============================================ */

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    scroll-behavior: smooth;
}

.main-content::-webkit-scrollbar {
    width: 6px;
}

.main-content::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.page {
    display: none;
    animation: fadeIn 0.25s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ============================================
   按钮
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-outline:hover {
    background: var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid transparent;
}

.btn-danger:hover {
    border-color: var(--error);
}

/* ============================================
   统计卡片
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.downloading {
    background: var(--info-bg);
    color: var(--info);
}

.stat-icon.uploading {
    background: rgba(139, 92, 246, 0.1);
    color: var(--upload-color);
}

.stat-icon.completed {
    background: var(--success-bg);
    color: var(--success);
}

.stat-icon.speed {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================
   卡片/区域
   ============================================ */

.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.section-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    gap: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================
   任务列表
   ============================================ */

.task-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 6px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 20px;
    transition: all var(--transition);
}

.task-item:hover {
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: var(--shadow-sm);
}

.task-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.task-filename {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

.task-status {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.task-status.pending {
    background: var(--warning-bg);
    color: var(--warning);
}

.task-status.downloading {
    background: var(--info-bg);
    color: var(--info);
}

.task-status.uploading {
    background: rgba(139, 92, 246, 0.1);
    color: var(--upload-color);
}

.task-status.completed {
    background: var(--success-bg);
    color: var(--success);
}

.task-status.failed {
    background: var(--error-bg);
    color: var(--error);
}

.task-status.cancelled {
    background: rgba(150, 150, 150, 0.1);
    color: #999;
}

.task-status.paused {
    background: var(--warning-bg);
    color: var(--warning);
}

.task-progress-section {
    margin-bottom: 12px;
}

.progress-labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
    position: relative;
}

.progress-fill.download {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.progress-fill.upload {
    background: linear-gradient(90deg, #8b5cf6, #a78bfa);
}

.progress-fill.complete {
    background: linear-gradient(90deg, #22c55e, #4ade80);
}

@keyframes progressPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.progress-fill.active {
    animation: progressPulse 1.5s ease-in-out infinite;
}

.task-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.task-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.task-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

/* ============================================
   设置页面
   ============================================ */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.settings-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent);
}

.settings-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: all var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239898ab' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex-direction: row;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.test-result {
    padding: 8px 14px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    display: none;
}

.test-result.success {
    display: block;
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.test-result.error {
    display: block;
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
}

/* ============================================
   弹窗
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ============================================
   Toast 通知
   ============================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

.toast.success {
    background: #16a34a;
    color: white;
}

.toast.error {
    background: #dc2626;
    color: white;
}

.toast.info {
    background: #2563eb;
    color: white;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

/* ============================================
   响应式
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        width: 64px;
    }

    .sidebar-header {
        padding: 16px;
    }

    .logo span,
    .nav-item span,
    .sidebar-footer span {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .main-content {
        padding: 20px 16px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .task-item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .task-actions {
        margin-left: 0;
    }
}