/* ═══════════════════════════════════════════
   Week Calendar Component Styles
   Outlook-style grid layout for schedule view
   ═══════════════════════════════════════════ */

.wkcal {
    --ppmin: 0.75px;
    --slot-mins: 60;
    --lane-gap: 2px;
    --event-pad: 4px;
    --min-mins: 15;
    --hour-label-width: 80px;
    --header-height: 64px;
    --allday-height: 40px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    overflow: hidden;
}

/* --- Header --- */
.wkcal-header {
    height: var(--header-height);
    display: grid;
    grid-template-columns: var(--hour-label-width) repeat(7, 1fr);
    background: #f8f9fa;
    border-bottom: 2px solid #e1e5e9;
    position: sticky;
    top: 0;
    z-index: 30;
}

.wkcal-time-header {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #495057;
    border-right: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.wkcal-day-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #e1e5e9;
    padding: 8px;
    font-weight: 600;
    color: #495057;
    background: #f8f9fa;
}

.wkcal-day-header:last-child { border-right: none; }

.wkcal-day-name { font-size: 15px; margin-bottom: 2px; }
.wkcal-day-date { font-size: 13px; color: #6c757d; }

/* --- Body Grid --- */
.wkcal-body {
    display: grid;
    grid-template-columns: var(--hour-label-width) 1fr;
    position: relative;
}

.wkcal-gutter {
    background: #f8f9fa;
    border-right: 1px solid #e1e5e9;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.wkcal-gutter-allday-spacer {
    border-bottom: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.wkcal-time-labels { position: relative; flex: 1; }
.wkcal-grid { display: flex; flex-direction: column; }

/* --- All-Day Row --- */
.wkcal-allday {
    min-height: var(--allday-height);
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid #e1e5e9;
    background: #fafbfc;
}

.wkcal-allday-cell {
    border-right: 1px solid #e1e5e9;
    padding: 4px;
    position: relative;
    min-height: var(--allday-height);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wkcal-allday-cell:last-child { border-right: none; }

/* --- Hours Grid --- */
.wkcal-hours {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    height: calc(16 * 60 * var(--ppmin) + 200px);
    position: relative;
    background: white;
}

.wkcal-day {
    position: relative;
    background-image: repeating-linear-gradient(
        to bottom,
        #e1e5e9 0, #e1e5e9 1px,
        transparent 1px,
        transparent calc(var(--ppmin) * var(--slot-mins))
    );
    background-position: 0 calc(30 * var(--ppmin));
    border-right: 1px solid #e1e5e9;
    min-height: calc(16 * 60 * var(--ppmin) + 200px);
}

.wkcal-day:last-child { border-right: none; }

/* --- Time Labels --- */
.wkcal-time-label {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #6c757d;
    font-weight: 500;
    background: #f8f9fa;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
}

.wkcal-time-label.hour-label { font-weight: 600; color: #495057; }

/* --- Shift Events --- */
.wkcal-event {
    position: absolute;
    box-sizing: border-box;
    border-radius: 6px;
    padding: var(--event-pad);
    background: #2563eb;
    color: white;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    z-index: 10;
    margin-right: var(--lane-gap);
    cursor: default;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.calendar-editable .wkcal-event { cursor: pointer; }

.calendar-editable .wkcal-event:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transform: translateY(-1px);
    z-index: 20;
}

.wkcal-event-title {
    font-weight: 700;
    margin-bottom: 2px;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    font-size: 14px;
}

.wkcal-event-time {
    font-size: 14px;
    opacity: 0.9;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.wkcal-event-hours {
    font-size: 13px;
    font-weight: 600;
    opacity: 0.9;
    margin-top: 2px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.wkcal-event-branch {
    font-size: 9px;
    opacity: 0.9;
    font-style: italic;
    margin-top: 2px;
}

/* Cross-branch styling */
.wkcal-event.cross-branch {
    position: relative;
    border: 2px dashed rgba(0, 0, 0, 0.3) !important;
    opacity: 0.85;
}

.wkcal-event.cross-branch::before {
    content: "\01F500";
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 12px;
}

/* Unfilled shift styling */
.wkcal-event-unfilled {
    background: #fff5f5 !important;
    background-image: repeating-linear-gradient(
        45deg, transparent, transparent 10px,
        rgba(220, 53, 69, 0.05) 10px, rgba(220, 53, 69, 0.05) 20px
    ) !important;
    border: 2px solid #dc3545 !important;
    color: #dc3545 !important;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.3) !important;
}

.wkcal-event-unfilled:hover {
    box-shadow: 0 3px 10px rgba(220, 53, 69, 0.4) !important;
    border-color: #c82333 !important;
    transform: translateY(-1px);
}

.wkcal-event-unfilled .wkcal-event-title,
.wkcal-event-unfilled .wkcal-event-time,
.wkcal-event-unfilled .wkcal-event-hours {
    color: #dc3545 !important;
    text-shadow: none !important;
}

/* --- Unpublished shift indicator --- */
.wkcal-event.shift-unpublished {
    outline: 2px dashed rgba(255, 255, 255, 0.85);
    outline-offset: -3px;
}

.shift-unpublished-badge {
    position: absolute;
    top: 3px;
    right: 4px;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    border-radius: 3px;
    padding: 1px 3px;
    line-height: 1.4;
    pointer-events: none;
}

/* --- Staffing Slots --- */
.wkcal-slot {
    position: absolute;
    box-sizing: border-box;
    border: 2px dashed #007bff;
    border-radius: 6px;
    background: rgba(0, 123, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    padding: 4px;
    color: #007bff;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    margin-right: var(--lane-gap);
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

.wkcal-slot:hover {
    background: rgba(0, 123, 255, 0.15);
    border-style: solid;
    transform: scale(1.02);
}

.wkcal-slot.drop-target {
    background: rgba(76, 175, 80, 0.3) !important;
    border: 3px solid #4caf50 !important;
    border-style: solid !important;
    transform: scale(1.05);
}

.slot-hours { font-size: 10px; font-weight: 600; opacity: 0.8; margin-top: 1px; }

/* Reserved slot */
.wkcal-slot-reserved {
    border-color: #ffc107 !important;
    background: rgba(255, 193, 7, 0.1) !important;
    border-width: 2px;
    border-style: solid;
}

.wkcal-slot-reserved:hover {
    background: rgba(255, 193, 7, 0.2) !important;
    border-color: #f57c00 !important;
}

.slot-reservation-indicator { position: absolute; top: 2px; right: 4px; color: #f57c00; font-size: 12px; z-index: 1; }
.slot-reservation-indicator i { text-shadow: 0 1px 2px rgba(255,255,255,0.8); }

.wkcal-slot-reserved[data-reserved="true"]::after {
    content: attr(title);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.wkcal-slot-reserved[data-reserved="true"]:hover::after { opacity: 1; }

/* Nice-to-have slot */
.wkcal-slot-nice-to-have {
    border-color: #6c757d !important;
    background: rgba(108, 117, 125, 0.05) !important;
    border-width: 2px;
    border-style: dotted;
    opacity: 0.7;
}

.wkcal-slot-nice-to-have:hover {
    background: rgba(108, 117, 125, 0.15) !important;
    border-color: #495057 !important;
    opacity: 1;
}

/* --- Absence & Note Indicators --- */
.absence-container { display: flex; flex-direction: column; gap: 2px; }

.absence-item {
    display: flex;
    align-items: center;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 10px;
    color: white;
    font-weight: 600;
    min-height: 18px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.absence-item i { margin-right: 4px; font-size: 11px; }

.absence-details {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.day-note-container { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }

.day-note {
    display: flex;
    align-items: center;
    padding: 4px 6px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    font-size: 12px;
    color: #856404;
    cursor: default;
    max-width: 100%;
}

.day-note i { margin-right: 4px; font-size: 13px; }
.note-preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.add-note-btn { font-size: 11px; padding: 2px 4px; opacity: 0; transition: opacity 0.2s ease; }
.calendar-editable .wkcal-allday-cell:hover .add-note-btn { opacity: 1; }

/* --- Public Holidays --- */
.public-holiday {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 2px;
}

.wkcal-holiday-event {
    position: absolute;
    background: #dc3545;
    color: white;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 15;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* --- Other Branch Work --- */
.other-branch-work-section {
    position: absolute;
    top: calc(16 * 60 * var(--ppmin));
    left: 0; right: 0; bottom: 0;
    background: rgba(248, 249, 250, 0.95);
    border-top: 2px solid #e1e5e9;
    padding: 6px 4px;
    overflow-y: auto;
}

.other-branch-work-item {
    border-radius: 4px;
    padding: 4px 6px;
    margin-bottom: 3px;
    font-size: 12px;
    line-height: 1.2;
    transition: all 0.2s ease;
    color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.2);
}

.other-branch-work-item:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.2); opacity: 0.9; }
.other-branch-work-name { font-weight: 600; color: white; margin-bottom: 1px; text-shadow: 0 1px 2px rgba(0,0,0,0.8); }
.other-branch-work-time { font-size: 11px; color: rgba(255,255,255,0.95); margin-bottom: 1px; text-shadow: 0 1px 2px rgba(0,0,0,0.8); }
.other-branch-work-branch { font-size: 13px; color: rgba(255,255,255,0.9); font-style: italic; font-weight: bold; text-shadow: 0 1px 2px rgba(0,0,0,0.8); }

.other-branch-work-label { position: absolute; top: calc(16 * 60 * var(--ppmin) + 10px); left: 0; right: 0; }
.other-branch-work-label div { font-size: 12px; font-weight: 600; color: #6c757d; text-align: center; padding: 4px; }

/* --- Drag & Drop States --- */
.calendar-editable.dragging-employee * { cursor: not-allowed !important; }

.calendar-editable.dragging-employee .wkcal-slot {
    cursor: copy !important;
    border-color: #4caf50 !important;
    background: rgba(76, 175, 80, 0.1) !important;
}

.wkcal-slot.drop-target { animation: wkcal-pulse 1.5s infinite; }

@keyframes wkcal-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* --- Accessibility --- */
.wkcal-event:focus { outline: 2px solid #0066cc; outline-offset: 2px; }
.wkcal-slot:focus { outline: 2px solid #007bff; outline-offset: 2px; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .wkcal { --ppmin: 0.6px; --hour-label-width: 60px; }
}

@media (max-width: 768px) {
    .wkcal { --ppmin: 0.7px; --hour-label-width: 50px; --header-height: 0px; }
    .wkcal-event { font-size: 12px; padding: 4px; }
    .wkcal-event-title { font-size: 13px; }
    .wkcal-event-time { font-size: 12px; }

    /* Single-day mobile view: only when JS has initialized (.mobile-day-ready) */
    .wkcal.mobile-day-ready .wkcal-header { display: none; }

    .wkcal.mobile-day-ready .wkcal-allday { grid-template-columns: 1fr; }
    .wkcal.mobile-day-ready .wkcal-hours { grid-template-columns: 1fr; }

    .wkcal.mobile-day-ready .wkcal-allday-cell,
    .wkcal.mobile-day-ready .wkcal-day-header,
    .wkcal.mobile-day-ready .wkcal-day { display: none; }

    .wkcal.mobile-day-ready .wkcal-allday-cell.mobile-day-active,
    .wkcal.mobile-day-ready .wkcal-day-header.mobile-day-active,
    .wkcal.mobile-day-ready .wkcal-day.mobile-day-active { display: block; }

    .wkcal.mobile-day-ready .wkcal-allday-cell.mobile-day-active { display: flex; }

    /* Better touch targets */
    .wkcal-slot { min-height: 44px; font-size: 13px; }
    .wkcal-event { min-height: 44px; }

    /* Wider events since we have full width */
    .wkcal-day.mobile-day-active { border-right: none; }
    .wkcal-allday-cell.mobile-day-active { border-right: none; }
}

/* --- Mobile Day Navigation Bar --- */
.mobile-day-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 8px 8px 0 0;
    padding: 8px 4px;
    margin-bottom: -1px;
    position: sticky;
    top: 0;
    z-index: 31;
}

.mobile-day-nav-btn {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 18px;
    color: #495057;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.mobile-day-nav-btn:active {
    background: #e9ecef;
    transform: scale(0.95);
}

.mobile-day-nav-title {
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    color: #212529;
    flex: 1;
    line-height: 1.3;
}

.mobile-day-nav-title .mobile-day-date {
    font-size: 13px;
    font-weight: 400;
    color: #6c757d;
}

.mobile-day-nav-title .mobile-day-today {
    font-size: 11px;
    color: #0d6efd;
    font-weight: 600;
}
