/*!
 * Product Picker - 可复用产品选择器模块
 * 版本: 1.0.0
 * 样式前缀: pp-
 * 兼容: 纯原生CSS, 不依赖任何框架
 */

/* ========== 触发按钮 ========== */
.pp-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    vertical-align: middle;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    line-height: 1.4;
}

.pp-trigger-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.pp-trigger-btn:active {
    transform: translateY(0);
}

.pp-trigger-btn.pp-small {
    padding: 5px 12px;
    font-size: 13px;
    border-radius: 6px;
}

.pp-trigger-btn.pp-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* ========== 遮罩层 ========== */
.pp-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    padding: 16px;
}

.pp-overlay.pp-open {
    opacity: 1;
    visibility: visible;
}

/* ========== 弹窗面板 ========== */
.pp-modal {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: translateY(20px) scale(0.97);
    transition: transform 0.25s ease;
    overflow: hidden;
}

.pp-overlay.pp-open .pp-modal {
    transform: translateY(0) scale(1);
}

/* ========== 弹窗头部 ========== */
.pp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid #f0f0f5;
    background: linear-gradient(135deg, #f8f9ff 0%, #f5f3ff 100%);
    flex-shrink: 0;
}

.pp-header-title {
    font-size: 17px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pp-header-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s ease;
    line-height: 1;
}

.pp-header-close:hover {
    background: #f0f0f5;
    color: #333;
}

/* ========== 步骤指示器 ========== */
.pp-steps {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    gap: 8px;
    border-bottom: 1px solid #f0f0f5;
    flex-shrink: 0;
}

.pp-step {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #aaa;
    transition: color 0.2s ease;
}

.pp-step.pp-active {
    color: #667eea;
    font-weight: 600;
}

.pp-step.pp-done {
    color: #52c41a;
}

.pp-step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f0f0f5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.pp-step.pp-active .pp-step-num {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}

.pp-step.pp-done .pp-step-num {
    background: #52c41a;
    color: #fff;
}

.pp-step-line {
    flex: 1;
    height: 2px;
    background: #f0f0f5;
    border-radius: 1px;
    min-width: 20px;
}

/* ========== 弹窗主体 ========== */
.pp-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.pp-body::-webkit-scrollbar {
    width: 6px;
}

.pp-body::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

/* ========== 搜索框 ========== */
.pp-search-wrap {
    position: relative;
    margin-bottom: 14px;
}

.pp-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #bbb;
    pointer-events: none;
}

.pp-search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    font-size: 14px;
    border: 1.5px solid #e8e8f0;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    background: #fafafe;
}

.pp-search-input:focus {
    border-color: #667eea;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.pp-search-input::placeholder {
    color: #bbb;
}

/* ========== 列表区域 ========== */
.pp-list {
    border: 1px solid #f0f0f5;
    border-radius: 10px;
    overflow: hidden;
    max-height: 320px;
    overflow-y: auto;
}

.pp-list::-webkit-scrollbar {
    width: 5px;
}

.pp-list::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

/* ========== 列表项 ========== */
.pp-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #f7f7fa;
    cursor: pointer;
    transition: background 0.15s ease;
    gap: 10px;
}

.pp-item:last-child {
    border-bottom: none;
}

.pp-item:hover {
    background: #f8f9ff;
}

.pp-item.pp-selected {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(118, 75, 162, 0.08));
    border-left: 3px solid #667eea;
    padding-left: 13px;
}

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

.pp-item-name {
    font-size: 14px;
    font-weight: 500;
    color: #1a1a2e;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pp-item-meta {
    font-size: 12px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pp-item-cat {
    display: inline-block;
    padding: 1px 8px;
    background: #f0f0f5;
    border-radius: 4px;
    font-size: 11px;
    color: #888;
}

.pp-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    color: #667eea;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.pp-item-check {
    color: #667eea;
    font-size: 16px;
    flex-shrink: 0;
    display: none;
}

.pp-item.pp-selected .pp-item-check {
    display: block;
}

/* ========== 空状态 ========== */
.pp-empty {
    padding: 40px 20px;
    text-align: center;
    color: #bbb;
    font-size: 14px;
}

.pp-empty-icon {
    font-size: 36px;
    margin-bottom: 10px;
    opacity: 0.5;
}

/* ========== 加载状态 ========== */
.pp-loading-wrap {
    padding: 40px 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.pp-spinner {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid #f0f0f5;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: pp-spin 0.8s linear infinite;
    margin-bottom: 10px;
}

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

/* ========== 错误提示 ========== */
.pp-error {
    padding: 16px;
    background: #fff2f0;
    border: 1px solid #ffccc7;
    border-radius: 10px;
    color: #cf1322;
    font-size: 13px;
    text-align: center;
    margin-bottom: 14px;
}

.pp-error-retry {
    margin-top: 8px;
    padding: 5px 16px;
    font-size: 12px;
    background: #cf1322;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* ========== 已选产品预览 ========== */
.pp-selected-preview {
    margin-top: 14px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #f8f9ff, #f5f3ff);
    border: 1px solid #e8e8f5;
    border-radius: 10px;
}

.pp-preview-label {
    font-size: 12px;
    color: #999;
    margin-bottom: 6px;
}

.pp-preview-name {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 6px;
}

.pp-preview-points {
    font-size: 12px;
    color: #666;
    line-height: 1.6;
}

.pp-preview-points li {
    margin-left: 16px;
}

/* ========== 弹窗底部 ========== */
.pp-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-top: 1px solid #f0f0f5;
    background: #fafafe;
    flex-shrink: 0;
    gap: 10px;
}

.pp-footer-hint {
    font-size: 12px;
    color: #aaa;
    flex: 1;
}

.pp-btn {
    padding: 9px 22px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    white-space: nowrap;
}

.pp-btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.pp-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.pp-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pp-btn-ghost {
    background: transparent;
    color: #888;
    border: 1px solid #e0e0e8;
}

.pp-btn-ghost:hover {
    background: #f5f5fa;
    color: #555;
}

/* ========== 内联模式（非弹窗） ========== */
.pp-inline {
    position: relative;
}

.pp-inline .pp-modal {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 1000;
    max-width: 420px;
    max-height: 480px;
    transform-origin: top left;
}

/* ========== 移动端适配 ========== */
@media (max-width: 600px) {
    .pp-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .pp-modal {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }

    .pp-overlay.pp-open .pp-modal {
        transform: translateY(0);
    }

    .pp-header {
        padding: 16px 18px;
    }

    .pp-header-title {
        font-size: 16px;
    }

    .pp-body {
        padding: 16px 18px;
    }

    .pp-steps {
        padding: 10px 18px;
    }

    .pp-footer {
        padding: 12px 18px;
    }

    .pp-list {
        max-height: 280px;
    }

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

/* ========== 深色模式适配（可选） ========== */
@media (prefers-color-scheme: dark) {
    .pp-modal {
        background: #1e1e2e;
    }

    .pp-header {
        background: linear-gradient(135deg, #2a2a3e, #252538);
        border-bottom-color: #333348;
    }

    .pp-header-title {
        color: #e8e8f0;
    }

    .pp-header-close {
        color: #888;
    }

    .pp-header-close:hover {
        background: #333348;
        color: #ddd;
    }

    .pp-body {
        background: #1e1e2e;
    }

    .pp-search-input {
        background: #2a2a3e;
        border-color: #3a3a4e;
        color: #e8e8f0;
    }

    .pp-search-input:focus {
        background: #2a2a3e;
    }

    .pp-list {
        border-color: #333348;
    }

    .pp-item {
        border-bottom-color: #2a2a38;
    }

    .pp-item:hover {
        background: #2a2a3e;
    }

    .pp-item-name {
        color: #e8e8f0;
    }

    .pp-item-cat {
        background: #333348;
        color: #aaa;
    }

    .pp-steps {
        border-bottom-color: #333348;
        background: #1e1e2e;
    }

    .pp-step-num {
        background: #333348;
    }

    .pp-footer {
        background: #252538;
        border-top-color: #333348;
    }

    .pp-btn-ghost {
        border-color: #444458;
        color: #aaa;
    }

    .pp-btn-ghost:hover {
        background: #333348;
    }

    .pp-selected-preview {
        background: linear-gradient(135deg, #2a2a3e, #252538);
        border-color: #3a3a4e;
    }

    .pp-preview-name {
        color: #e8e8f0;
    }

    .pp-preview-points {
        color: #aaa;
    }
}
