/**
 * Progress Matrix Visual Styles
 * ConstructVis-style Elevation Matrix rendering
 *
 * Phase 2 of PROGRESS_MATRIX_VISUAL_REDESIGN_PLAN.md
 * Created: 2026-01-06
 *
 * References:
 * - Section 3.1: Layout Structure
 * - Section 3.2: Color Scheme (Status Colors)
 * - Section 3.3: Trade Cell Design
 * - Section 3.4: Floor Slab Design
 * - Section 9.5: CSS Variables pattern from existing progress-matrix.css
 */

/* ============================================
   CSS Variables for Visual View
   Extends existing --pm-* variables
   ============================================ */
:root {
    /* Visual View specific variables */
    --pmv-floor-min-height: auto;        /* CHANGED: No min-height, floor shrinks to content */
    --pmv-floor-label-width: 80px;
    --pmv-trade-cell-size: 70px;
    --pmv-trade-cell-gap: 6px;           /* REDUCED: Tighter cell spacing */
    --pmv-slab-height: 20px;             /* REDUCED: Smaller slab bar */
    --pmv-foundation-height: 32px;       /* REDUCED: Smaller foundation */
    --pmv-border-radius: 8px;            /* REDUCED: Smaller radius */
    --pmv-transition-speed: 0.2s;

    /* Status Colors - Section 3.2 */
    --pmv-status-completed: #3b82f6;      /* blue-500 - SWAPPED per user request */
    --pmv-status-in-progress: #10b981;    /* emerald-500 - SWAPPED per user request */
    --pmv-status-delayed: #ef4444;        /* red-500 */
    --pmv-status-blocked: #f59e0b;        /* amber-500 */
    --pmv-status-not-started-bg: #f1f5f9; /* slate-100 */
    --pmv-status-not-started-text: #94a3b8; /* slate-400 */

    /* Floor Section Colors */
    --pmv-floor-bg: #ffffff;
    --pmv-floor-border: #e2e8f0;          /* slate-200 */
    --pmv-floor-label-bg: #f8fafc;        /* slate-50 */
    --pmv-roof-bg: #fef3c7;               /* amber-100 */
    --pmv-roof-border: #fcd34d;           /* amber-300 */

    /* Slab Colors */
    --pmv-slab-poured: #4ade80;           /* green-400 */
    --pmv-slab-pouring: #facc15;          /* yellow-400 */
    --pmv-slab-rebar: #9ca3af;            /* gray-400 */

    /* Foundation */
    --pmv-foundation-bg: #374151;         /* gray-700 */
    --pmv-foundation-text: #f9fafb;       /* gray-50 */
}

/* ============================================
   Main Container - Elevation Matrix
   Section 3.1: Layout Structure
   ============================================ */
.elevation-matrix {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: linear-gradient(180deg, #e0f2fe 0%, #f0f9ff 100%); /* Sky gradient */
    overflow: hidden;
}

.elevation-matrix-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 4px;           /* Top/bottom 8px, left/right 4px */
    display: flex;
    flex-direction: column;
    gap: 2px; /* Minimal gap between floors for building effect */
}

/* ============================================
   Floor Section
   Each floor row in the building visualization
   ============================================ */
.floor-section {
    display: flex;
    flex-direction: column;
    /* min-height removed - floor shrinks to content */
    background: var(--pmv-floor-bg);
    border: 1px solid var(--pmv-floor-border);
    border-radius: 6px;
    margin: 0 8px;              /* REDUCED: Less horizontal margin */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: box-shadow var(--pmv-transition-speed);
}

.floor-section:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Roof floor special styling */
.floor-section.roof {
    background: var(--pmv-roof-bg);
    border-color: var(--pmv-roof-border);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

/* ============================================
   Floor Label (Left side)
   ============================================ */
.floor-label {
    position: absolute;
    left: -90px;
    top: 50%;
    transform: translateY(-50%);
    width: var(--pmv-floor-label-width);
    text-align: center;
    background: var(--pmv-floor-label-bg);
    border: 1px solid var(--pmv-floor-border);
    border-radius: 8px;
    padding: 8px 4px;
}

.floor-label-type {
    font-size: 10px;
    color: #64748b; /* slate-500 */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.floor-label-number {
    font-size: 24px;
    font-weight: 700;
    color: #1e293b; /* slate-800 */
    line-height: 1;
}

/* Inline floor label (inside floor section) */
.floor-section-header {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-bottom: 1px solid var(--pmv-floor-border);
    background: var(--pmv-floor-label-bg);
    border-radius: 5px 5px 0 0;
}

.floor-section.roof .floor-section-header {
    border-top-left-radius: 19px;
    border-top-right-radius: 19px;
}

.floor-section-label {
    font-weight: 700;
    font-size: 16px;
    color: #1e293b;
    min-width: 80px;
}

/* Drilldown navigation in header - Notion Style Breadcrumb */
.drilldown-nav {
    flex: 1;
    display: flex;
    align-items: center;
    align-self: center;
    justify-content: center;
}

.drilldown-nav .breadcrumb-container {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    height: 18px !important;
    max-height: 18px !important;
    min-height: 0 !important;
    overflow: hidden;
    gap: 4px;
    background: #ffffff;
    border-radius: 4px;
    padding: 0 5px;
    border: 1px solid #e5e5e5;
}

.drilldown-nav .back-button {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    height: 16px;
    min-height: 0;
    gap: 4px;
    padding: 0 10px;
    margin: 0;
    background: transparent;
    color: #404040;
    border: none;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
}

.drilldown-nav .back-button:hover {
    background: #3b82f6;
    color: #ffffff;
}

.drilldown-nav .back-button svg {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
}

.drilldown-nav .breadcrumb-chevron {
    color: #d4d4d4;
    font-size: 14px;
    line-height: 1;
}

.drilldown-nav .drilldown-title {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    height: 16px;
    padding: 0 8px;
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: #171717;
    background: transparent;
    line-height: 1;
}

.floor-section-progress {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.floor-progress-label {
    font-size: 11px;
    font-weight: 500;
    color: #64748b;
}

.floor-progress-bar {
    width: 100px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.floor-progress-fill {
    height: 100%;
    background: var(--pmv-status-in-progress);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.floor-progress-text {
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    min-width: 40px;
}

/* ============================================
   Floor Content (Trade Grid Area)
   ============================================ */
.floor-content {
    padding: 8px 10px;          /* REDUCED: Less padding */
    display: flex;
    flex-direction: column;
}


/* ============================================
   Trade Grid
   Section 3.3: Trade Cell Design
   ============================================ */
.trade-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--pmv-trade-cell-gap);
    align-items: flex-start;
}

/* ============================================
   Trade Cell
   Section 3.3: Trade Cell Design
   Dimensions: 60-80px, border-radius 12px
   ============================================ */
.trade-cell {
    width: var(--pmv-trade-cell-size);
    min-height: var(--pmv-trade-cell-size);
    padding: 4px 2px;           /* Add padding for content */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--pmv-border-radius);
    cursor: pointer;
    transition: all var(--pmv-transition-speed);
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.trade-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

.trade-cell:active {
    transform: scale(0.98);
}

/* Trade cell icon (optional SVG) */
.trade-icon {
    font-size: 20px;
    margin-bottom: 4px;
    opacity: 0.9;
}

/* Trade cell progress text */
.trade-progress {
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

/* Trade cell name tooltip */
.trade-cell[title] {
    position: relative;
}

/* Trade name label - Title Case (not uppercase), allows 3 lines */
.trade-name {
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.1px;
    margin-top: 2px;
    max-width: calc(var(--pmv-trade-cell-size) - 4px);
    line-height: 1.2;
    text-align: center;
    /* Allow wrapping to 3 lines max (more space without task count) */
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    opacity: 0.95;
    /* NO text-transform - let JS handle Title Case formatting */
}

/* Trade count (number of tasks) - hidden when name is long */
.trade-count {
    font-size: 8px;
    opacity: 0.75;
    margin-top: 1px;
}

/* Hide task count when trade name wraps (takes 2 lines) */
.trade-cell:has(.trade-name) .trade-count {
    /* Let CSS handle visibility based on available space */
}

/* Leaf cell - SAME SIZE as trade-cell (70x70), no expansion */
/* Note: .leaf-cell class removed from HTML, all cells use .trade-cell */

/* Placeholder cell for vertical alignment (empty space when trade not on floor) */
.trade-cell-placeholder {
    background: transparent;
    border: none;
    cursor: default;
    pointer-events: none;
    /* Ensure placeholder maintains dimensions for alignment */
    visibility: hidden;
}

/* Ensure trade-cell placeholder has correct size */
.trade-cell.trade-cell-placeholder {
    width: var(--pmv-trade-cell-size);
    min-height: var(--pmv-trade-cell-size);
}

/* Ensure subtask-cell placeholder has correct size */
.subtask-cell.trade-cell-placeholder {
    width: 200px;
    min-height: 55px;
}

/* ============================================
   Status Color Classes
   Section 3.2: Color Scheme
   ============================================ */
.status-completed {
    background: var(--pmv-status-completed);
    color: #ffffff;
}

.status-completed .trade-icon,
.status-completed .trade-progress {
    color: #ffffff;
}

.status-in-progress {
    background: var(--pmv-status-in-progress);
    color: #ffffff;
}

.status-in-progress .trade-icon,
.status-in-progress .trade-progress {
    color: #ffffff;
}

.status-delayed {
    background: var(--pmv-status-delayed);
    color: #ffffff;
}

.status-delayed .trade-icon,
.status-delayed .trade-progress {
    color: #ffffff;
}

/* Pulsing animation for delayed items */
.status-delayed {
    animation: pulse-delayed 2s ease-in-out infinite;
}

@keyframes pulse-delayed {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

.status-blocked {
    background: var(--pmv-status-blocked);
    color: #ffffff;
}

.status-blocked .trade-icon,
.status-blocked .trade-progress {
    color: #ffffff;
}

.status-not-started {
    background: var(--pmv-status-not-started-bg);
    color: var(--pmv-status-not-started-text);
    border: 1px dashed #cbd5e1;
}

.status-not-started .trade-icon,
.status-not-started .trade-progress {
    color: var(--pmv-status-not-started-text);
}

/* ============================================
   Sub-Task Cells (Drill-down view)
   Design: Option 2 - Horizontal Layout + Duration
   ============================================ */
.subtask-cell {
    width: 200px;
    min-height: 55px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--pmv-transition-speed);
}

.subtask-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Info section (name + duration) on left */
.subtask-info {
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

.subtask-name {
    font-size: 13px;
    font-weight: 400;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.subtask-duration {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.85;
    margin-top: 2px;
}

/* Large percentage on right */
.subtask-percent {
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Delay indicator styling */
.subtask-name .delay-indicator {
    margin-right: 4px;
}

/* Not started subtask cells - black text */
.subtask-cell.status-not-started {
    color: #1e293b;
}
.subtask-cell.status-not-started .subtask-name,
.subtask-cell.status-not-started .subtask-duration,
.subtask-cell.status-not-started .subtask-percent {
    color: #1e293b;
}

.no-subtasks {
    padding: 20px;
    text-align: center;
    color: #64748b;
    font-size: 13px;
    font-style: italic;
}

/* ============================================
   Roof Equipment Visualization
   ============================================ */
.roof-equipment {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    justify-content: center;
}

.hvac-unit {
    width: 40px;
    height: 30px;
    background: linear-gradient(180deg, #94a3b8 0%, #64748b 100%);
    border-radius: 4px;
    position: relative;
}

.hvac-unit::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 8px;
    background: #475569;
    border-radius: 2px 2px 0 0;
}

.vent-pipe {
    width: 12px;
    height: 40px;
    background: linear-gradient(180deg, #cbd5e1 0%, #94a3b8 100%);
    border-radius: 2px;
}

.exhaust-fan {
    width: 24px;
    height: 24px;
    background: #64748b;
    border-radius: 50%;
    position: relative;
}

.exhaust-fan::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: #334155;
    border-radius: 50%;
}

/* ============================================
   Slab Bar
   Section 3.4: Floor Slab Design
   ============================================ */
.slab-bar {
    height: var(--pmv-slab-height);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 7px 7px;
    position: relative;
    overflow: hidden;
}

.floor-section.roof .slab-bar {
    border-radius: 0;
}

.slab-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 1;
}

/* Slab status: Poured (100%) */
.slab-poured {
    background: linear-gradient(90deg, var(--pmv-slab-poured) 0%, #22c55e 100%);
    color: #ffffff;
}

/* Slab status: Pouring (1-99%) */
.slab-pouring {
    background: linear-gradient(90deg, var(--pmv-slab-poured) var(--slab-progress, 50%), var(--pmv-slab-rebar) var(--slab-progress, 50%));
    color: #1f2937;
}

/* Slab status: Rebar/Not Started (0%) */
.slab-rebar {
    background: repeating-linear-gradient(
        45deg,
        var(--pmv-slab-rebar),
        var(--pmv-slab-rebar) 2px,
        #a1a1aa 2px,
        #a1a1aa 4px
    );
    color: #374151;
}

/* ============================================
   Foundation Bar
   ============================================ */
.foundation-bar {
    height: var(--pmv-foundation-height);
    background: var(--pmv-foundation-bg);
    color: var(--pmv-foundation-text);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 20px 20px;
    border-radius: 0 0 8px 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ============================================
   View Toggle Button (Table/Visual switch)
   ============================================ */
.view-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}

.view-toggle-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    border-radius: 4px;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    transition: all var(--pmv-transition-speed);
}

.view-toggle-btn:hover {
    color: #334155;
}

.view-toggle-btn.active {
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Animations
   ============================================ */

/* Fade in animation for floors */
@keyframes floor-slide-in {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.floor-section {
    animation: floor-slide-in 0.3s ease-out;
    animation-fill-mode: both;
}

/* Staggered animation for floors */
.floor-section:nth-child(1) { animation-delay: 0ms; }
.floor-section:nth-child(2) { animation-delay: 50ms; }
.floor-section:nth-child(3) { animation-delay: 100ms; }
.floor-section:nth-child(4) { animation-delay: 150ms; }
.floor-section:nth-child(5) { animation-delay: 200ms; }
.floor-section:nth-child(6) { animation-delay: 250ms; }
.floor-section:nth-child(7) { animation-delay: 300ms; }
.floor-section:nth-child(8) { animation-delay: 350ms; }
.floor-section:nth-child(9) { animation-delay: 400ms; }
.floor-section:nth-child(10) { animation-delay: 450ms; }

/* Trade cell pop animation */
@keyframes trade-pop {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.trade-cell {
    animation: trade-pop 0.2s ease-out;
    animation-fill-mode: both;
}


/* Progress fill animation */
@keyframes progress-fill {
    from {
        width: 0;
    }
}

.floor-progress-fill,
.subtask-progress-fill {
    animation: progress-fill 0.5s ease-out;
}

/* ============================================
   Loading State
   ============================================ */
.elevation-matrix-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
}

.elevation-matrix-loading .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--pmv-status-in-progress);
    border-radius: 50%;
    animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.elevation-matrix-loading .loading-text {
    font-size: 14px;
    color: #64748b;
}

/* ============================================
   Empty State
   ============================================ */
.elevation-matrix-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: #64748b;
}

.elevation-matrix-empty-icon {
    font-size: 48px;
    opacity: 0.5;
}

.elevation-matrix-empty-text {
    font-size: 14px;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    :root {
        --pmv-trade-cell-size: 56px;
        --pmv-trade-cell-gap: 6px;
        --pmv-floor-min-height: 100px;
    }

    .floor-section {
        margin: 0 10px;
    }

    .elevation-matrix-scroll {
        padding: 10px 4px;
    }

    .trade-progress {
        font-size: 12px;
    }

    .trade-name {
        display: none;
    }

    .floor-section-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .floor-section-progress {
        margin-left: 0;
        width: 100%;
    }

    .floor-progress-bar {
        flex: 1;
    }
}

/* ============================================
   Scrollbar Styling (matches table view)
   ============================================ */
.elevation-matrix-scroll::-webkit-scrollbar {
    width: 12px;
}

.elevation-matrix-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 6px;
}

.elevation-matrix-scroll::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.4);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.elevation-matrix-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.6);
    background-clip: content-box;
}

/* Firefox scrollbar */
.elevation-matrix-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .elevation-matrix {
        background: white;
    }

    .floor-section {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }

    .trade-cell {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .status-completed { background: #10b981 !important; }
    .status-in-progress { background: #3b82f6 !important; }
    .status-delayed { background: #ef4444 !important; }
    .status-blocked { background: #f59e0b !important; }
    .status-not-started { background: #f1f5f9 !important; }

    /* Disable animations for print */
    * {
        animation: none !important;
    }
}
