/**
 * PCM Table Builder Styles
 * استایل‌های حرفه‌ای و responsive برای جداول
 * 
 * @version 2.4.0
 */

/* ==================== استایل‌های پایه ==================== */
.pcm-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.pcm-table th,
.pcm-table td {
    padding: 12px 16px;
    text-align: right;
    direction: rtl;
}

.pcm-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
}

/* ==================== استایل Caption ==================== */
.pcm-table caption {
    caption-side: top;
    text-align: center;
    font-weight: bold;
    padding: 12px;
    font-size: 16px;
    color: #1f2937;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
    border-bottom: 2px solid #e5e7eb;
    direction: rtl;
}

/* ==================== استایل 1: کلاسیک ==================== */
.pcm-table-style-classic {
    border: 2px solid #e5e7eb;
}

.pcm-table-style-classic th {
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
    color: #1f2937;
    border-bottom: 2px solid #d1d5db;
}

.pcm-table-style-classic td {
    border: 1px solid #e5e7eb;
    background: white;
}

.pcm-table-style-classic tbody tr:hover {
    background: #f9fafb;
    transition: background 0.3s ease;
}

/* ==================== استایل 2: مدرن ==================== */
.pcm-table-style-modern {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border-radius: 12px;
}

.pcm-table-style-modern th {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 16px;
    border: none;
}

.pcm-table-style-modern td {
    border: none;
    border-bottom: 1px solid #f3f4f6;
    background: white;
}

.pcm-table-style-modern tbody tr:last-child td {
    border-bottom: none;
}

.pcm-table-style-modern tbody tr:hover {
    background: linear-gradient(90deg, #fef3c7 0%, #fde68a 50%, #fef3c7 100%);
    transform: scale(1.01);
    transition: all 0.3s ease;
}

/* ==================== استایل 3: مینیمال ==================== */
.pcm-table-style-minimal {
    border: none;
    box-shadow: none;
}

.pcm-table-style-minimal th {
    background: transparent;
    color: #374151;
    border-bottom: 3px solid #e5e7eb;
    padding: 12px 8px;
}

.pcm-table-style-minimal td {
    border: none;
    border-bottom: 1px solid #f3f4f6;
    padding: 12px 8px;
}

.pcm-table-style-minimal tbody tr:hover {
    background: #fafafa;
}

/* ==================== استایل 4: رنگی ==================== */
.pcm-table-style-colorful {
    border-radius: 10px;
    overflow: hidden;
}

.pcm-table-style-colorful th {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    padding: 16px;
    border: none;
    position: relative;
}

.pcm-table-style-colorful th::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #60a5fa, #3b82f6, #2563eb);
}

.pcm-table-style-colorful td {
    border: none;
    background: white;
    border-bottom: 1px solid #e0f2fe;
}

.pcm-table-style-colorful tbody tr:hover {
    background: linear-gradient(90deg, #dbeafe 0%, #bfdbfe 50%, #dbeafe 100%);
    box-shadow: inset 0 0 0 2px #3b82f6;
}

/* ==================== استایل 5: استرایپ ==================== */
.pcm-table-style-stripe th {
    background: #1f2937;
    color: white;
    border: none;
}

.pcm-table-style-stripe td {
    border: none;
}

.pcm-table-style-stripe tbody tr:nth-child(odd) {
    background: #f9fafb;
}

.pcm-table-style-stripe tbody tr:nth-child(even) {
    background: white;
}

.pcm-table-style-stripe tbody tr:hover {
    background: #fef3c7;
    cursor: pointer;
}

/* ==================== استایل 6: الگانت ==================== */
.pcm-table-style-elegant {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border-radius: 16px;
}

.pcm-table-style-elegant th {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #f1f5f9;
    padding: 18px;
    font-size: 14px;
    border: none;
}

.pcm-table-style-elegant td {
    border: none;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 16px;
}

.pcm-table-style-elegant tbody tr:hover {
    background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 50%, #f8fafc 100%);
    box-shadow: inset 0 0 0 1px #cbd5e1;
}

/* ==================== استایل 7: تیره ==================== */
.pcm-table-style-dark {
    background: #1f2937;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.pcm-table-style-dark th {
    background: #111827;
    color: #f9fafb;
    border-bottom: 2px solid #374151;
}

.pcm-table-style-dark td {
    color: #e5e7eb;
    background: #1f2937;
    border-bottom: 1px solid #374151;
}

.pcm-table-style-dark tbody tr:hover {
    background: #374151;
}

/* ==================== استایل 8: گرادیانت ==================== */
.pcm-table-style-gradient {
    border-radius: 12px;
    overflow: hidden;
}

.pcm-table-style-gradient th {
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #3b82f6 100%);
    color: white;
    padding: 16px;
    border: none;
    animation: gradient-shift 5s ease infinite;
    background-size: 200% 200%;
}

@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.pcm-table-style-gradient td {
    border: none;
    background: white;
    border-bottom: 1px solid #f3f4f6;
}

.pcm-table-style-gradient tbody tr:hover {
    background: linear-gradient(90deg, #fce7f3 0%, #ede9fe 50%, #dbeafe 100%);
}

/* ==================== Responsive Design ==================== */
@media screen and (max-width: 768px) {
    .pcm-table-responsive {
        border: none;
        box-shadow: none;
    }
    
    .pcm-table-responsive thead {
        display: none;
    }
    
    .pcm-table-responsive tbody,
    .pcm-table-responsive tr,
    .pcm-table-responsive td {
        display: block;
        width: 100%;
    }
    
    .pcm-table-responsive tr {
        margin-bottom: 20px;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        background: white;
        padding: 16px;
    }
    
    .pcm-table-responsive td {
        text-align: right;
        position: relative;
        padding: 0;
        border: none;
        border-bottom: 1px solid #f3f4f6;
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 12px;
    }
    
    .pcm-table-responsive td:last-child {
        border-bottom: none;
    }
    
    .pcm-table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6366f1;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        display: block;
        margin-bottom: 4px;
    }
    
    .pcm-table-responsive td::after {
        content: attr(data-label) ": ";
        display: none;
    }
}

/* ==================== مدال ساخت جدول ==================== */
.pcm-table-modal {
    display: none;
    position: fixed;
    z-index: 100000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

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

.pcm-table-modal-content {
    background: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

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

.pcm-table-modal-header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 24px 32px;
    border-radius: 16px 16px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pcm-table-modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.pcm-table-modal-close {
    color: white;
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    background: none;
    border: none;
    transition: transform 0.2s;
}

.pcm-table-modal-close:hover {
    transform: rotate(90deg);
}

.pcm-table-modal-body {
    padding: 32px;
}

.pcm-table-form-group {
    margin-bottom: 24px;
}

.pcm-table-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #374151;
    font-size: 14px;
}

.pcm-table-form-group input[type="number"],
.pcm-table-form-group input[type="text"],
.pcm-table-form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s;
}

.pcm-table-form-group input[type="number"]:focus,
.pcm-table-form-group input[type="text"]:focus,
.pcm-table-form-group select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.pcm-table-input-text {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    direction: rtl;
}

.pcm-table-input-text::placeholder {
    color: #9ca3af;
    font-style: italic;
}

.pcm-table-form-checkbox {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.pcm-table-form-checkbox:hover {
    background: #f3f4f6;
}

.pcm-table-form-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.pcm-table-form-checkbox label {
    margin: 0;
    cursor: pointer;
    font-weight: 500;
    color: #1f2937;
}

.pcm-table-modal-footer {
    padding: 20px 32px;
    background: #f9fafb;
    border-radius: 0 0 16px 16px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.pcm-table-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.pcm-table-btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.pcm-table-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.pcm-table-btn-secondary {
    background: white;
    color: #6b7280;
    border: 2px solid #e5e7eb;
}

.pcm-table-btn-secondary:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

/* ==================== پیش‌نمایش استایل‌ها ==================== */
.pcm-table-style-preview {
    margin-top: 16px;
    padding: 16px;
    background: #f9fafb;
    border-radius: 8px;
    border: 2px dashed #d1d5db;
}

.pcm-table-style-preview-title {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 12px;
}

.pcm-table-style-preview-table {
    width: 100%;
    font-size: 12px;
}

/* ==================== انیمیشن‌های اضافی ==================== */
.pcm-table tbody tr {
    animation: fadeInRow 0.5s ease backwards;
}

.pcm-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.pcm-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.pcm-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.pcm-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.pcm-table tbody tr:nth-child(5) { animation-delay: 0.25s; }

@keyframes fadeInRow {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==================== Print Styles ==================== */
@media print {
    .pcm-table {
        box-shadow: none;
        page-break-inside: avoid;
    }
    
    .pcm-table tbody tr:hover {
        background: transparent !important;
    }
}

/* ==================== دکمه ویرایش جدول ==================== */
.pcm-table-wrapper {
    position: relative;
    margin: 20px 0;
}

.pcm-table-edit-btn {
    position: absolute;
    top: -40px;
    left: 0;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.pcm-table-wrapper:hover .pcm-table-edit-btn {
    opacity: 1;
    transform: translateY(0);
}

.pcm-table-edit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.pcm-table-edit-btn:active {
    transform: translateY(0);
}

/* ==================== مدال ویرایشگر جدول ==================== */
.pcm-table-editor-modal {
    display: none;
    position: fixed;
    z-index: 100001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.pcm-table-editor-content {
    background: white;
    margin: 2% auto;
    padding: 0;
    border-radius: 20px;
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

.pcm-table-editor-header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 24px 32px;
    border-radius: 20px 20px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.pcm-table-editor-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.pcm-table-editor-close {
    color: white;
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    background: none;
    border: none;
    transition: transform 0.2s;
    line-height: 1;
}

.pcm-table-editor-close:hover {
    transform: rotate(90deg);
}

.pcm-table-editor-body {
    padding: 24px 32px;
    overflow-y: auto;
    flex: 1;
}

.pcm-table-editor-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    padding: 16px;
    background: #f9fafb;
    border-radius: 12px;
}

.pcm-editor-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pcm-editor-btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.pcm-editor-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.3);
}

.pcm-editor-btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.pcm-editor-btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

.pcm-editor-btn-secondary {
    background: white;
    color: #6b7280;
    border: 2px solid #e5e7eb;
}

.pcm-editor-btn-secondary:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.pcm-editor-style-select {
    padding: 10px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: white;
    transition: all 0.3s;
}

.pcm-editor-style-select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* جدول قابل ویرایش */
.pcm-editable-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.pcm-editable-table th,
.pcm-editable-table td {
    border: 2px solid #e5e7eb;
    padding: 12px;
    text-align: right;
    position: relative;
}

.pcm-editable-table th {
    background: #f3f4f6;
    font-weight: 600;
}

.pcm-editable-cell {
    min-height: 40px;
    padding: 8px;
    cursor: text;
    transition: background 0.2s;
}

.pcm-editable-cell:hover {
    background: #fef3c7;
}

.pcm-editable-cell:focus {
    outline: 2px solid #6366f1;
    outline-offset: -2px;
    background: #fff;
}

.pcm-cell-delete-btn,
.pcm-row-delete-btn,
.pcm-col-delete-btn {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pcm-editable-table td:hover .pcm-cell-delete-btn,
.pcm-editable-table tr:hover .pcm-row-delete-btn,
.pcm-editable-table th:hover .pcm-col-delete-btn {
    opacity: 1;
}

.pcm-row-delete-btn {
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
}

.pcm-col-delete-btn {
    left: 50%;
    top: -12px;
    transform: translateX(-50%);
}

.pcm-cell-delete-btn:hover,
.pcm-row-delete-btn:hover,
.pcm-col-delete-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.pcm-table-editor-footer {
    padding: 20px 32px;
    background: #f9fafb;
    border-radius: 0 0 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.pcm-editor-footer-left {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pcm-editor-footer-right {
    display: flex;
    gap: 12px;
}

.pcm-table-responsive-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.pcm-table-responsive-toggle:hover {
    border-color: #6366f1;
    background: #f9fafb;
}

.pcm-table-responsive-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.pcm-table-responsive-toggle label {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
}

/* ==================== Responsive برای ویرایشگر ==================== */
@media screen and (max-width: 768px) {
    .pcm-table-editor-content {
        width: 98%;
        margin: 1% auto;
        max-height: 98vh;
    }
    
    .pcm-table-editor-header {
        padding: 16px 20px;
    }
    
    .pcm-table-editor-header h2 {
        font-size: 18px;
    }
    
    .pcm-table-editor-body {
        padding: 16px 20px;
    }
    
    .pcm-table-editor-controls {
        padding: 12px;
    }
    
    .pcm-editor-btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .pcm-table-editor-footer {
        padding: 16px 20px;
        flex-direction: column;
    }
    
    .pcm-editor-footer-left,
    .pcm-editor-footer-right {
        width: 100%;
        justify-content: center;
    }
    
    .pcm-editable-table {
        font-size: 13px;
    }
    
    .pcm-editable-table th,
    .pcm-editable-table td {
        padding: 8px;
    }
}
