/**
 * Interactive Business Model Canvas Visualization
 * CSS Grid Layout System for Collaborative Canvas
 */

/* Canvas Container */
.canvas-visualization {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 0.8fr auto;
    gap: 2px;
    min-height: calc(100vh - 80px);
    padding: 10px;
    background-color: var(--canvas-background, #f8f9fa);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* BMC Block Positioning */
.canvas-block {
    position: relative;
    border: 2px solid var(--block-border, #dee2e6);
    border-radius: 8px;
    padding: 15px;
    background-color: var(--block-background, #ffffff);
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden;
    min-height: 120px;
}

.canvas-block:hover {
    border-color: var(--block-border-hover, #007bff);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
    transform: translateY(-2px);
}

.canvas-block.editing {
    border-color: var(--block-border-editing, #28a745);
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}

.canvas-block.being-edited-by-other {
    border-color: var(--block-border-other-editing, #ffc107);
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.1);
}

/* Traditional BMC Grid Positioning */
.block-partnerships { 
    grid-area: 1 / 1 / 3 / 2; 
    background-color: var(--partnerships-color, #E8F5E8);
    display: flex;
    flex-direction: column;
}

.block-partnerships .block-content {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

.block-activities { 
    grid-area: 1 / 2 / 2 / 3; 
    background-color: var(--activities-color, #FFF2CC);
}

.block-resources { 
    grid-area: 2 / 2 / 3 / 3; 
    background-color: var(--resources-color, #F8CECC);
}

.block-value-prop { 
    grid-area: 1 / 3 / 3 / 4; 
    background-color: var(--value-prop-color, #D5E8D4);
    display: flex;
    flex-direction: column;
}

.block-value-prop .block-content {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

.block-relationships { 
    grid-area: 1 / 4 / 3 / 5; 
    background-color: var(--relationships-color, #DAE8FC);
    display: flex;
    flex-direction: column;
}

.block-relationships .block-content {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

.block-channels { 
    grid-area: 3 / 4 / 4 / 5; 
    background-color: var(--channels-color, #FFE6CC);
}

.block-segments { 
    grid-area: 1 / 5 / 3 / 6; 
    background-color: var(--segments-color, #E1D5E7);
    display: flex;
    flex-direction: column;
}

.block-segments .block-content {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

.block-cost { 
    grid-area: 3 / 1 / 4 / 4; 
    background-color: var(--cost-color, #F8CECC);
}

.block-revenue { 
    grid-area: 3 / 4 / 4 / 6; 
    background-color: var(--revenue-color, #D5E8D4);
}

/* Block Headers */
.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.block-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--block-title-color, #343a40);
    margin: 0;
}

.block-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.canvas-block:hover .block-actions {
    opacity: 1;
}

.block-action-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--action-btn-color, #6c757d);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.block-action-btn:hover {
    background-color: var(--action-btn-hover, #e9ecef);
    color: var(--action-btn-hover-color, #495057);
}

/* Block Content */
.block-content {
    line-height: 1.5;
    color: var(--block-content-color, #495057);
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
}

.block-content::-webkit-scrollbar {
    width: 4px;
}

.block-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

.block-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

.block-content-editable {
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    width: 100%;
    min-height: 60px;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

.block-content-placeholder {
    color: var(--placeholder-color, #adb5bd);
    font-style: italic;
}

/* User Presence Indicators */
.user-presence {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 4px;
    z-index: 10;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--user-color, #007bff);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: help;
}

.user-cursor {
    position: absolute;
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 100;
    transition: all 0.1s ease;
}

.user-cursor::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 8px solid var(--cursor-color, #007bff);
    border-right: 8px solid transparent;
    border-bottom: 12px solid transparent;
    border-top: 12px solid var(--cursor-color, #007bff);
}

.user-cursor-label {
    position: absolute;
    top: 20px;
    left: 0;
    background-color: var(--cursor-color, #007bff);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 101;
}

/* Edit Status Indicators */
.edit-status {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background-color: var(--edit-status-bg, #28a745);
    color: white;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    display: none;
}

.canvas-block.being-edited .edit-status {
    display: block;
    background-color: var(--edit-status-active, #28a745);
}

.canvas-block.being-edited-by-other .edit-status {
    display: block;
    background-color: var(--edit-status-other, #ffc107);
    color: var(--edit-status-other-text, #212529);
}

/* Loading States */
.block-loading {
    position: relative;
    pointer-events: none;
}

.block-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--loading-color, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .canvas-visualization {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(9, auto);
        gap: 8px;
        padding: 8px;
    }
    
    .canvas-block {
        grid-area: auto !important;
        min-height: 80px;
        padding: 12px;
    }
    
    .block-value-prop,
    .block-segments {
        min-height: 80px;
    }
    
    .block-title {
        font-size: 1rem;
    }
    
    .block-content {
        font-size: 0.9rem;
        max-height: 100px;
    }
    
    .user-presence {
        top: 5px;
        right: 5px;
    }
    
    .user-avatar {
        width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }
    
    /* Mobile expand button */
    .mobile-expand-btn {
        display: block;
        position: absolute;
        bottom: 8px;
        right: 8px;
        background-color: var(--expand-btn-bg, #007bff);
        color: white;
        border: none;
        border-radius: 50%;
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
        cursor: pointer;
        z-index: 10;
    }
    
    .mobile-expand-btn:hover {
        background-color: var(--expand-btn-hover, #0056b3);
    }
}

@media (min-width: 769px) {
    .mobile-expand-btn {
        display: none;
    }
}

/* Tablet Responsive Design */
@media (max-width: 1024px) and (min-width: 769px) {
    .canvas-visualization {
        gap: 4px;
        padding: 8px;
    }
    
    .canvas-block {
        padding: 12px;
        min-height: 100px;
    }
    
    .block-title {
        font-size: 1rem;
    }
    
    .block-content {
        font-size: 0.9rem;
        max-height: 150px;
    }
}

/* Print Styles */
@media print {
    .canvas-visualization {
        grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
        grid-template-rows: 1fr 1fr 1fr;
        gap: 1px;
        padding: 0;
        background: white;
        color: black;
        min-height: auto;
        page-break-inside: avoid;
    }
    
    .canvas-block {
        border: 1px solid #000;
        background: white !important;
        padding: 10px;
        min-height: 80px;
        break-inside: avoid;
    }
    
    .block-title {
        font-size: 0.9rem;
        color: black;
    }
    
    .block-content {
        font-size: 0.8rem;
        color: black;
        max-height: none;
        overflow: visible;
    }
    
    .user-presence,
    .edit-status,
    .block-actions,
    .mobile-expand-btn {
        display: none !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .canvas-block {
        border-width: 3px;
        border-color: #000;
    }
    
    .block-title {
        color: #000;
        font-weight: 700;
    }
    
    .block-content {
        color: #000;
    }
}

/* Attribution Styling */
.canvas-attribution {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 16px;
    background-color: var(--attribution-bg, #f8f9fa);
    border-top: 1px solid var(--attribution-border, #dee2e6);
    margin-top: 10px;
}

.attribution-text {
    font-size: 0.85rem;
    color: var(--attribution-text, #6c757d);
    margin: 0;
    text-align: center;
    line-height: 1.4;
}

.attribution-text i {
    margin-right: 6px;
    color: var(--attribution-icon, #007bff);
}

.attribution-text a {
    color: var(--attribution-link, #007bff);
    text-decoration: none;
    border-bottom: 1px dotted var(--attribution-link, #007bff);
}

.attribution-text a:hover {
    color: var(--attribution-link-hover, #0056b3);
    border-bottom-style: solid;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .canvas-block,
    .block-action-btn,
    .user-cursor {
        transition: none;
    }
    
    .canvas-block:hover {
        transform: none;
    }
    
    .block-loading::after {
        animation: none;
    }
}
