/* Role-based Access Control Styles - FIXED VERSION */
/* ไฟล์นี้เป็นส่วนเสริมสำหรับการจัดการสิทธิ์ - แก้ไขปัญหาแล้ว */

/* ==== PERMISSION BADGES ==== */
.permission-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.7em;
    font-weight: bold;
    text-transform: uppercase;
    margin-left: 8px;
    vertical-align: middle;
    animation: fadeIn 0.3s ease-in;
}

.admin-badge {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    box-shadow: 0 1px 3px rgba(231, 76, 60, 0.3);
}

.readonly-badge {
    background: linear-gradient(45deg, #f39c12, #e67e22);
    color: white;
    box-shadow: 0 1px 3px rgba(243, 156, 18, 0.3);
}

/* ==== ADMIN-ONLY ELEMENTS ==== */
.admin-only-text {
    color: #e74c3c;
    font-size: 0.8em;
    font-style: italic;
    margin-top: 0.25rem;
}

.admin-cost-price-label {
    color: #e74c3c !important;
    font-weight: 600;
    position: relative;
}

.admin-cost-price-label::before {
    content: "🔒";
    margin-right: 4px;
    font-size: 0.8em;
}

/* ==== SPECIFIC COLUMN HIDING FOR NON-ADMIN (ใช้ selector ที่เฉพาะเจาะจง) ==== */
/* ซ่อนเฉพาะคอลัมน์ราคาทุน (คอลัมน์ที่ 7) สำหรับ non-admin */
.non-admin .products-table th.cost-price-column,
.non-admin .products-table td.cost-price-column {
    display: none;
}

/* ซ่อนฟิลด์ราคาทุนในฟอร์มสำหรับ non-admin */
.non-admin .form-group.cost-price-field {
    display: none;
}

/* ซ่อนรายการราคาทุนใน detail view สำหรับ non-admin */
.non-admin .detail-item.cost-price-detail {
    display: none;
}

/* ตัวอย่างการใช้งาน - เฉพาะในแถวของตาราง */
.non-admin .cost-price-cell {
    display: none;
}

/* ==== READONLY STYLING ==== */
.readonly-cost-price {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px solid #ffc107;
    cursor: not-allowed;
    color: #6c757d;
    position: relative;
}

.readonly-cost-price:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.25);
}

.readonly-cost-price::after {
    content: "🔒";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #ffc107;
    pointer-events: none;
    font-size: 0.9em;
}

/* ==== PRICE CELL STYLING ==== */
.price-cell-readonly {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border-left: 4px solid #ffc107;
    position: relative;
    padding-left: 12px;
}

.price-cell-readonly::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, #ffc107, #f39c12);
    animation: pulse 2s infinite;
}

/* ==== NON-ADMIN NOTICES ==== */
.non-admin-notice {
    display: none;
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    padding: 0.5rem;
    border-radius: 4px;
    margin-top: 0.5rem;
    font-size: 0.85em;
    position: relative;
    animation: slideInDown 0.3s ease-out;
}

.non-admin .non-admin-notice {
    display: block;
}

.non-admin-notice::before {
    content: "⚠️";
    margin-right: 6px;
}

/* ==== ADMIN UI ENHANCEMENTS ==== */
.is-admin .admin-cost-price-label::after {
    content: "Admin Access";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: #e74c3c;
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.6em;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1000;
}

.is-admin .admin-cost-price-label:hover::after {
    opacity: 1;
}

/* ==== FORM ENHANCEMENTS ==== */
.form-group.admin-only-form-field {
    position: relative;
    border: 2px dashed #e74c3c;
    border-radius: 8px;
    padding: 1rem;
    background: linear-gradient(135deg, #fdf2f2 0%, #fce4ec 100%);
}

.form-group.admin-only-form-field::before {
    content: "🔐 Admin Only";
    position: absolute;
    top: -10px;
    left: 10px;
    background: #e74c3c;
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.7em;
    font-weight: bold;
}

/* ==== ANIMATIONS ==== */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ==== ROLE INDICATORS ==== */
.role-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8em;
    z-index: 9999;
    animation: slideInUp 0.5s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.role-indicator.admin {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
}

.role-indicator.manager {
    background: linear-gradient(45deg, #f39c12, #e67e22);
}

.role-indicator.editor {
    background: linear-gradient(45deg, #3498db, #2980b9);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==== PERMISSION TOOLTIPS ==== */
.permission-tooltip {
    position: relative;
    cursor: help;
}

.permission-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 0.8em;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.permission-tooltip::before {
    content: "";
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.permission-tooltip:hover::after,
.permission-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

/* ==== RESPONSIVE DESIGN ==== */
@media (max-width: 768px) {
    .permission-badge {
        font-size: 0.6em;
        padding: 1px 4px;
    }
    
    .role-indicator {
        position: relative;
        top: auto;
        right: auto;
        margin: 0.5rem 0;
        text-align: center;
    }
    
    .non-admin-notice {
        font-size: 0.8em;
        padding: 0.4rem;
    }
    
    .admin-only-form-field {
        padding: 0.8rem;
    }
}

/* ==== DARK MODE SUPPORT ==== */
@media (prefers-color-scheme: dark) {
    .readonly-cost-price {
        background: linear-gradient(135deg, #2d3436 0%, #636e72 100%);
        border-color: #fdcb6e;
        color: #ddd;
    }
    
    .price-cell-readonly {
        background: linear-gradient(135deg, #2d3436 0%, #636e72 100%);
        border-left-color: #fdcb6e;
    }
    
    .non-admin-notice {
        background: #2d3436;
        border-color: #fdcb6e;
        color: #ddd;
    }
    
    .form-group.admin-only-form-field {
        background: linear-gradient(135deg, #2d3436 0%, #636e72 100%);
        border-color: #e17055;
    }
}

/* ==== PRINT STYLES ==== */
@media print {
    .permission-badge,
    .role-indicator,
    .non-admin-notice {
        display: none !important;
    }
    
    .admin-cost-price-label::before {
        display: none;
    }
    
    .readonly-cost-price::after {
        display: none;
    }
}

/* ==== เพิ่ม CSS สำหรับการเรียงลำดับ ==== */
.sort-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.sort-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sort-group label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 0;
}

#sortField {
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
}

.sort-order-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid #007bff;
    background: white;
    color: #007bff;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sort-order-btn:hover {
    background: #007bff;
    color: white;
}

.sort-order-btn.desc {
    background: #007bff;
    color: white;
}

/* Sortable headers */
.sortable-header {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background-color 0.2s ease;
}

.sortable-header:hover {
    background-color: rgba(0, 123, 255, 0.1);
}

.sortable-header.active {
    background-color: rgba(0, 123, 255, 0.2);
    color: #007bff;
}

.sort-icon {
    margin-left: 0.5rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.sortable-header:hover .sort-icon,
.sortable-header.active .sort-icon {
    opacity: 1;
}