/**
 * Riverside Pharmacy Assets - Public Styles
 */

/* ============================================
   Asset Buttons
   ============================================ */

/* Line item download button - subtle icon button */
.rpa-line-item-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    background: transparent;
    color: #2288c9;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 8px;
}

.rpa-line-item-download-btn:hover {
    background: #f0f6fc;
    border-color: #2288c9;
    color: #105a88;
}

.rpa-line-item-download-btn svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   Modal
   ============================================ */
.rpa-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
}

.rpa-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.rpa-modal-container {
    position: relative;
    max-width: 900px;
    max-height: 90vh;
    margin: 5vh auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.rpa-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid #e0e0e0;
}

.rpa-modal-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    color: #1F2A30;
}

.rpa-modal-close {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.rpa-modal-close:hover {
    background: #f0f0f0;
    color: #333;
}

.rpa-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.rpa-modal-content {
    display: flex;
    flex-direction: column;
}

.rpa-modal-loading {
    text-align: center;
    padding: 80px 30px;
}

.rpa-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #A69B73;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.rpa-modal-error {
    text-align: center;
    padding: 60px 30px;
    color: #d63638;
}

.rpa-assets-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.rpa-assets-actions {
    display: flex;
    gap: 10px;
}

.rpa-toolbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.rpa-group-by {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rpa-group-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #4a5568;
    white-space: nowrap;
}

.rpa-group-select {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #2d3748;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #cbd5e0;
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    cursor: pointer;
}

.rpa-group-select:hover {
    border-color: #a0aec0;
}

.rpa-group-select:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.rpa-view-toggle {
    display: flex;
    gap: 0;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
}

.rpa-view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-right: 1px solid #e5e7eb;
    cursor: pointer;
    color: #666;
    transition: all 0.2s ease;
}

.rpa-view-btn:last-child {
    border-right: none;
}

.rpa-view-btn:hover {
    background: #f9fafb;
    color: #2288c9;
}

.rpa-view-btn--active {
    background: #2288c9;
    color: #fff;
}

.rpa-view-btn--active:hover {
    background: #105a88;
    color: #fff;
}

.rpa-view-btn svg {
    width: 18px;
    height: 18px;
}

.rpa-assets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding: 20px;
}

.rpa-assets-grid[data-view="list"] {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-item {
    border-bottom: 1px solid #e5e7eb;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-item:last-child {
    border-bottom: none;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-label {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 12px 16px;
    border: none;
    border-radius: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-preview {
    width: 60px;
    height: 60px;
    min-width: 60px;
    margin-bottom: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-name {
    flex: 1;
    margin-bottom: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-category,
.rpa-assets-grid[data-view="list"] .rpa-asset-size {
    margin-bottom: 0;
}

.rpa-assets-grid[data-view="list"] .rpa-asset-checkbox ~ .rpa-asset-preview::after {
    top: 50%;
    transform: translateY(-50%);
}

.rpa-assets-grid[data-view="list"] .rpa-product-group {
    display: flex;
    flex-direction: column;
}

.rpa-product-group {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.rpa-product-name {
    font-size: 18px;
    font-weight: 600;
    margin: 20px 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
    grid-column: 1 / -1;
}

.rpa-product-group:first-child .rpa-product-name {
    margin-top: 0;
}

.rpa-asset-item {
    break-inside: avoid;
}

.rpa-asset-label {
    display: block;
    cursor: pointer;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    transition: all 0.2s ease;
    background: #fff;
}

.rpa-asset-label:hover {
    border-color: #A69B73;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.rpa-asset-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.rpa-asset-checkbox:checked + .rpa-asset-label {
    border-color: #A69B73;
    background: #fafaf8;
}

.rpa-asset-label {
    position: relative;
}

.rpa-asset-checkbox ~ .rpa-asset-preview::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-radius: 50%;
    background: #fff;
}

.rpa-asset-checkbox:checked ~ .rpa-asset-preview::after {
    content: '✓';
    border-color: #A69B73;
    background: #A69B73;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

.rpa-asset-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rpa-asset-preview img {
    width: 100%;
    object-fit: cover;
}

.rpa-file-icon {
    font-size: 48px;
}

.rpa-asset-info {
    padding: 5px;
}

.rpa-asset-name {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    margin-bottom: 6px;
    word-break: break-word;
    line-height: 1.3;
}

.rpa-asset-category {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    color: #fff;
    font-weight: 500;
    margin-bottom: 4px;
}

.rpa-asset-size {
    font-size: 12px;
    color: #999;
}

.rpa-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-top: 1px solid #e0e0e0;
}

.rpa-selected-count {
    font-size: 14px;
    color: #666;
}

#rpa-selected-count-text {
    font-weight: 600;
    color: #A69B73;
}

.rpa-modal-actions {
    display: flex;
    gap: 10px;
}

/* ============================================
   Button overrides for modal
   ============================================ */
.rpa-modal .rpo-btn {
    font-size: 0.875rem;
}

.rpo-btn--primary:disabled,
.rpo-btn--primary[disabled] {
    background-color: #cbd5e1;
    border-color: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.6;
}

.rpo-btn--primary:disabled:hover,
.rpo-btn--primary[disabled]:hover {
    transform: none;
    box-shadow: none;
    background-color: #cbd5e1;
    border-color: #cbd5e1;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .rpa-modal-container {
        max-width: 95%;
        margin: 2.5vh auto;
    }
    
    .rpa-modal-header,
    .rpa-modal-footer {
        padding: 15px 20px;
    }
    
    .rpa-assets-grid,
    .rpa-product-group {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .rpa-assets-grid {
        padding: 15px;
    }
    
    .rpa-assets-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }
    
    .rpa-toolbar-right {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    
    .rpa-group-by {
        width: 100%;
        justify-content: space-between;
    }
    
    .rpa-group-select {
        flex: 1;
    }
    
    .rpa-view-toggle {
        width: 100%;
    }
    
    .rpa-view-btn {
        flex: 1;
    }
    
    .rpa-modal-footer {
        flex-direction: column;
        gap: 1rem;
    }
    
    .rpa-modal-actions {
        width: 100%;
        flex-direction: column;
    }
    
    .rpa-modal-actions .rpo-btn {
        width: 100%;
    }
}

/* ============================================
   Bulk Download Styles
   ============================================ */

.rpo-bulk-download-section {
    margin: 20px 0;
}

.rpa-bulk-download-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Bulk Modal */
.rpa-bulk-modal-container {
    position: relative;
    max-width: 900px;
    max-height: 90vh;
    margin: 5vh auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.rpa-bulk-modal-header {
    padding: 2rem;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.rpa-bulk-modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
}

.rpa-bulk-modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
    min-height: 400px;
}

.rpa-bulk-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

.rpa-bulk-modal-loading p {
    margin-top: 1rem;
    color: #718096;
}

/* Products container - categories stack vertically */
#rpa-bulk-products-container {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Category Sections - full width, stacked */
.rpa-bulk-category-section {
    margin-bottom: .5rem;
    width: 100%;
    display: block;
}

.rpa-bulk-category-section:last-child {
    margin-bottom: 0;
}

/* Category Header - flexbox for title and button */
.rpa-bulk-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e5e5e5;
}

.rpa-bulk-category-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
    padding: 0;
    border: none;
}

/* Main Toggle Button */
#rpa-bulk-toggle-all[data-state="deselect"] {
    background: #A69B73 !important;
    border-color: #A69B73 !important;
    color: #fff !important;
}

#rpa-bulk-toggle-all[data-state="deselect"]:hover {
    background: #8a7e5d !important;
    border-color: #8a7e5d !important;
}

/* Category Toggle Button */
.rpa-category-toggle {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #A69B73;
    background: transparent;
    border: 1px solid #A69B73;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.rpa-category-toggle:hover {
    background: #A69B73;
    color: #fff;
}

.rpa-category-toggle:active {
    transform: scale(0.98);
}

/* When in deselect mode, show different styling */
.rpa-category-toggle[data-state="deselect"] {
    background: #A69B73;
    color: #fff;
}

.rpa-category-toggle[data-state="deselect"]:hover {
    background: #8a7e5d;
}

/* Products Grid - 2 columns within each category */
.rpa-bulk-products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    width: 100%;
}

.rpa-bulk-product-item {
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    transition: all 0.2s ease;
    background: #fff;
}

.rpa-bulk-product-item:hover {
    border-color: #A69B73;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.rpa-bulk-product-label {
    display: flex;
    align-items: start;
    gap: 12px;
    padding: 1rem;
    cursor: pointer;
    margin: 0;
}

.rpa-bulk-product-checkbox {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.rpa-bulk-product-thumbnail {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rpa-bulk-product-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rpa-bulk-no-image {
    font-size: 28px;
    color: #cbd5e0;
}

.rpa-bulk-product-info {
    flex: 1;
}

.rpa-bulk-product-name {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 8px;
    line-height: 1.4;
}

.rpa-bulk-product-size {
    color: #718096;
    font-weight: 400;
    font-size: 0.9em;
}

.rpa-bulk-asset-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rpa-bulk-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.rpa-bulk-badge--featured {
    background: #fef3c7;
    color: #92400e;
}

.rpa-bulk-badge--factpanel {
    background: #d1fae5;
    color: #065f46;
}

/* Toolbar */
.rpa-bulk-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 6px;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.rpa-bulk-toolbar-left {
    display: flex;
    gap: 8px;
}

.rpa-bulk-selected-count {
    font-size: 0.9375rem;
    color: #4a5568;
    font-weight: 500;
}

.rpa-bulk-selected-count #rpa-bulk-selected-count-text {
    font-weight: 700;
    color: #A69B73;
}

/* Footer */
.rpa-bulk-modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid #e5e5e5;
    background: #f8f9fa;
    flex-shrink: 0;
}

.rpa-bulk-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.rpa-bulk-actions .rpo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Error State */
.rpa-bulk-modal-error {
    padding: 2rem;
    text-align: center;
}

.rpa-bulk-modal-error .rpa-error-message {
    color: #e53e3e;
    font-weight: 500;
}

/* No Products State */
.rpa-bulk-no-products {
    text-align: center;
    padding: 3rem;
    color: #718096;
}

/* Responsive */
@media screen and (max-width: 1024px) {
    .rpa-bulk-products-grid {
        grid-template-columns: 1fr; /* Single column on tablets and below */
    }
    
    .rpa-bulk-category-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .rpa-category-toggle {
        width: 100%;
    }
}

@media screen and (max-width: 768px) {
    .rpa-bulk-modal-container {
        max-width: 95%;
        max-height: 95vh;
    }
    
    .rpa-bulk-modal-header,
    .rpa-bulk-modal-body,
    .rpa-bulk-modal-footer {
        padding: 1rem;
    }
    
    .rpa-bulk-product-item {
        min-width: 0; /* Allow items to shrink on mobile */
    }
    
    .rpa-bulk-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .rpa-bulk-toolbar-left {
        width: 100%;
        justify-content: center;
    }
    
    .rpa-bulk-selected-count {
        text-align: center;
    }
    
    .rpa-bulk-actions {
        flex-direction: column;
    }
    
    .rpa-bulk-actions .rpo-btn {
        width: 100%;
        justify-content: center;
    }
}

