/* ============ 全局样式 ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f6ef7;
    --primary-dark: #3b5de7;
    --primary-light: #eef1fe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============ 顶部导航 ============ */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-sub {
    font-size: 14px;
    font-weight: 500;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

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

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

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

.btn-lg {
    padding: 12px 28px;
    font-size: 16px;
}

.btn-icon {
    font-size: 16px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============ 主内容区 ============ */
.main {
    flex: 1;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

/* ============ 解析卡片 ============ */
.parse-card, .settings-card, .files-card, .download-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

.link-input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg-primary);
}

.link-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: white;
}

.parse-actions {
    display: flex;
    gap: 12px;
    margin-top: 14px;
}

.parse-result {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--primary-light);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

.parse-info {
    font-size: 14px;
    color: var(--text-secondary);
    word-break: break-all;
}

/* ============ 设置面板 ============ */
.settings-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.7;
}

.credential-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.credential-tab {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.credential-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.credential-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.credential-tab.has-credential::after {
    content: " ✓";
    color: var(--success);
}

.credential-tab.active.has-credential::after {
    color: white;
}

.credential-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: "Consolas", "Monaco", monospace;
    resize: vertical;
    background: var(--bg-primary);
    word-break: break-all;
}

.credential-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: white;
}

.credential-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.credential-status {
    font-size: 13px;
    color: var(--success);
}

.credential-help {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.credential-help summary {
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px 0;
}

.help-content {
    margin-top: 10px;
    padding: 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.help-content p {
    margin-bottom: 6px;
}

.help-content strong {
    color: var(--text-primary);
}

/* ============ 文件列表 ============ */
.files-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.files-path {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.path-item {
    cursor: pointer;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.path-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.path-separator {
    color: var(--text-muted);
}

.files-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
    gap: 12px;
}

.file-item:hover {
    background: var(--bg-primary);
}

.file-icon {
    font-size: 22px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.file-actions {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
}

.file-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.files-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    color: var(--text-secondary);
    font-size: 14px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============ 下载结果 ============ */
.download-info {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.download-file-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

.download-size {
    font-size: 14px;
    color: var(--text-secondary);
}

.download-url-box {
    padding: 12px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.download-url-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.download-url-text {
    font-size: 12px;
    font-family: "Consolas", "Monaco", monospace;
    color: var(--text-secondary);
    word-break: break-all;
    line-height: 1.6;
}

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

.download-referer-hint {
    font-size: 12px;
    color: var(--warning);
    background: #fffbeb;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--warning);
}

/* ============ 底部 ============ */
.footer {
    text-align: center;
    padding: 20px;
    font-size: 13px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-light);
    background: var(--bg-card);
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: white;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 360px;
    word-break: break-all;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--primary); }

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============ 响应式 ============ */
@media (max-width: 640px) {
    .main {
        padding: 16px;
    }
    .parse-card, .settings-card, .files-card, .download-card {
        padding: 18px;
    }
    .parse-actions {
        flex-direction: column;
    }
    .parse-actions .btn {
        width: 100%;
    }
    .header-inner {
        padding: 12px 16px;
    }
    .credential-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .download-actions {
        flex-direction: column;
    }
    .download-actions .btn {
        width: 100%;
    }
}
