/* ═══════════════════════════════════════════════════════════
   微信公众号图片提取器 - 完整样式表
   包含：主题变量、布局、卡片、按钮、网格、Modal、Toast、响应式
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS 变量 ─── */
:root {
    --primary: #07C160;
    --primary-dark: #06AD56;
    --primary-light: #E8F8F0;
    --primary-hover: #05A04E;
    --secondary: #f0f2f5;
    --secondary-dark: #e4e6eb;
    --danger: #FF4D4F;
    --danger-light: #FFF1F0;
    --warning: #FAAD14;
    --success: #52C41A;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --text-tertiary: #999;
    --bg-app: #f5f6f8;
    --bg-card: #ffffff;
    --bg-input: #fafafa;
    --border: #e8e8e8;
    --border-hover: #d9d9d9;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition: all 0.25s ease;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                  "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ─── 基础重置 ─── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-stack);
    background: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── 顶部导航 ─── */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, #06B554 100%);
    color: white;
    box-shadow: 0 2px 12px rgba(7, 193, 96, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.app-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* ─── 主区域 ─── */
.app-main {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ─── 卡片 ─── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 24px;
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ─── 输入区域 ─── */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.url-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: var(--font-stack);
    background: var(--bg-input);
    color: var(--text-primary);
    resize: vertical;
    min-height: 110px;
    transition: var(--transition);
    line-height: 1.6;
}

.url-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.12);
}

.url-input::placeholder {
    color: var(--text-tertiary);
}

.url-input.invalid {
    border-color: var(--danger);
    background: var(--danger-light);
}

.url-input-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ─── 高级选项 ─── */
.advanced-toggle {
    margin-top: 14px;
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.25s;
    font-size: 10px;
    margin-right: 4px;
}

.advanced-toggle .toggle-icon.expanded {
    transform: rotate(90deg);
}

.advanced-options {
    margin-top: 12px;
    padding: 16px;
    background: var(--bg-app);
    border-radius: var(--radius-md);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 300px;
    }
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 13px;
}

.option-label {
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.option-hint {
    color: var(--text-tertiary);
    font-size: 12px;
}

.num-input {
    width: 64px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-align: center;
}

.num-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.1);
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}

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

/* ─── 按钮 ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: var(--font-stack);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

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

.btn:not(:disabled):hover {
    transform: translateY(-1px);
}

.btn:not(:disabled):active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(7, 193, 96, 0.25);
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(7, 193, 96, 0.35);
}

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

.btn-secondary:not(:disabled):hover {
    background: var(--secondary-dark);
}

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

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

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

.btn-danger:not(:disabled):hover {
    background: #e63940;
}

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

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

.file-upload-label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

/* ─── 解析按钮区域 ─── */
.parse-action {
    margin-top: 20px;
    text-align: center;
}

.parse-hint {
    margin-top: 10px;
    text-align: center;
    font-size: 13px;
    color: var(--text-tertiary);
    min-height: 20px;
}

.parse-hint.error {
    color: var(--danger);
}

.parse-hint.success {
    color: var(--success);
}

/* ─── Loading 动画 ─── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ─── 结果区域 ─── */
.result-card {
    padding: 24px;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.result-info {
    flex: 1;
    min-width: 200px;
}

.result-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
    word-break: break-all;
}

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

.result-meta strong {
    color: var(--primary);
}

.result-actions-top {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.view-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.view-btn {
    background: white;
    color: var(--text-secondary);
    padding: 5px 10px;
    border: none;
    border-radius: 0;
}

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

/* ─── 图片网格 ─── */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding: 4px 0 16px;
}

.image-grid.list-view {
    grid-template-columns: 1fr;
}

/* ─── 图片卡片 ─── */
.image-card {
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
    position: relative;
    cursor: pointer;
}

.image-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
}

.image-card.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.image-card.downloading {
    border-color: var(--warning);
}

.image-card.completed {
    border-color: var(--success);
}

.image-card.failed {
    border-color: var(--danger);
}

.image-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #f9f9f9;
    overflow: hidden;
}

.image-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}

.image-card:hover .image-card-thumb img {
    transform: scale(1.05);
}

.image-card-thumb .skeleton {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.image-card-checkbox {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: var(--primary);
    z-index: 2;
}

.image-card-status {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: rgba(255,255,255,0.95);
    box-shadow: var(--shadow-sm);
    z-index: 2;
}

.image-card-status.downloading {
    background: var(--warning);
    color: white;
}

.image-card-status.completed {
    background: var(--success);
    color: white;
}

.image-card-status.failed {
    background: var(--danger);
    color: white;
}

.image-card-info {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.image-card-info .info-format {
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-primary);
}

.image-card-info .info-size {
    color: var(--text-tertiary);
}

.image-card-retry {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-card.failed:hover .image-card-retry {
    opacity: 1;
}

/* 列表视图样式 */
.list-view .image-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.list-view .image-card-thumb {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    aspect-ratio: auto;
}

.list-view .image-card-info {
    flex: 1;
    padding: 0;
}

.list-view .image-card-checkbox {
    position: static;
    width: 20px;
    height: 20px;
}

.list-view .image-card-status {
    position: static;
    width: 24px;
    height: 24px;
}

/* ─── 空状态 ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 16px;
}

.empty-hint {
    font-size: 13px !important;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* ─── 下载操作栏 ─── */
.download-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

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

.selection-info strong {
    color: var(--primary);
}

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

/* ─── 进度条 ─── */
.progress-section {
    margin-top: 16px;
    padding: 20px;
    background: var(--bg-app);
    border-radius: var(--radius-md);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 500;
}

#progressPercent {
    color: var(--primary);
    font-weight: 600;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--secondary-dark);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #06D670 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.3) 50%,
        transparent 100%
    );
    animation: progressShine 1.5s infinite;
}

@keyframes progressShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.download-stats {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.download-stats .stat-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ─── Modal ─── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: white;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-image {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    display: block;
}

.modal-info {
    padding: 12px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    border-top: 1px solid var(--border);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 18px;
    cursor: pointer;
    z-index: 10;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(0,0,0,0.8);
    transform: scale(1.1);
}

.modal-title {
    padding: 20px 20px 12px;
    font-size: 18px;
    font-weight: 600;
}

/* ─── 历史记录面板 ─── */
.history-modal {
    width: 500px;
    max-width: 90vw;
    padding: 0;
}

.history-list {
    padding: 12px 20px;
    max-height: 400px;
    overflow-y: auto;
    flex: 1;
}

.history-item {
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-app);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
}

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

.history-item-title {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-meta {
    font-size: 12px;
    color: var(--text-tertiary);
}

.history-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: 40px 0;
}

/* ─── Toast 通知 ─── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    max-width: 380px;
    word-break: break-word;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

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

/* ─── 页脚 ─── */
.app-footer {
    text-align: center;
    padding: 16px 24px;
    font-size: 12px;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border);
    background: white;
}

/* ─── 拖拽高亮 ─── */
.input-card.drag-over {
    border: 2px dashed var(--primary);
    background: var(--primary-light);
}

.url-input.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ═══════════════════════════════════════════════════════════
   响应式媒体查询
   ═══════════════════════════════════════════════════════════ */

/* 平板端 (481px - 768px) */
@media (max-width: 768px) {
    .header-content {
        padding: 12px 16px;
    }

    .app-title {
        font-size: 17px;
    }

    .app-main {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    .result-header {
        flex-direction: column;
    }

    .download-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .download-actions {
        justify-content: center;
    }

    .options-grid {
        gap: 10px;
    }
}

/* 手机端 (≤480px) */
@media (max-width: 480px) {
    .app-title {
        font-size: 15px;
    }

    .header-content {
        padding: 10px 12px;
    }

    .app-main {
        padding: 10px;
        gap: 12px;
    }

    .card {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .url-input {
        min-height: 90px;
        font-size: 13px;
        padding: 10px 12px;
    }

    .btn {
        font-size: 13px;
        padding: 7px 14px;
    }

    .btn-lg {
        padding: 10px 24px;
        font-size: 14px;
        width: 100%;
    }

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

    .option-group {
        font-size: 12px;
    }

    .num-input {
        width: 54px;
    }

    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .toast {
        max-width: none;
    }

    .result-title {
        font-size: 16px;
    }

    .image-card-info {
        padding: 6px 8px;
        font-size: 11px;
    }

    .list-view .image-card {
        flex-direction: column;
    }

    .list-view .image-card-thumb {
        width: 100%;
        height: 120px;
    }
}

/* 大屏桌面端 (>1200px) */
@media (min-width: 1201px) {
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}
