/* =============================================
   PPM - Product Price Manager
   ============================================= */

:root {
    --ppm-primary:      #6366f1;
    --ppm-primary-dk:   #4f46e5;
    --ppm-success:      #10b981;
    --ppm-warning:      #f59e0b;
    --ppm-danger:       #ef4444;
    --ppm-bg:           #f1f5f9;
    --ppm-card:         #ffffff;
    --ppm-border:       #e2e8f0;
    --ppm-text:         #1e293b;
    --ppm-muted:        #64748b;
    --ppm-radius:       14px;
    --ppm-radius-sm:    8px;
    --ppm-shadow:       0 2px 8px rgba(0,0,0,0.08);
    --ppm-shadow-lg:    0 8px 24px rgba(0,0,0,0.12);
    --ppm-tr:           all 0.2s ease;
}

/* =============================================
   Wrapper
   ============================================= */
.ppm-wrapper {
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    direction: rtl;
    max-width: 1100px;
    margin: 28px auto;
    padding: 0 16px;
    color: var(--ppm-text);
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

/* =============================================
   Header
   ============================================= */
.ppm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    background: linear-gradient(135deg, var(--ppm-primary) 0%, var(--ppm-primary-dk) 100%);
    color: #fff;
    padding: 22px 28px;
    border-radius: var(--ppm-radius);
    margin-bottom: 18px;
    box-shadow: var(--ppm-shadow-lg);
}

.ppm-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ppm-header-icon { font-size: 30px; line-height: 1; }

.ppm-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.ppm-header-stats {
    display: flex;
    gap: 10px;
}

.ppm-stat-box {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: var(--ppm-radius-sm);
    padding: 10px 20px;
    text-align: center;
    min-width: 90px;
}

.ppm-stat-label {
    display: block;
    font-size: 11px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.ppm-stat-value {
    display: block;
    font-size: 22px;
    font-weight: 800;
}

/* =============================================
   Search
   ============================================= */
.ppm-search-section {
    background: var(--ppm-card);
    border: 1px solid var(--ppm-border);
    border-radius: var(--ppm-radius);
    padding: 18px 22px;
    margin-bottom: 18px;
    box-shadow: var(--ppm-shadow);
}

.ppm-search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.ppm-search-icon {
    position: absolute;
    right: 14px;
    font-size: 18px;
    pointer-events: none;
    z-index: 2;
}

#ppm-search-input {
    width: 100%;
    padding: 13px 46px 13px 76px;
    font-size: 15px;
    font-family: inherit;
    border: 2px solid var(--ppm-border);
    border-radius: var(--ppm-radius-sm);
    background: var(--ppm-bg);
    color: var(--ppm-text);
    outline: none;
    transition: var(--ppm-tr);
    direction: rtl;
}

#ppm-search-input:focus {
    border-color: var(--ppm-primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}

#ppm-search-input::placeholder {
    color: var(--ppm-muted);
    font-size: 14px;
}

/* دکمه پاک کردن */
.ppm-clear-btn {
    position: absolute;
    left: 46px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: var(--ppm-border);
    color: var(--ppm-muted);
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--ppm-tr);
    line-height: 1;
    padding: 0;
}

.ppm-clear-btn.visible { display: flex; }

.ppm-clear-btn:hover {
    background: var(--ppm-danger);
    color: #fff;
}

/* اسپینر سرچ */
.ppm-search-spinner {
    position: absolute;
    left: 14px;
    display: none;
}

.ppm-search-spinner.active { display: block; }

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

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

.ppm-search-info {
    margin-top: 10px;
    font-size: 13px;
    color: var(--ppm-muted);
    min-height: 20px;
    line-height: 1.5;
}

/* =============================================
   Table Container
   ============================================= */
.ppm-table-container {
    background: var(--ppm-card);
    border: 1px solid var(--ppm-border);
    border-radius: var(--ppm-radius);
    overflow: hidden;
    box-shadow: var(--ppm-shadow);
    min-height: 180px;
    position: relative;
}

/* لودینگ */
.ppm-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--ppm-muted);
}

.ppm-loading-spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--ppm-border);
    border-top-color: var(--ppm-primary);
    border-radius: 50%;
    animation: ppm-spin 0.8s linear infinite;
    margin-bottom: 14px;
}

.ppm-loading p { margin: 0; font-size: 14px; }

/* =============================================
   Table
   ============================================= */
.ppm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    display: none;
}

.ppm-table.loaded { display: table; }

/* هدر جدول */
.ppm-table thead tr {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 2px solid var(--ppm-border);
}

.ppm-table thead th {
    padding: 14px 18px;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    color: var(--ppm-text);
    white-space: nowrap;
}

.ppm-col-num    { width: 52px; text-align: center !important; }
.ppm-col-name   { min-width: 220px; }
.ppm-col-sale,
.ppm-col-purchase,
.ppm-col-profit { width: 160px; }
.ppm-col-percent{ width: 110px; text-align: center !important; }

/* سطرهای جدول */
.ppm-table tbody tr {
    border-bottom: 1px solid var(--ppm-border);
    transition: background 0.15s ease;
    animation: ppm-rowIn 0.3s ease both;
}

@keyframes ppm-rowIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ppm-table tbody tr:last-child { border-bottom: none; }

.ppm-table tbody tr:nth-child(even) { background: #fafbfc; }

.ppm-table tbody tr:hover { background: rgba(99,102,241,0.05); }

.ppm-table td {
    padding: 13px 18px;
    vertical-align: middle;
}

/* دیلی‌های انیمیشن */
.ppm-table tbody tr:nth-child(1)  { animation-delay: .02s }
.ppm-table tbody tr:nth-child(2)  { animation-delay: .04s }
.ppm-table tbody tr:nth-child(3)  { animation-delay: .06s }
.ppm-table tbody tr:nth-child(4)  { animation-delay: .08s }
.ppm-table tbody tr:nth-child(5)  { animation-delay: .10s }
.ppm-table tbody tr:nth-child(6)  { animation-delay: .12s }
.ppm-table tbody tr:nth-child(7)  { animation-delay: .14s }
.ppm-table tbody tr:nth-child(8)  { animation-delay: .16s }
.ppm-table tbody tr:nth-child(9)  { animation-delay: .18s }
.ppm-table tbody tr:nth-child(10) { animation-delay: .20s }

/* =============================================
   سلول‌ها
   ============================================= */

/* شماره ردیف */
.ppm-td-num {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--ppm-muted);
}

/* نام */
.ppm-td-name a {
    color: var(--ppm-primary);
    text-decoration: none;
    font-weight: 600;
    line-height: 1.5;
    transition: var(--ppm-tr);
}

.ppm-td-name a:hover {
    color: var(--ppm-primary-dk);
    text-decoration: underline;
}

/* قیمت‌ها */
.ppm-td-price { white-space: nowrap; }

.ppm-price-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ppm-price-del {
    font-size: 12px;
    color: var(--ppm-muted);
    text-decoration: line-through;
    font-weight: 400;
}

.ppm-price-blue   { color: var(--ppm-primary); font-weight: 700; font-size: 14px; }
.ppm-price-red    { color: var(--ppm-danger);  font-weight: 700; font-size: 14px; }
.ppm-price-orange { color: var(--ppm-warning); font-weight: 700; font-size: 14px; }

.ppm-profit-pos { color: var(--ppm-success); font-weight: 700; font-size: 14px; }
.ppm-profit-neg { color: var(--ppm-danger);  font-weight: 700; font-size: 14px; }

.ppm-dash { color: var(--ppm-muted); font-style: italic; font-size: 13px; }

/* ستون وسط‌چین */
.ppm-td-center { text-align: center; }

/* بج درصد */
.ppm-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.ppm-badge-green  {
    background: rgba(16,185,129,0.12);
    color: var(--ppm-success);
    border: 1px solid rgba(16,185,129,0.3);
}

.ppm-badge-yellow {
    background: rgba(245,158,11,0.12);
    color: var(--ppm-warning);
    border: 1px solid rgba(245,158,11,0.3);
}

.ppm-badge-red {
    background: rgba(239,68,68,0.12);
    color: var(--ppm-danger);
    border: 1px solid rgba(239,68,68,0.3);
}

/* هایلایت سرچ */
.ppm-hl {
    background: rgba(99,102,241,0.18);
    color: var(--ppm-primary-dk);
    border-radius: 3px;
    padding: 0 2px;
    font-weight: 700;
    font-style: normal;
}

/* =============================================
   Empty
   ============================================= */
.ppm-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--ppm-muted);
}

.ppm-empty-icon { font-size: 50px; margin-bottom: 14px; }

.ppm-empty p {
    font-size: 16px;
    font-weight: 600;
    color: var(--ppm-text);
    margin: 0 0 8px;
}

.ppm-empty small { font-size: 13px; }

/* =============================================
   Pagination
   ============================================= */
.ppm-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 20px 16px;
}

.ppm-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--ppm-border);
    border-radius: var(--ppm-radius-sm);
    background: var(--ppm-card);
    color: var(--ppm-text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--ppm-tr);
    white-space: nowrap;
}

.ppm-page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--ppm-primary);
    color: var(--ppm-primary);
    background: rgba(99,102,241,0.06);
}

.ppm-page-btn.active {
    background: var(--ppm-primary);
    border-color: var(--ppm-primary);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

.ppm-page-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ppm-dots {
    padding: 0 4px;
    color: var(--ppm-muted);
    font-size: 16px;
    display: inline-flex;
    align-items: center;
}

/* =============================================
   Access Denied
   ============================================= */
.ppm-access-denied {
    text-align: center;
    padding: 60px 20px;
    background: var(--ppm-card);
    border: 1px solid var(--ppm-border);
    border-radius: var(--ppm-radius);
    color: var(--ppm-muted);
}

.ppm-denied-icon { font-size: 50px; margin-bottom: 16px; }

/* =============================================
   Admin MetaBox
   ============================================= */
.ppm-metabox {
    padding: 4px 0;
    font-family: Tahoma, sans-serif;
    direction: rtl;
}

.ppm-field-group { margin-bottom: 16px; }

.ppm-field-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 13px;
    color: #1e293b;
    margin-bottom: 8px;
}

.ppm-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.ppm-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.ppm-note {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: #ef4444;
    line-height: 1.5;
}

.ppm-price-info {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
}

.ppm-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed #e2e8f0;
    font-size: 12px;
}

.ppm-info-row:last-child { border-bottom: none; }

.ppm-info-label { color: #64748b; font-weight: 500; }

.ppm-info-value {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ppm-info-value.ppm-sale   { color: #6366f1; }
.ppm-info-value.ppm-profit { color: #10b981; }

.ppm-badge-sm {
    background: #10b981;
    color: #fff;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 768px) {

    .ppm-header {
        padding: 16px 18px;
        flex-direction: column;
        align-items: flex-start;
    }

    .ppm-header h2 { font-size: 17px; }

    .ppm-header-stats { width: 100%; }

    .ppm-stat-box { flex: 1; }

    .ppm-search-section { padding: 14px 16px; }

    /* جدول اسکرول افقی روی موبایل */
    .ppm-table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .ppm-table { min-width: 600px; }

    .ppm-table td,
    .ppm-table th { padding: 10px 12px; font-size: 13px; }

    .ppm-pagination { gap: 4px; padding: 16px 10px; }

    .ppm-page-btn { min-width: 36px; height: 36px; font-size: 13px; padding: 0 10px; }
}

@media (max-width: 480px) {
    .ppm-wrapper { padding: 0 10px; margin: 16px auto; }
    .ppm-header h2 { font-size: 15px; }
    #ppm-search-input { font-size: 14px; padding: 11px 44px 11px 70px; }
}