/**
 * Universal Canvas Base CSS
 * Common styles shared across all framework canvases (BMC, SWOT, VPC, Porter's, PESTELE, McKinsey 7S)
 * Provides foundation styling that can be extended by framework-specific CSS
 */

/* ================== GLOBAL RESET AND BASE ================== */

.canvas-visualization * {
    box-sizing: border-box;
}

.canvas-visualization {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 600px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary, #333);
    background: var(--background-primary, #ffffff);
    overflow: auto;
    display: grid;
    gap: 1px;
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ================== CSS VARIABLES (THEME READY) ================== */

:root {
    /* Base Colors */
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --text-placeholder: #bbbbbb;
    
    /* Background Colors */
    --background-primary: #ffffff;
    --background-secondary: #f8f9fa;
    --background-tertiary: #e9ecef;
    --background-hover: #f1f3f5;
    
    /* Border Colors */
    --border-light: #e0e0e0;
    --border-medium: #cccccc;
    --border-dark: #999999;
    
    /* Action Colors */
    --color-primary: #007bff;
    --color-secondary: #6c757d;
    --color-success: #28a745;
    --color-warning: #ffc107;
    --color-danger: #dc3545;
    --color-info: #17a2b8;
    
    /* Interactive Elements */
    --button-bg: #f8f9fa;
    --button-hover: #e9ecef;
    --button-active: #dee2e6;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    
    /* Animation */
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* ================== CANVAS BLOCKS ================== */

.canvas-block {
    position: relative;
    background: var(--background-primary);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    overflow: hidden;
    transition: all var(--transition-fast);
    cursor: pointer;
    min-height: 120px;
    display: flex;
    flex-direction: column;
}

.canvas-block:hover {
    border-color: var(--border-medium);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.canvas-block.editing {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.canvas-block.has-content {
    background: var(--background-primary);
}

.canvas-block.has-placeholder .block-content {
    opacity: 0.7;
}

/* ================== BLOCK HEADER ================== */

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--background-secondary);
    border-bottom: 1px solid var(--border-light);
    min-height: 40px;
}

.block-title {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.block-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

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

.block-action-btn {
    background: var(--button-bg);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
}

.block-action-btn:hover {
    background: var(--button-hover);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

.block-action-btn:active {
    background: var(--button-active);
    transform: translateY(1px);
}

.block-action-btn i {
    font-size: 10px;
}

/* ================== BLOCK CONTENT ================== */

.block-content {
    flex: 1;
    padding: 12px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-primary);
    background: transparent;
    min-height: 60px;
    overflow-y: auto;
    word-wrap: break-word;
}

.block-content-placeholder {
    color: var(--text-placeholder);
    font-style: italic;
    font-size: 12px;
    line-height: 1.3;
}

.block-content.has-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.block-content:not(.has-placeholder) {
    padding-top: 16px;
}

/* ================== USER PRESENCE AND STATUS ================== */

.user-presence {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
    pointer-events: none;
}

.user-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: bold;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: var(--shadow-sm);
}

.edit-status {
    position: absolute;
    bottom: 4px;
    left: 4px;
    padding: 2px 6px;
    background: var(--color-primary);
    color: white;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.canvas-block.editing .edit-status {
    opacity: 1;
}

/* ================== MOBILE ELEMENTS ================== */

.mobile-expand-btn {
    display: none;
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 12px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}

.mobile-expand-btn:hover {
    transform: scale(1.1);
}

.mobile-expand-btn:active {
    transform: scale(0.95);
}

/* ================== MODAL STYLES ================== */

.canvas-block-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn var(--transition-medium) ease-out;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--background-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalSlideIn var(--transition-medium) ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--background-secondary);
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.modal-close-btn:hover {
    background: var(--button-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.modal-body .expanded-content {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    background: var(--background-primary);
    color: var(--text-primary);
}

.modal-body .expanded-content:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    background: var(--background-secondary);
    border-top: 1px solid var(--border-light);
}

.modal-footer .btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.modal-footer .btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.modal-footer .btn-primary:hover {
    background: #0056b3;
    border-color: #0056b3;
}

.modal-footer .btn-secondary {
    background: var(--background-primary);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

.modal-footer .btn-secondary:hover {
    background: var(--button-hover);
}

/* ================== LOADING AND STATES ================== */

.canvas-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.canvas-loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-light);
    border-top: 2px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.canvas-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--color-danger);
    font-size: 14px;
}

/* ================== AI GENERATION INDICATORS ================== */

.ai-generation-indicator {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--color-info);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 10;
    animation: aiIndicatorPulse 2s ease-in-out infinite;
}

.ai-generation-indicator i {
    font-size: 10px;
}

.ai-generation-indicator small {
    opacity: 0.8;
    font-size: 9px;
}

.canvas-block.ai-generated {
    position: relative;
}

.canvas-block.ai-generated::before {
    content: '🤖';
    position: absolute;
    top: 6px;
    left: 6px;
    font-size: 12px;
    z-index: 5;
    opacity: 0.6;
}

/* ================== RESPONSIVE DESIGN ================== */

/* Tablet Layout */
@media (max-width: 1024px) {
    .canvas-visualization {
        padding: 6px;
        gap: 1px;
        min-height: 500px;
    }
    
    .block-header {
        padding: 6px 10px;
    }
    
    .block-title {
        font-size: 11px;
    }
    
    .block-content {
        padding: 10px;
        font-size: 12px;
    }
    
    .block-action-btn {
        padding: 3px 5px;
        min-width: 22px;
        height: 22px;
    }
}

/* Mobile Layout */
@media (max-width: 768px) {
    .canvas-visualization {
        height: auto;
        min-height: 400px;
        padding: 4px;
        display: block;
        overflow-y: auto;
    }
    
    .canvas-block {
        margin-bottom: 8px;
        min-height: 100px;
        cursor: default;
    }
    
    .canvas-block:last-child {
        margin-bottom: 0;
    }
    
    .block-actions {
        display: none;
    }
    
    .mobile-expand-btn {
        display: flex;
    }
    
    .block-header {
        padding: 8px 12px;
    }
    
    .block-title {
        font-size: 12px;
    }
    
    .block-content {
        padding: 12px;
        min-height: 50px;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 20px;
    }
    
    .modal-body .expanded-content {
        min-height: 150px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .canvas-visualization {
        padding: 2px;
        font-size: 13px;
    }
    
    .canvas-block {
        margin-bottom: 6px;
        border-radius: 4px;
    }
    
    .block-header {
        padding: 6px 8px;
        min-height: 36px;
    }
    
    .block-title {
        font-size: 11px;
    }
    
    .block-content {
        padding: 8px;
        font-size: 12px;
    }
    
    .mobile-expand-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
    
    .modal-content {
        width: 98%;
        border-radius: 8px;
    }
    
    .modal-header,
    .modal-footer {
        padding: 12px 16px;
    }
    
    .modal-body {
        padding: 16px;
    }
}

/* ================== ANIMATIONS ================== */

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

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes aiIndicatorPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* ================== ACCESSIBILITY ================== */

@media (prefers-reduced-motion: reduce) {
    .canvas-visualization,
    .canvas-block,
    .block-action-btn,
    .mobile-expand-btn,
    .modal-content,
    .ai-generation-indicator {
        transition: none;
        animation: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --border-light: #000000;
        --border-medium: #000000;
        --text-placeholder: #666666;
        --background-hover: #f0f0f0;
    }
    
    .canvas-block {
        border-width: 2px;
    }
    
    .canvas-block:hover {
        border-width: 3px;
    }
}

/* ================== PRINT STYLES ================== */

@media print {
    .canvas-visualization {
        height: auto;
        min-height: auto;
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    .canvas-block {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #333;
    }
    
    .block-actions,
    .mobile-expand-btn,
    .user-presence,
    .edit-status,
    .ai-generation-indicator {
        display: none !important;
    }
    
    .block-content {
        color: #000;
        background: #fff;
    }
    
    .block-title {
        color: #000;
        font-weight: bold;
    }
}

/* ================== FRAMEWORK-SPECIFIC OVERRIDES ================== */

/* These can be overridden by framework-specific CSS files */

.canvas-visualization[data-framework="bmc"] {
    /* BMC-specific base styles */
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 0.8fr;
}

/* BMC Block Grid Positioning */
.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="keyPartners"] {
    grid-area: 1 / 1 / 3 / 2;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="keyActivities"] {
    grid-area: 1 / 2 / 2 / 3;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="keyResources"] {
    grid-area: 2 / 2 / 3 / 3;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="valueProposition"] {
    grid-area: 1 / 3 / 3 / 4;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="customerRelationships"] {
    grid-area: 1 / 4 / 2 / 5;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="channels"] {
    grid-area: 2 / 4 / 3 / 5;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="customerSegments"] {
    grid-area: 1 / 5 / 3 / 6;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="costStructure"] {
    grid-area: 3 / 1 / 4 / 4;
}

.canvas-visualization[data-framework="bmc"] .canvas-block[data-section="revenueStreams"] {
    grid-area: 3 / 4 / 4 / 6;
}

.canvas-visualization[data-framework="swot"] {
    /* SWOT-specific base styles */
}

.canvas-visualization[data-framework="vpc"] {
    /* VPC-specific base styles */
}

.canvas-visualization[data-framework="porters"] {
    /* Porter's Forces-specific base styles */
}

.canvas-visualization[data-framework="pestele"] {
    /* PESTELE-specific base styles */
}

.canvas-visualization[data-framework="mckinsey7s"] {
    /* McKinsey 7S-specific base styles */
}

/* ================== BMC ATTRIBUTION ================== */

.canvas-attribution {
    grid-column: 1 / -1;
    background: var(--background-secondary);
    border-top: 1px solid var(--border-light);
    padding: 16px 20px;
    margin-top: 8px;
    border-radius: 0 0 8px 8px;
    text-align: center;
}

.attribution-text {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    line-height: 1.4;
}

.attribution-text i {
    color: var(--color-info);
    font-size: 14px;
}

.attribution-text a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.attribution-text a:hover {
    color: #0056b3;
    text-decoration: underline;
}

/* Mobile attribution styling */
@media (max-width: 768px) {
    .canvas-attribution {
        padding: 12px 16px;
        margin-top: 6px;
    }
    
    .attribution-text {
        font-size: 11px;
        flex-direction: column;
        gap: 4px;
        text-align: center;
    }
    
    .attribution-text i {
        font-size: 12px;
    }
}
