/**
 * Billboard Custom Calendar Matrix Styles
 * 
 * Provides a clean, responsive matrix layout for billboard reservations
 * Compatible with WordPress themes through scoped CSS
 * Enhanced with Google Calendar-style scrolling and drag interaction
 */

/* Calendar Container */
.bpcrm-calendar-container {
    max-width: 100%;
    margin: 0 auto;
    font-family: inherit;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

/* Calendar Controls */
.bpcrm-calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f9f9f9;
    border-bottom: 1px solid #ddd;
    flex-wrap: wrap;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.bpcrm-month-selector {
    display: flex;
    align-items: center;
    gap: 15px;
}

.bpcrm-current-month {
    font-weight: 600;
    font-size: 16px;
    min-width: 150px;
    text-align: center;
}

.bpcrm-view-controls {
    display: flex;
    gap: 5px;
}

/* Matrix Layout with Fixed Headers */
.bpcrm-calendar-matrix {
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: auto;
    background: white;
    position: relative;
    max-height: 600px; /* Allow scrolling for many billboards */
    scroll-behavior: smooth;
}

.bpcrm-matrix-wrapper {
    min-width: 100%;
    display: table;
    position: relative;
}

.bpcrm-matrix-header {
    display: table-row;
    background: #f5f5f5;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 50;
}

.bpcrm-matrix-header > div {
    display: table-cell;
    padding: 10px;
    border-bottom: 2px solid #ddd;
    border-right: 1px solid #ddd;
    text-align: center;
    vertical-align: middle;
    background: #f5f5f5;
}

.bpcrm-panel-header {
    min-width: 200px;
    text-align: left !important;
    background: #e9ecef;
    position: sticky;
    left: 0;
    z-index: 51;
    box-shadow: 2px 0 4px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s ease;
}

.bpcrm-day-header {
    min-width: 40px;
    font-size: 12px;
}

.bpcrm-day-header.weekend {
    background: #f8f9fa;
    color: #6c757d;
}

.bpcrm-matrix-body {
    display: table-row-group;
}

.bpcrm-panel-row {
    display: table-row;
}

.bpcrm-panel-row:nth-child(even) {
    background: #f9f9f9;
}

.bpcrm-panel-row:hover {
    background: #f0f8ff;
}

.bpcrm-panel-info {
    display: table-cell;
    padding: 15px;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
    min-width: 200px;
    background: white;
    position: sticky;
    left: 0;
    z-index: 10;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    transition: box-shadow 0.2s ease;
}

.bpcrm-panel-title {
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
}

.bpcrm-panel-address {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.bpcrm-panel-details {
    font-size: 11px;
    color: #888;
}

.bpcrm-panel-size, .bpcrm-panel-price {
    display: inline-block;
    margin-right: 10px;
    padding: 2px 6px;
    background: #e9ecef;
    border-radius: 3px;
}

.bpcrm-day-cell {
    display: table-cell;
    width: 40px;
    height: 40px;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    position: relative;
    vertical-align: middle;
    transition: all 0.15s ease;
    user-select: none;
    padding: 2px;
}

/* Day cell states */
.bpcrm-day-cell.available {
    background: #d4edda;
}

.bpcrm-day-cell.available:hover {
    background: #c3e6cb;
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Reserved cells - remove old styles, use only bars from frontend.css */
.bpcrm-day-cell.reserved {
    background: transparent !important;
    cursor: pointer;
    position: relative;
}

.bpcrm-day-cell.reserved:hover {
    background: transparent !important;
}

/* Hide old reserved indicators - but allow new bars from frontend.css */
.bpcrm-day-cell.reserved:not(.reservation-start)::before,
.bpcrm-day-cell.reserved::after {
    display: none !important;
}



.bpcrm-day-cell.past {
    background: #f8f9fa;
    color: #6c757d;
    cursor: not-allowed;
}

.bpcrm-day-cell.weekend {
    background: #e9ecef;
    color: #6c757d;
}

.bpcrm-day-cell.weekend.available {
    background: #e9f7ef;
    color: #155724;
}

/* Pending/cart items - remove old styles, use only bars from frontend.css */
.bpcrm-day-cell.pending {
    background: transparent !important;
    position: relative;
}

.bpcrm-day-cell.pending:hover {
    background: transparent !important;
}

/* Hide old pending indicators - but allow new bars from frontend.css */
.bpcrm-day-cell.pending:not(.cart-start)::before,
.bpcrm-day-cell.pending::after {
    display: none !important;
}

/* Ensure cart-start bars override any reserved styling */
.bpcrm-day-cell.pending.cart-start::before {
    display: flex !important;
}

/* Remove old multiple reservation styles - bars handle this now */

/* Enhanced Selection States - Google Calendar Style */
.bpcrm-day-cell.selected {
    background: #4285f4 !important;
    border: 2px solid #1a73e8;
    color: white;
    box-shadow: 0 2px 8px rgba(66, 133, 244, 0.4);
    z-index: 5;
    position: relative;
}

.bpcrm-day-cell.selecting {
    background: #a8d1ff !important;
    border: 1px solid #4285f4;
    color: #1a73e8;
    box-shadow: 0 1px 4px rgba(66, 133, 244, 0.3);
    z-index: 4;
    position: relative;
}

/* Smooth drag preview */
.bpcrm-day-cell.drag-preview {
    background: rgba(66, 133, 244, 0.2) !important;
    border: 1px dashed #4285f4;
    animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.5; }
    to { opacity: 1; }
}

/* Drag selection visual feedback */
.bpcrm-calendar-matrix.selecting {
    cursor: crosshair;
}

.bpcrm-calendar-matrix.selecting .bpcrm-day-cell:not(.reserved):not(.past):not(.pending) {
    transition: all 0.1s ease;
}

/* Selection range visual connection */
.bpcrm-day-cell.selecting:not(:last-child) {
    border-right: 2px solid #4285f4;
}

.bpcrm-day-cell.selecting:first-child {
    border-radius: 4px 0 0 4px;
}

.bpcrm-day-cell.selecting:last-child {
    border-radius: 0 4px 4px 0;
}

.bpcrm-day-cell.selecting:only-child {
    border-radius: 4px;
}

/* Enhanced selection state transitions */
.bpcrm-day-cell.selection-confirmed {
    transform: scale(1.02);
    transition: transform 0.2s ease;
}

.bpcrm-day-cell.selection-start {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
    border-left: 3px solid #1a73e8;
}

.bpcrm-day-cell.selection-end {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    border-right: 3px solid #1a73e8;
}

.bpcrm-day-cell.selection-middle {
    border-top: 2px solid #4285f4;
    border-bottom: 2px solid #4285f4;
}

.bpcrm-day-cell.selection-single {
    border-radius: 6px;
    border: 3px solid #1a73e8;
}

/* Smooth scrolling for matrix */
.bpcrm-calendar-matrix {
    scroll-behavior: smooth;
}

/* Enhanced sticky positioning with smooth shadow transitions */
.bpcrm-panel-header {
    transition: box-shadow 0.2s ease;
}

.bpcrm-panel-info {
    transition: box-shadow 0.2s ease;
}

.bpcrm-calendar-matrix:hover .bpcrm-panel-header {
    box-shadow: 3px 0 6px rgba(0,0,0,0.15);
}

.bpcrm-calendar-matrix:hover .bpcrm-panel-info {
    box-shadow: 3px 0 6px rgba(0,0,0,0.1);
}

/* Loading and no data states */
.bpcrm-matrix-loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.bpcrm-no-data {
    text-align: center;
    padding: 40px;
    color: #999;
    font-style: italic;
}

/* Legend */
.bpcrm-calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 12px;
}

.bpcrm-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.bpcrm-legend-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid #ccc;
}

.bpcrm-legend-color.available {
    background: #d4edda;
}

.bpcrm-legend-color.reserved {
    background: #f9f9f9;
    position: relative;
}

.bpcrm-legend-color.reserved::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    height: 3px;
    background: #dc3545;
    border-radius: 2px;
}



.bpcrm-legend-color.selected {
    background: #4285f4;
    border-color: #1a73e8;
}

.bpcrm-legend-color.pending {
    background: #f9f9f9;
    position: relative;
}

.bpcrm-legend-color.pending::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 2px;
    right: 2px;
    height: 3px;
    background: #ffc107;
    border-radius: 2px;
}

.bpcrm-legend-color.weekend {
    background: #e9ecef;
    border-color: #6c757d;
}

/* Selection modal */
.bpcrm-selection-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bpcrm-modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.bpcrm-modal-content h3 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.bpcrm-selection-details {
    margin: 20px 0;
}

.bpcrm-selection-details p {
    margin: 8px 0;
    color: #555;
}

.bpcrm-modal-actions {
    text-align: right;
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.bpcrm-modal-actions .button {
    margin-left: 10px;
}

/* Reservation Cart */
.bpcrm-reservation-cart {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
}

.bpcrm-reservation-cart h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: #333;
}

.bpcrm-cart-items {
    min-height: 60px;
    margin-bottom: 15px;
}

.bpcrm-cart-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    margin-bottom: 8px;
}

.bpcrm-cart-item-details {
    flex: 1;
}

.bpcrm-cart-item-details strong {
    display: block;
    margin-bottom: 4px;
    color: #333;
}

.bpcrm-cart-item-price {
    color: #0073aa;
    font-weight: 600;
}

.bpcrm-empty-cart {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 20px;
}

.bpcrm-cart-total {
    text-align: right;
    margin-bottom: 15px;
    font-size: 16px;
}

.bpcrm-cart-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Responsive Design */
@media (max-width: 768px) {
    .bpcrm-calendar-container {
        margin: 10px 0;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    .bpcrm-calendar-controls {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        padding: 10px 15px;
        gap: 10px;
    }
    
    .bpcrm-month-selector {
        justify-content: center;
        order: 1;
        margin-bottom: 10px;
    }

    .bpcrm-month-selector button {
        padding: 8px 12px;
        font-size: 14px;
        min-width: 80px;
    }

    .bpcrm-current-month {
        font-size: 18px;
        font-weight: 700;
        color: #333;
        min-width: 180px;
    }

    .bpcrm-view-controls {
        order: 2;
        justify-content: center;
    }
    
    .bpcrm-calendar-matrix {
        max-height: 70vh;
        overflow-x: auto;
        overflow-y: auto;
        border-radius: 0 0 8px 8px;
        /* Enable smooth scrolling */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    .bpcrm-panel-info {
        min-width: 110px;
        width: 110px;
        padding: 6px 8px;
        position: sticky;
        left: 0;
        background: white;
        border-right: 2px solid #ddd;
        z-index: 15;
    }
    
    .bpcrm-panel-title {
        font-size: 11px;
        font-weight: bold;
        line-height: 1.2;
        margin-bottom: 3px;
    }
    
    .bpcrm-panel-address {
        font-size: 9px;
        line-height: 1.1;
        margin-bottom: 3px;
        color: #666;
    }

    .bpcrm-panel-details {
        font-size: 8px;
    }

    .bpcrm-panel-size, .bpcrm-panel-price {
        font-size: 8px;
        padding: 1px 4px;
        margin: 1px 2px 0 0;
    }
    
    .bpcrm-day-cell {
        min-width: 36px;
        width: 36px;
        height: 45px;
        border-radius: 4px;
        /* Better touch targets */
        touch-action: manipulation;
    }

    .bpcrm-day-cell.available:hover {
        transform: scale(1.1);
        transition: transform 0.15s ease;
    }
    
    .bpcrm-day-header {
        min-width: 36px;
        width: 36px;
        padding: 6px 2px;
        font-size: 9px;
        font-weight: 600;
        position: sticky;
        top: 0;
        background: #f5f5f5;
        z-index: 10;
    }

    .bpcrm-day-number {
        font-size: 11px;
        font-weight: bold;
        color: #333;
    }

    .bpcrm-day-name {
        font-size: 8px;
        color: #666;
        text-transform: uppercase;
    }
    
    .bpcrm-calendar-legend {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        font-size: 10px;
        padding: 8px 10px;
        justify-content: center;
    }

    .bpcrm-legend-item {
        flex: 0 0 auto;
        text-align: center;
    }

    .bpcrm-legend-color {
        width: 14px;
        height: 14px;
        margin: 0 auto 2px;
    }
    
    .bpcrm-modal-content {
        padding: 15px;
        margin: 10px;
        border-radius: 12px;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .bpcrm-modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .bpcrm-modal-actions .button {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        border-radius: 8px;
    }

    /* Enhanced reservation bars for mobile */
    .bpcrm-day-cell.reserved.reservation-start::before,
    .bpcrm-day-cell.pending.cart-start::before {
        font-size: 8px;
        padding: 1px 4px;
        height: 60%;
        top: 20%;
        border-radius: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Touch-friendly bulk selection */
    .bpcrm-bulk-selection {
        margin: 8px;
        padding: 12px;
        border-radius: 12px;
    }
}

@media (max-width: 480px) {
    .bpcrm-calendar-container {
        margin: 5px 0;
        border-radius: 6px;
    }

    .bpcrm-calendar-controls {
        padding: 8px 10px;
        gap: 8px;
    }

    .bpcrm-current-month {
        font-size: 16px;
        min-width: 160px;
    }

    .bpcrm-month-selector button {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 60px;
    }

    .bpcrm-calendar-matrix {
        max-height: 65vh;
        border-radius: 0 0 6px 6px;
    }

    .bpcrm-panel-info {
        min-width: 85px;
        width: 85px;
        padding: 4px 5px;
    }

    .bpcrm-panel-title {
        font-size: 10px;
        line-height: 1.1;
        margin-bottom: 2px;
    }

    .bpcrm-panel-address {
        font-size: 8px;
        margin-bottom: 2px;
    }

    .bpcrm-panel-details {
        font-size: 7px;
    }

    .bpcrm-panel-size, .bpcrm-panel-price {
        font-size: 7px;
        padding: 1px 2px;
    }
    
    .bpcrm-day-cell {
        min-width: 32px;
        width: 32px;
        height: 40px;
        border-radius: 3px;
    }
    
    .bpcrm-day-header {
        min-width: 32px;
        width: 32px;
        padding: 4px 1px;
        font-size: 8px;
    }

    .bpcrm-day-number {
        font-size: 10px;
    }
    
    .bpcrm-day-name {
        display: none; /* Hide day names on very small screens */
    }

    .bpcrm-calendar-legend {
        flex-direction: column;
        gap: 6px;
        font-size: 9px;
        padding: 6px 8px;
    }

    .bpcrm-legend-item {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }

    .bpcrm-legend-color {
        width: 12px;
        height: 12px;
        margin: 0;
    }

    .bpcrm-modal-content {
        padding: 12px;
        margin: 8px;
        border-radius: 10px;
        max-height: 85vh;
    }

    .bpcrm-modal-actions .button {
        padding: 10px;
        font-size: 14px;
    }

    /* Smaller reservation bars for very small screens */
    .bpcrm-day-cell.reserved.reservation-start::before,
    .bpcrm-day-cell.pending.cart-start::before {
        font-size: 7px;
        padding: 1px 2px;
        height: 50%;
        top: 25%;
        border-radius: 2px;
    }

    /* Touch-optimized interactions */
    .bpcrm-day-cell {
        /* Larger touch area for easier selection */
        position: relative;
    }

    .bpcrm-day-cell::after {
        content: '';
        position: absolute;
        top: -4px;
        left: -4px;
        right: -4px;
        bottom: -4px;
        z-index: -1;
    }
}

/* Bulk Selection Feature */
.bpcrm-bulk-selection {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin: 10px 0;
    padding: 15px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bpcrm-bulk-content {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.bpcrm-bulk-instructions {
    font-size: 12px;
    color: #666;
    font-style: italic;
    margin: 0 5px;
}

.bpcrm-interval-primary {
    background: #4285f4 !important;
    color: white !important;
    border-color: #1a73e8 !important;
    font-weight: bold;
}

.bpcrm-bulk-text {
    font-weight: 600;
    color: #495057;
    margin-right: 10px;
    white-space: nowrap;
}

.bpcrm-bulk-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #ffffff;
    border: 2px solid #4285f4;
    border-radius: 6px;
    color: #4285f4;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.bpcrm-bulk-btn:hover {
    background: #4285f4;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(66, 133, 244, 0.3);
}

.bpcrm-bulk-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(66, 133, 244, 0.4);
}

.bpcrm-bulk-btn .dashicons {
    font-size: 14px;
    line-height: 1;
}

/* Different colors for different bulk actions */
.bpcrm-select-weekend {
    border-color: #28a745;
    color: #28a745;
}

.bpcrm-select-weekend:hover {
    background: #28a745;
    color: white;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.bpcrm-select-weekdays {
    border-color: #ffc107;
    color: #856404;
}

.bpcrm-select-weekdays:hover {
    background: #ffc107;
    color: #856404;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3);
}

/* Feedback message */
.bpcrm-bulk-feedback {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border: 1px solid #c3e6cb;
    border-radius: 6px;
    padding: 10px 15px;
    margin: 10px 0;
    color: #155724;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 6px rgba(40, 167, 69, 0.2);
    animation: slideDown 0.3s ease-out;
}

/* Desktop and large screen optimizations */
@media (min-width: 1200px) {
    .bpcrm-calendar-container {
        max-width: 1400px;
        margin: 0 auto;
    }

    .bpcrm-calendar-matrix {
        max-height: 80vh;
    }

    .bpcrm-panel-info {
        min-width: 200px;
        width: 200px;
        padding: 12px 15px;
    }

    .bpcrm-day-cell {
        min-width: 38px;
        width: 38px;
        height: 55px;
    }

    .bpcrm-day-header {
        min-width: 38px;
        width: 38px;
        padding: 8px 4px;
    }

    .bpcrm-calendar-legend {
        justify-content: center;
        gap: 20px;
        font-size: 13px;
    }
}

/* Landscape phone optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .bpcrm-calendar-matrix {
        max-height: 55vh;
    }

    .bpcrm-calendar-controls {
        padding: 6px 10px;
    }

    .bpcrm-current-month {
        font-size: 14px;
        min-width: 140px;
    }

    .bpcrm-month-selector button {
        padding: 6px 8px;
        font-size: 11px;
    }

    .bpcrm-calendar-legend {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        font-size: 9px;
        padding: 6px 8px;
    }

    .bpcrm-legend-item {
        flex: 0 0 auto;
        font-size: 9px;
    }
}

/* Responsive adjustments for bulk selection */
@media (max-width: 768px) {
    .bpcrm-bulk-content {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .bpcrm-bulk-text {
        text-align: center;
        margin-right: 0;
        margin-bottom: 5px;
    }
    
    .bpcrm-bulk-btn {
        justify-content: center;
        padding: 10px 16px;
    }
}

@media (max-width: 480px) {
    .bpcrm-bulk-selection {
        margin: 5px 0;
        padding: 10px 15px;
    }
    
    .bpcrm-bulk-btn {
        font-size: 11px;
        padding: 8px 12px;
    }
    
    .bpcrm-bulk-btn .dashicons {
        font-size: 12px;
    }
} 