/**
 * Shop Floor Enhanced Styles - FINAL LAYOUT ENFORCEMENT
 * File: assets/css/shop-floor-enhanced.css
 *
 * FIX: Stabilized calendar navigation, fixed bleed/stacking issues, and restored calendar grid visibility.
 */

/* === BASE STYLES === */
.shop-floor-enhanced {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh !important; /* CRITICAL: Force height */
    padding: 20px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: none !important; /* Neutralize max-width rules from themes/Elementor */
}

/* === HEADER === */
.shop-floor-header {
    background: white;
    padding: 25px 40px;
    border-radius: 15px;
    margin-bottom: 25px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideDown 0.5s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.shop-floor-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

.shop-floor-title h1 {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.shop-floor-title .live-indicator {
    width: 12px;
    height: 12px;
    background: #27ae60;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

.shop-floor-meta {
    display: flex;
    gap: 30px;
    align-items: center;
    /* FIX: Ensure meta items are visible, adjust padding if necessary */
    padding-top: 5px; 
}

.meta-item {
    text-align: center;
}

.meta-label {
    font-size: 12px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.meta-value {
    font-size: 24px;
    font-weight: 700;
    color: #2c3e50;
}

.clock {
    font-size: 28px;
    font-weight: 700;
    color: #667eea;
    font-variant-numeric: tabular-nums;
}

/* === CONTROLS === */
.shop-floor-controls {
    background: white;
    padding: 20px 30px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-switcher {
    display: flex;
    gap: 10px;
    background: #f8f9fa;
    padding: 5px;
    border-radius: 8px;
}

.view-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: #7f8c8d;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-btn:hover {
    color: #2c3e50;
    background: rgba(102, 126, 234, 0.1);
}

.view-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.view-filters {
    display: flex;
    gap: 15px;
    align-items: center;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-label {
    font-size: 11px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.filter-select {
    padding: 8px 15px;
    border: 2px solid #ecf0f1;
    border-radius: 6px;
    font-size: 14px;
    color: #2c3e50;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filter-select:hover,
.filter-select:focus {
    border-color: #667eea;
    outline: none;
}

.refresh-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.refresh-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* === GRID VIEW (PROJECTS) === */
#grid-view {
    /* display: block !important; <--- REMOVED: Managed by .view-container.view-active */
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: none !important;
}

.projects-grid {
    display: flex !important; /* CRITICAL: Use flexbox for horizontal flow */
    flex-wrap: wrap !important; 
    gap: 20px !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    list-style: none !important;
}

.job-card {
    /* Set flex basis for responsive column layout (3 columns by default) */
    flex: 0 0 calc(33.333% - 14px); 
    min-width: 350px; 

    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    margin: 0; /* Reset margins */
}

.job-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.job-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.job-card:hover::before {
    transform: scaleY(1);
}

.job-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.job-title {
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0 0 5px 0;
}

.job-client {
    font-size: 13px;
    color: #7f8c8d;
}

.job-status {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

.status-in-progress {
    background: #d1ecf1;
    color: #0c5460;
}

.status-completed {
    background: #d4edda;
    color: #155724;
}

.status-on-hold {
    background: #f8d7da;
    color: #721c24;
}

.job-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 15px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 11px;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.detail-value {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}

.progress-section {
    margin-top: 15px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-label {
    font-size: 12px;
    color: #7f8c8d;
    font-weight: 600;
}

.progress-percentage {
    font-size: 14px;
    font-weight: 700;
    color: #667eea;
}

.progress-bar {
    height: 8px;
    background: #ecf0f1;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    transition: width 0.5s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.cut-plan-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #e8f5e9;
    color: #2e7d32;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 10px;
}

/* === CALENDAR VIEW === */
#calendar-view {
    /* display: block !important; <--- REMOVED: Managed by .view-container.view-active */
    width: 100%;
    padding: 0 !important;
    margin: 0 !important;
}

/* FIX: Add Flexbox to main view container to manage header/content stacking */
#calendar-view.view-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden; /* Contains the scrollable sub-view */
}


.calendar-view-switcher {
    /* NEW RULE: Ensure switcher is always visible and contained within the #calendar-view */
    flex-shrink: 0;
    padding: 0 20px; 
    margin-bottom: 20px;
}

.calendar-sub-view {
    /* NEW RULE: Container for Month/Week specific logic (Header/Grid) */
    display: none; 
    /* FIX: Set internal content to stack vertically and take up space */
    flex-direction: column;
    flex: 1; /* CRITICAL: Must be flex: 1 to fill parent #calendar-view */
    min-height: 0;
    overflow: hidden;
    padding: 0 20px 20px 20px; /* Only top/bottom padding */
}

.calendar-sub-view.view-active {
    display: flex;
    flex: 1; /* Fills remaining space */
    overflow-y: auto; /* Allow scroll if the calendar grid gets too long */
}

.calendar-view-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    animation: fadeIn 0.5s ease;
}

.calendar-header {
    /* RE-STABILIZE: Ensure header elements are side-by-side and don't wrap prematurely */
    flex-shrink: 0;
    background: white; /* Changed from colored gradient to white/transparent to avoid bleed issues */
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.calendar-nav {
    display: flex;
    gap: 15px;
    align-items: center;
}

.calendar-nav button {
    padding: 8px 15px;
    border: none;
    background: #f8f9fa;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: #2c3e50;
    transition: all 0.3s ease;
}

.calendar-nav button:hover {
    background: #667eea;
    color: white;
}

.calendar-month {
    font-size: 20px; /* Reduced size slightly for stacking prevention */
    font-weight: 700;
    color: #2c3e50;
    margin: 0 10px;
}

/* 💥 FIX: Isolate Calendar Grid Container for Vertical Space Management 💥 */
.calendar-grid-container {
    display: flex;
    flex-direction: column;
    flex: 1; /* CRITICAL: Must take up all vertical space */
    min-height: 0;
    overflow: hidden;
}

.calendar-grid {
    display: grid !important; /* CRITICAL: Force display grid */
    grid-template-columns: repeat(7, 1fr) !important;
    /* FIX: Set flexible grid rows with a minimum size */
    grid-auto-rows: minmax(150px, 1fr); /* Min height 150px or equal division */
    gap: 1px !important; /* Gap between cells */
    flex: 1; /* CRITICAL: Fills remaining vertical space in parent */
    background: #ecf0f1;
    overflow: hidden;
}

.calendar-day-names {
    /* RE-STABILIZE */
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    flex-shrink: 0;
    background: #2c3e50;
    color: white;
    font-weight: 600;
    font-size: 14px;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}

.calendar-day-name {
    padding: 10px;
    text-align: center;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}
.calendar-day-name:last-child {
    border-right: none;
}


.calendar-day {
    min-height: 0; /* Let grid-auto-rows manage height */
    background: #f8f9fa;
    padding: 10px;
    transition: all 0.3s ease;
    display: block !important; /* CRITICAL: Reset internal display if necessary */
    border: none;
}

.calendar-day:hover {
    background: #ecf0f1;
}

.calendar-day.today {
    background: #e3f2fd;
    border: 2px solid #667eea;
}

.calendar-day.today .day-number {
    color: #667eea;
}

.calendar-day.other-month {
    opacity: 0.4;
}

.day-number {
    font-size: 14px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 8px;
}

.day-jobs {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.calendar-job {
    padding: 4px 8px;
    background: white;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    border-left: 3px solid #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
}

.calendar-job:hover {
    transform: translateX(3px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* === SHOP VIEW (KANBAN) === */
#shop-view {
    /* display: block !important; <--- REMOVED: Managed by .view-container.view-active */
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
}

.shop-view .kanban-board {
    display: flex !important; /* CRITICAL: Use flexbox for horizontal columns */
    gap: 25px !important;
    width: 100%;
    min-height: 600px;
    overflow-x: auto; /* Allow horizontal scrolling if columns overflow */
    padding-bottom: 20px;
}

.shop-station {
    /* CRITICAL: Allow stations to shrink down to min-width, and not grow by default */
    flex: 0 0 400px; 
    min-width: 400px; /* Ensure wide enough column base */
    
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
}

.shop-station::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}

.station-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.station-name {
    font-size: 20px;
    font-weight: 700;
    color: #2c3e50;
}

.station-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.station-status.active {
    background: #d4edda;
    color: #155724;
}

.station-status.idle {
    background: #fff3cd;
    color: #856404;
}

.station-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.station-jobs {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto; /* Enable scrolling within columns */
    padding-right: 10px; /* Space for scrollbar */
}

.station-job {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    cursor: pointer;
    transition: all 0.3s ease;
}

.station-job:hover {
    background: #ecf0f1;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.station-job-title {
    font-size: 15px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 8px;
}

.station-job-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #7f8c8d;
}

/* === CUT PLAN MODAL (Styles remain the same) === */
.cut-plan-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 999999;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.cut-plan-modal.active {
    display: flex;
}

.cut-plan-content {
    background: white;
    border-radius: 15px;
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.cut-plan-header {
    padding: 25px 30px;
    border-bottom: 2px solid #ecf0f1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 15px 15px 0 0;
}

.cut-plan-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
}

.cut-plan-close {
    width: 35px;
    height: 35px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.cut-plan-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.cut-plan-body {
    padding: 30px;
}

.cut-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    background: #ecf0f1;
    transform: translateY(-3px);
}

.stat-label {
    font-size: 12px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #2c3e50;
}

.stat-value.highlight {
    color: #667eea;
}

.cut-layout {
    margin-top: 30px;
}

.cut-layout h3 {
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 20px;
}

.stock-piece {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    border-left: 4px solid #667eea;
}

.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.stock-title {
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
}

.cuts-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.cut-item {
    background: white;
    padding: 12px;
    border-radius: 6px;
    border: 2px solid #ecf0f1;
    text-align: center;
    transition: all 0.3s ease;
}

.cut-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.cut-length {
    font-size: 16px;
    font-weight: 700;
    color: #667eea;
}

.cut-label {
    font-size: 11px;
    color: #7f8c8d;
    margin-top: 4px;
}

.waste-indicator {
    margin-top: 15px;
    padding: 12px;
    background: #fff3cd;
    border-radius: 6px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #856404;
}

/* === LOADING & EMPTY STATES === */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #ecf0f1;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 20px;
    color: #2c3e50;
    margin-bottom: 10px;
}

/* === RESPONSIVE DESIGN (Adjusted for Flexbox) === */
@media (max-width: 1200px) {
    .job-card {
        /* 2 Columns: 50% width minus half the gap (10px) */
        flex: 0 0 calc(50% - 10px); 
        min-width: 300px;
    }
    
    .shop-station {
        min-width: 350px; /* Reduced minimum width */
    }
}

@media (max-width: 768px) {
    .job-card {
        /* 1 Column: Full width */
        flex: 0 0 100%;
    }
    
    /* CRITICAL: Stack Kanban columns vertically on mobile */
    .shop-view .kanban-board {
        flex-direction: column !important;
        overflow-x: hidden; /* Prevent horizontal scroll */
        height: auto;
    }
    
    .shop-station {
        width: 100%;
        min-width: auto;
        flex: 1 1 auto;
    }
    
    .calendar-grid {
        gap: 5px !important;
    }
}

/* VIEW TOGGLE FIX - FINAL ENFORCEMENT */
/* Assumes all view containers (e.g., #grid-view, #shop-view) have the class .view-container */
.view-container {
    display: none !important; /* Hide all views by default */
}

.view-container.view-active {
    display: block !important; /* Only show the currently active view */
}
