/* ==========================================================================
   CPMLS Product Uploader - Frontend Styles
   ========================================================================== */

.cpmls-panel {
    max-width: 1280px;
    margin: 20px auto;
    padding: 0 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
    color: #1d2327;
}

/* 嵌入在 My Account 內時的調整 - 去掉外層 margin/padding,交給 WC 版型控制 */
.cpmls-panel--embed {
    max-width: none;
    margin: 0;
    padding: 0;
}
.cpmls-panel--embed .cpmls-section:first-of-type {
    margin-top: 0;
}

/* Login prompt */
.cpmls-login-prompt {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}
.cpmls-login-prompt h2 { margin-top: 0; }

/* Flash messages */
.cpmls-flash {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    border-left: 4px solid;
}
.cpmls-flash-success { background: #ecfdf5; border-color: #10b981; color: #065f46; }
.cpmls-flash-error   { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.cpmls-flash a       { color: inherit; text-decoration: underline; margin-left: 8px; }

/* Section */
.cpmls-section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
}
.cpmls-section-title {
    margin: 0 0 18px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid #f1f5f9;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.cpmls-badge {
    background: #1e40af;
    color: #fff;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 600;
}
.cpmls-empty {
    color: #6b7280;
    font-style: italic;
    padding: 20px 0;
    text-align: center;
}
.cpmls-error {
    color: #991b1b;
    background: #fef2f2;
    padding: 14px;
    border-radius: 8px;
    border-left: 4px solid #ef4444;
}

/* Product list */
.cpmls-product-list {
    display: grid;
    gap: 10px;
}

/* 搜尋與狀態篩選列 */
.cpmls-list-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    align-items: center;
}
.cpmls-search-input {
    flex: 1;
    min-width: 180px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.cpmls-status-filter {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    min-width: 110px;
}
.cpmls-search-input:focus,
.cpmls-status-filter:focus {
    outline: none;
    border-color: #1e40af;
    box-shadow: 0 0 0 3px rgba(30,64,175,.1);
}

/* 分頁 */
.cpmls-pagination {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #e5e7eb;
}
.cpmls-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all .15s;
}
.cpmls-page-link:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #111827;
}
.cpmls-page-current {
    background: #1e40af !important;
    border-color: #1e40af !important;
    color: #fff !important;
    cursor: default;
}
.cpmls-page-disabled {
    color: #9ca3af;
    background: #f9fafb;
    cursor: not-allowed;
    opacity: .6;
}
.cpmls-page-ellipsis {
    padding: 0 4px;
    color: #9ca3af;
    font-size: 14px;
}
.cpmls-product-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: box-shadow .15s;
}
.cpmls-product-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.cpmls-product-thumb {
    flex: 0 0 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    background: #e5e7eb;
}
.cpmls-product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cpmls-no-image {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: #9ca3af; font-size: 12px;
}
.cpmls-product-info { flex: 1; min-width: 0; }
.cpmls-product-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cpmls-product-meta {
    font-size: 12px;
    color: #6b7280;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.cpmls-status {
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}
.cpmls-status-publish { background: #d1fae5; color: #065f46; }
.cpmls-status-future  { background: #dbeafe; color: #1e40af; }
.cpmls-status-draft   { background: #fef3c7; color: #92400e; }
.cpmls-status-pending { background: #fce7f3; color: #9f1239; }

.cpmls-product-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== 審核狀態樣式 ===== */
.cpmls-review-pending {
    border-left: 4px solid #f59e0b !important;
    background: #fffbeb;
}
.cpmls-review-rejected {
    border-left: 4px solid #ef4444 !important;
    background: #fef2f2;
}

.cpmls-review-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
}
.cpmls-review-badge--pending  { background: #fef3c7; color: #92400e; }
.cpmls-review-badge--rejected { background: #fee2e2; color: #991b1b; }

.cpmls-reject-box {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    color: #7f1d1d;
}
.cpmls-reject-box em {
    color: #991b1b;
    font-size: 12px;
    display: block;
    margin-top: 4px;
    font-style: italic;
}

.cpmls-reject-banner {
    padding: 14px 18px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-left: 4px solid #ef4444;
    border-radius: 6px;
    margin-bottom: 16px;
    color: #7f1d1d;
    line-height: 1.7;
}
.cpmls-reject-banner em {
    background: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-style: normal;
    color: #991b1b;
    font-weight: 500;
}
.cpmls-review-banner {
    padding: 12px 16px;
    background: #fffbeb;
    border-left: 4px solid #f59e0b;
    border-radius: 6px;
    margin-bottom: 16px;
    color: #92400e;
}

/* Buttons */
.cpmls-btn {
    display: inline-block;
    padding: 6px 14px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
}
.cpmls-btn:hover { background: #f3f4f6; color: #111827; }
.cpmls-btn-primary {
    background: #1e40af;
    color: #fff;
    border-color: #1e40af;
}
.cpmls-btn-primary:hover { background: #1e3a8a; color: #fff; }
.cpmls-btn-large {
    padding: 14px 40px;
    font-size: 16px;
    font-weight: 600;
}
.cpmls-btn-edit { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.cpmls-btn-edit:hover { background: #fde68a; color: #78350f; }
.cpmls-btn-view { background: #e0e7ff; border-color: #a5b4fc; color: #3730a3; }
.cpmls-btn-view:hover { background: #c7d2fe; color: #312e81; }
.cpmls-btn-delete { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.cpmls-btn-delete:hover { background: #fecaca; color: #7f1d1d; }

/* 頂部工具列 */
.cpmls-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.cpmls-toolbar-hint {
    color: #1e40af;
    font-size: 13px;
    flex: 1;
    min-width: 200px;
}
.cpmls-newtab-btn {
    white-space: nowrap;
}

/* Price / SKU combo input (select + 數字輸入並排) */
.cpmls-combo {
    display: flex;
    gap: 6px;
    align-items: stretch;
}
.cpmls-combo-select {
    flex: 0 0 auto;
    min-width: 120px;
}
.cpmls-combo-select--fixed {
    max-width: 110px;
}
.cpmls-combo-input {
    flex: 1;
    min-width: 0;
}

/* 價格選擇 + 自訂輸入(自訂框獨立一行,避免擠到隔壁欄位) */
.cpmls-price-select {
    width: 100%;
}
.cpmls-price-custom {
    width: 100%;
    margin-top: 8px;
}

/* 欄位下方提示文字 */
.cpmls-field-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
}
.cpmls-field-hint code {
    background: #f1f5f9;
    color: #1e40af;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cpmls-btn-back {
    display: inline-block;
    color: #6b7280;
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 4px;
}
.cpmls-btn-back:hover { background: #f3f4f6; color: #111827; }

/* Form */
.cpmls-form-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
    align-items: start;
}
@media (max-width: 900px) {
    .cpmls-form-grid { grid-template-columns: 1fr; }
}

.cpmls-field {
    margin-bottom: 16px;
}
.cpmls-field label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
    color: #374151;
}
.cpmls-field label small {
    font-weight: normal;
    color: #6b7280;
    margin-left: 4px;
}
.cpmls-required {
    color: #dc2626;
    margin-left: 2px;
}
.cpmls-field input[type="text"],
.cpmls-field input[type="number"],
.cpmls-field input[type="date"],
.cpmls-field input[type="time"],
.cpmls-field input[type="file"],
.cpmls-field select,
.cpmls-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.cpmls-field textarea {
    resize: vertical;
    min-height: 70px;
    line-height: 1.5;
}
.cpmls-field input:focus,
.cpmls-field select:focus,
.cpmls-field textarea:focus {
    outline: none;
    border-color: #1e40af;
    box-shadow: 0 0 0 3px rgba(30,64,175,.1);
}

/* CUS- 鎖定樣式:視覺提示這個欄位/控制元件是自動填的,不可編輯 */
.cpmls-input-locked {
    background: #f9fafb !important;
    color: #6b7280 !important;
    cursor: not-allowed;
    border-style: dashed !important;
}
select.cpmls-input-locked {
    /* select 沒有 readonly,要用 pointer-events 鎖,搭配視覺提示 */
    opacity: 0.75;
}
.cpmls-checkbox-locked {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed !important;
}
.cpmls-checkbox-locked input:checked + span {
    color: #1e40af !important;
    font-weight: 600;
}
.cpmls-field input[type="file"] {
    padding: 8px;
    background: #f9fafb;
}
.cpmls-field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

/* Fieldset */
.cpmls-fieldset {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px;
    margin: 0 0 18px 0;
    background: #fafbfc;
}
.cpmls-fieldset legend {
    font-weight: 600;
    padding: 0 8px;
    color: #1e40af;
}

/* Checkbox / Radio groups */
.cpmls-checkbox-group,
.cpmls-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}
.cpmls-radio-vertical {
    flex-direction: column;
}
.cpmls-checkbox,
.cpmls-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f3f4f6;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: all .15s;
    user-select: none;
}
.cpmls-checkbox:hover,
.cpmls-radio:hover { background: #e5e7eb; }
.cpmls-checkbox input,
.cpmls-radio input { margin: 0; cursor: pointer; }
.cpmls-checkbox input:checked + span,
.cpmls-radio input:checked + span {
    font-weight: 600;
    color: #1e40af;
}
.cpmls-checkbox:has(input:checked),
.cpmls-radio:has(input:checked) {
    background: #dbeafe;
    box-shadow: inset 0 0 0 1px #1e40af;
}
.cpmls-category-group {
    display: block; /* 覆寫父類的 flex,讓每項確實各佔一行 */
    max-height: 280px;
    overflow-y: auto;
    padding: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}
.cpmls-category-group .cpmls-checkbox {
    display: flex; /* 本身恢復 flex 以便 label 內的 input/span 對齊 */
    align-items: center;
    width: fit-content;
    max-width: 100%;
    margin-bottom: 4px;
    padding: 6px 12px;
}
.cpmls-cat-depth-1 { margin-left: 14px; }
.cpmls-cat-depth-2 { margin-left: 28px; }
.cpmls-cat-depth-3 { margin-left: 42px; }
.cpmls-cat-depth-4 { margin-left: 56px; }

/* 檔案需要重新選擇的提示(送失敗後出現) */
.cpmls-file-warning {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    color: #92400e;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
}

/* ===== Image previews & gallery editor ===== */

/* 封面 - 既有圖預覽(edit mode) */
.cpmls-current-image {
    margin-bottom: 8px;
}
.cpmls-current-image-caption {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 4px;
}

/* 新增模式選檔後的封面預覽 */
.cpmls-new-cover-preview {
    margin-top: 8px;
}
.cpmls-new-cover-preview:empty {
    display: none;
}

/* 封面縮圖容器(既有 + 新選共用) - 內含圖片與右上 × 按鈕 */
.cpmls-cover-thumb {
    position: relative;
    display: inline-block;
    border-radius: 6px;
    border: 2px solid #10b981;
    overflow: hidden;
}
.cpmls-cover-thumb img {
    max-width: 160px;
    height: auto;
    display: block;
}
.cpmls-current-image .cpmls-cover-thumb {
    border-color: #d1d5db;
    border-style: dashed;
}

/* 圖庫(既有 + 新增) - 共用容器 */
.cpmls-existing-gallery,
.cpmls-new-gallery-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    padding: 12px;
    margin: 8px 0;
    background: #f9fafb;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
}
.cpmls-new-gallery-preview:empty {
    display: none;
}
.cpmls-new-gallery-preview .cpmls-preview-caption {
    grid-column: 1 / -1;
}

/* 單張圖庫項目 */
.cpmls-gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
    transition: box-shadow .12s;
}
.cpmls-gallery-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.cpmls-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 新上傳的圖(綠框視覺區分) */
.cpmls-gallery-item--new {
    border-color: #10b981;
    border-width: 2px;
}

/* 刪除按鈕 - 永遠顯示(原本只在 hover 顯示太隱蔽) */
.cpmls-gallery-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #dc2626;
    color: #fff;
    border: 2px solid #fff;
    /* "×" 字元在大多數中文字型中下沉,改用 Arial 並調整字級/行高才能視覺置中 */
    font-family: Arial, sans-serif;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 2px 0; /* 底 2px 補償 × 字元的下沉 */
    z-index: 2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: background .15s, transform .15s;
}
.cpmls-gallery-remove:hover {
    background: #b91c1c;
    transform: scale(1.1);
}

/* 排序控制列(底部) */
.cpmls-gallery-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 4px 6px;
    z-index: 2;
}
.cpmls-gallery-move {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .15s;
}
.cpmls-gallery-move:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.4);
}
.cpmls-gallery-move:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.cpmls-gallery-position {
    font-size: 11px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    user-select: none;
}

/* 圖片順序徽章(新上傳預覽用) */
.cpmls-gallery-order {
    position: absolute;
    top: 4px;
    left: 4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #10b981;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpmls-preview-caption {
    display: block;
    font-size: 12px;
    color: #059669;
    margin-bottom: 6px;
    font-weight: 500;
}

/* Schedule inputs */
.cpmls-schedule-inputs {
    margin-top: 12px;
    padding: 12px;
    background: #fff;
    border-radius: 6px;
    border: 1px dashed #d1d5db;
}

/* Submit */
.cpmls-submit-row {
    margin-top: 24px;
    text-align: center;
    padding-top: 20px;
    border-top: 2px solid #f1f5f9;
}

/* Sidebar */
.cpmls-form-sidebar {
    position: sticky;
    top: 20px;
}
.cpmls-preview-box,
.cpmls-tip-box {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 14px;
}
.cpmls-preview-box h3,
.cpmls-tip-box h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #1e40af;
}
.cpmls-preview-content {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
    min-height: 140px;
    color: #334155;
    margin: 0;
}
.cpmls-tip-box ul {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    color: #475569;
}
.cpmls-tip-box li { margin-bottom: 4px; }
