/* =====================================================
   Calendar View (Google Calendar Style)
   ===================================================== */

.calendar-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: white;
    position: relative;
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid var(--slate-200);
    height: 100%;
    max-height: 100%;
}

/* --- Header Section --- */
.calendar-header {
    display: flex;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--slate-200);
    background: var(--slate-50);
    padding-right: 6px;
}

.calendar-corner {
    width: 60px;
    flex-shrink: 0;
    border-right: 1px solid var(--slate-200);
    background: var(--slate-50);
}

.calendar-header-staff-row {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.calendar-staff-header {
    flex: 1;
    min-width: 200px;
    padding: 8px 6px;
    border-right: 1px solid var(--slate-200);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: white;
}

.calendar-staff-header:last-child {
    border-right: none;
}

/* Horizontal row: avatar | name+role | partner btn */
.calendar-staff-header .staff-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.calendar-staff-header .avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.calendar-staff-header .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

.calendar-staff-header .me-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 9px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.calendar-staff-header .staff-header-info {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.calendar-staff-header .name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slate-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.2;
}

.calendar-staff-header .role {
    font-size: 0.6rem;
    color: var(--slate-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

/* Partner Toggle Button */
.partner-toggle-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--slate-300);
    transition: all 0.2s ease;
}

.partner-toggle-btn:hover {
    background: var(--slate-100);
    color: var(--warning);
    transform: scale(1.15);
}

.partner-toggle-btn.active {
    color: var(--warning);
}

/* Partner Column Highlight */
.calendar-staff-header.partner-column {
    background: #fffbeb;
    border-bottom: 2px solid #fbbf24;
}

/* Performance Mini-Bar in Header */
.calendar-perf-container {
    width: 100%;
    margin-top: 4px;
    padding: 0 4px;
}

.calendar-perf-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--slate-500);
    margin-bottom: 2px;
}

.calendar-perf-bar-bg {
    width: 100%;
    height: 4px;
    background: var(--slate-100);
    border-radius: 2px;
    overflow: hidden;
}

.calendar-perf-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}


/* --- Body Section --- */
.calendar-body-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    /* Enable horizontal scroll */
    position: relative;
    display: flex;
    padding-top: 25px;
    /* Add space above 08:00 without showing 07:00 */
    min-height: 0;
    height: 100%;
}

/* Time Sidebar */
.calendar-time-labels {
    width: 60px;
    flex-shrink: 0;
    background: var(--slate-50);
    border-right: 1px solid var(--slate-200);
    z-index: 30;
    /* Higher than task cards (10-20) */
    position: sticky;
    left: 0;
}

.time-slot-label {
    height: 80px;
    position: relative;
    font-size: 0.75rem;
    color: var(--slate-500);
    text-align: right;
    padding-right: 8px;
    border-bottom: 1px solid transparent;
}

.time-slot-label span {
    display: block;
    transform: translateY(-50%);
    position: relative;
    top: 0;
}

/* Grid Area */
.calendar-header {
    display: flex;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--slate-200);
    background: var(--slate-50);
    padding-right: 6px;
    position: sticky;
    /* Sticky Header Fix */
    top: 0;
    z-index: 40;
}

/* ... existing styles ... */

.checklist-time-log {
    font-size: 0.65rem;
    color: var(--slate-400);
    opacity: 0.7;
    margin-left: auto;
    padding-left: 8px;
}

.calendar-grid-area {
    flex: 1;
    display: flex;
    position: relative;
    min-height: 100%;
    /* Force full height */
    /* Horizontal lines for times */
    background-size: 100% 80px;
    /* Match hour height */
    background-image: linear-gradient(to bottom, var(--slate-200) 1px, transparent 1px);
    background-repeat: repeat-y;
    /* Ensure constant repeat */
}

/* Staff Column in Grid */
.calendar-staff-column {
    flex: 1;
    min-width: 200px;
    /* Match header width */
    border-right: 1px solid var(--slate-100);
    position: relative;
    height: 100%;
}

.calendar-staff-column:last-child {
    border-right: none;
}

/* Task Item (Absolute) */
.calendar-task-card {
    position: absolute;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: max(10px, 0.75rem);
    cursor: pointer;
    overflow: hidden;
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    line-height: 1.3;
    display: flex;
    flex-direction: column;
    min-height: 24px;
    border: 1px solid white;
    color: white;
    box-sizing: border-box;
    max-width: 100%;
}

.calendar-task-card:hover {
    /* z-index stay as is (stacked) - respecting visual overlap logic */
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
    /* Just a subtle lift instead of scale */
}

.calendar-task-card .task-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: max(10px, 0.75rem);
    color: white;
    /* Force white */
    margin-bottom: 2px;
}

.calendar-task-card .task-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 1px;
    color: rgba(255, 255, 255, 0.9);
    font-size: max(9px, 0.7rem);
    white-space: nowrap;
}

.calendar-task-card .task-meta svg {
    width: 10px;
    height: 10px;
    opacity: 0.9;
    color: white;
}

/* Categories - Solid Colors */
/* Jobdesk: Default fallback (overridden by status-specific classes below) */
.calendar-task-card.cat-Jobdesk {
    background: #94a3b8;
    /* slate-400 - default/fallback */
}

/* Point 5: Jobdesk Status-Based Colors (Utama) */
.calendar-task-card.cat-Jobdesk.jobdesk-status-todo {
    background: #94a3b8;
    /* slate-400 - Abu-abu Profesional */
}

.calendar-task-card.cat-Jobdesk.jobdesk-status-in-progress {
    background: #3b82f6;
    /* blue-500 - Biru Fokus */
}

.calendar-task-card.cat-Jobdesk.jobdesk-status-done {
    background: #10b981;
    /* emerald-500 - Hijau Terang */
    opacity: 1;
    /* Override the generic status-done opacity */
}

.calendar-task-card.cat-Tugas-Tambahan {
    background: #f59e0b;
    /* Amber */
}

.calendar-task-card.cat-Inisiatif {
    background: #0d9488;
    /* Teal Darker */
}

.calendar-task-card.cat-Request {
    background: #e11d48;
    /* Rose */
}

/* Done State - applies to non-Jobdesk categories */
.calendar-task-card.status-done {
    opacity: 0.6;
    background: #64748b;
    /* Slate 500 */
    text-decoration: none;
    /* Let title handle strike */
}

/* Jobdesk Done overrides the generic status-done */
.calendar-task-card.cat-Jobdesk.jobdesk-status-done.status-done {
    opacity: 1;
    background: #10b981;
    /* emerald-500 */
}

.calendar-task-card.status-done .task-title {
    text-decoration: line-through;
    color: rgba(255, 255, 255, 0.8);
}

/* Jobdesk Done title - no line-through for better readability but keep indicator */
.calendar-task-card.cat-Jobdesk.jobdesk-status-done .task-title {
    text-decoration: line-through;
    color: rgba(255, 255, 255, 0.9);
}

/* Status Badge Pill */
.task-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    font-size: max(8px, 0.6rem);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    width: fit-content;
    letter-spacing: 0.02em;
}

.task-status-badge.status-badge-todo {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.task-status-badge.status-badge-in-progress {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.task-status-badge.status-badge-done {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Compact Card - single line for very short tasks */
/* Point 3: Ensure text visibility at all zoom levels */
.calendar-task-card.compact-card {
    flex-direction: row;
    align-items: center;
    padding: 2px 6px;
    justify-content: center;
}

.calendar-task-card.compact-card .compact-title {
    font-size: max(9px, 0.65rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0;
    line-height: 1.3;
}

.btn-icon-danger {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #ef4444;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-danger:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

/* =====================================================
   Skeleton Loading
===================================================== */

@keyframes skeleton-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(90deg,
            var(--slate-200) 25%,
            var(--slate-100) 50%,
            var(--slate-200) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.sm {
    height: 10px;
    width: 60%;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-card {
    height: 60px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.skeleton-task-detail {
    padding: var(--space-4);
}

.skeleton-task-detail .skeleton-header {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.skeleton-task-detail .skeleton-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Inline loading for buttons */
.btn.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Loading overlay for sections */
.section-loading {
    position: relative;
    min-height: 100px;
}

.section-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 11;
}

/* Detail content loading overlay */
.task-detail-loading {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.task-detail-loading .skeleton-badge {
    display: flex;
    gap: var(--space-2);
}

.task-detail-loading .skeleton-badge>div {
    width: 80px;
    height: 24px;
}

.task-detail-loading .skeleton-title {
    height: 24px;
    width: 70%;
}

.task-detail-loading .skeleton-meta {
    height: 14px;
    width: 50%;
}

.task-detail-loading .skeleton-checklist {
    margin-top: var(--space-4);
}

.task-detail-loading .skeleton-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.task-detail-loading .skeleton-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.task-detail-loading .skeleton-item-text {
    height: 16px;
    flex: 1;
}

/* =====================================================
   Task List View
===================================================== */
.list-view-container {
    padding: var(--space-4);
    background: white;
    min-height: calc(100vh - 120px);
}

.list-view-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    background: var(--slate-50);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--slate-200);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-chip {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--slate-600);
    background: white;
    border: 1px solid var(--slate-200);
    cursor: pointer;
    transition: var(--transition-fast);
}

.filter-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#list-time-filter {
    padding: 6px 12px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--slate-300);
    font-size: 0.875rem;
    color: var(--slate-700);
    outline: none;
    cursor: pointer;
}

#list-time-filter:focus {
    border-color: var(--primary);
}

.list-group {
    margin-bottom: var(--space-6);
}

.list-group h3 {
    font-size: 1rem;
    color: var(--slate-700);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--slate-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-group h3 span.count {
    font-size: 0.75rem;
    background: var(--slate-200);
    color: var(--slate-600);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.list-task-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: white;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    transition: var(--transition-fast);
    cursor: pointer;
}

.list-task-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.list-task-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    text-align: center;
    padding-right: var(--space-3);
    border-right: 1px solid var(--slate-100);
}

.list-task-time .date {
    font-size: 0.75rem;
    color: var(--slate-500);
    margin-bottom: 2px;
}

.list-task-time .time {
    font-size: 1rem;
    font-weight: 700;
    color: var(--slate-800);
}

.list-task-info {
    flex: 1;
}

.list-task-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 4px;
}

.list-task-title {
    font-weight: 600;
    color: var(--slate-800);
    font-size: 0.95rem;
}

.list-task-meta {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 0.8rem;
    color: var(--slate-500);
}

.list-task-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.list-task-meta svg {
    width: 14px;
    height: 14px;
}

.list-task-status {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.list-task-status.todo {
    background: var(--slate-100);
    color: var(--slate-600);
}

.list-task-status.in-progress {
    background: var(--primary-bg);
    color: var(--primary);
}

.list-task-status.done {
    background: var(--success-bg);
    color: var(--success);
}

/* Staff Avatar available in All view */
.list-staff-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: var(--space-2);
}

@media (max-width: 768px) {
    .list-view-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
        overflow-x: auto;
    }

    .list-task-card {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .list-task-time {
        flex-direction: row;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--slate-100);
        padding-bottom: var(--space-2);
        padding-right: 0;
        justify-content: flex-start;
        gap: var(--space-2);
    }

    .list-task-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }
}

/* Meta-style Date Filter Dropdown */
/* Meta-style Date Filter Dropdown COMPACT FIX */
.date-filter-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    /* Changed from right: 0 to left: 0 */
    margin-top: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    z-index: 1000;
    width: max-content;
    max-width: 90vw;
    overflow: hidden;
}

.date-filter-dropdown.hidden {
    display: none;
}

/* Sidebar */
.filter-sidebar {
    width: 140px;
    /* Reduced from 180px */
    background: #f8fafc;
    border-right: 1px solid var(--border-color);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.preset-btn {
    text-align: left;
    padding: 8px 10px;
    /* Reduced padding */
    border-radius: 6px;
    font-size: 0.8rem;
    /* Reduced font */
    color: var(--slate-700);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: #e2e8f0;
}

.preset-btn.active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 500;
}

/* Custom Area */
.filter-custom {
    flex: 1;
    padding: 12px;
    /* Reduced padding */
    display: flex;
    flex-direction: column;
}

/* Dual Calendar Styles COMPACT */
.selected-range-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.range-item {
    display: flex;
    flex-direction: column;
}

.range-item label {
    font-size: 0.7rem;
    color: var(--slate-500);
    margin-bottom: 2px;
}

.range-item span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--slate-800);
}

.dual-calendar-container {
    position: relative;
    margin-bottom: 12px;
}

.calendars-wrapper {
    display: flex;
    gap: 16px;
    /* Reduced from 24px */
    flex-wrap: wrap;
    /* Allow wrap on very small screens */
    justify-content: center;
}

.calendar-month {
    width: 210px;
    /* Reduced from 250px */
}

.calendar-month-header {
    text-align: center;
    font-weight: 600;
    color: var(--slate-700);
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    text-align: center;
}

.calendar-day-header {
    font-size: 0.7rem;
    color: var(--slate-400);
    padding: 4px 0;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    /* Reduced font */
    color: var(--slate-700);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.1s;
}

.calendar-day:hover:not(.empty) {
    background: #e2e8f0;
}

.calendar-day.empty {
    cursor: default;
}

.calendar-day.selected {
    background: var(--primary);
    color: white;
}

.calendar-day.in-range {
    background: #eff6ff;
    color: var(--primary);
    border-radius: 0;
}

.calendar-day.range-start {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.calendar-day.range-end {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}

.calendar-nav {
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.calendar-nav button {
    pointer-events: auto;
    background: transparent;
    border: none;
    color: var(--slate-500);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
}

.calendar-nav button:hover {
    background: #f1f5f9;
}

.filter-actions-bottom {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    gap: 8px;
}

.custom-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slate-500);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-custom .arrow {
    color: var(--slate-400);
}

.range-arrow {
    color: var(--slate-400);
    font-size: 0.85rem;
}

/* =====================================================
   History View (Full Page)
===================================================== */

.history-view-container {
    padding: var(--space-4);
}

.history-view-header {
    margin-bottom: var(--space-4);
}

.history-view-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--slate-800);
    margin: 0 0 var(--space-1) 0;
}

.history-view-header h3 svg {
    width: 22px;
    height: 22px;
    color: var(--primary);
}

.history-view-header p {
    margin: 0;
    font-size: 0.85rem;
}

.history-view-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* History Date Groups */
.history-date-group {
    background: white;
    border-radius: var(--radius-xl);
    border: 1px solid var(--slate-200);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.history-date-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: linear-gradient(135deg, var(--slate-50) 0%, var(--slate-100) 100%);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--slate-700);
    border-bottom: 1px solid var(--slate-200);
}

.history-date-header svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.history-tasks {
    display: flex;
    flex-direction: column;
}

/* History Task Cards */
.history-task-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: var(--transition-fast);
    border-bottom: 1px solid var(--slate-100);
}

.history-task-card:last-child {
    border-bottom: none;
}

.history-task-card:hover {
    background: var(--slate-50);
}

.history-task-card.completed .history-task-status {
    background: var(--success-bg);
    color: var(--success);
}

.history-task-card.past-due .history-task-status {
    background: var(--danger-bg);
    color: var(--danger);
}

.history-task-status {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.history-task-status svg {
    width: 18px;
    height: 18px;
}

.history-task-info {
    flex: 1;
    min-width: 0;
}

.history-task-title {
    font-weight: 600;
    color: var(--slate-800);
    font-size: 0.9rem;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-task-meta {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-size: 0.75rem;
    color: var(--slate-500);
}

.history-task-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-task-meta svg {
    width: 12px;
    height: 12px;
}

.history-task-badge {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.history-task-badge.completed {
    background: var(--success-bg);
    color: var(--success);
}

.history-task-badge.past-due {
    background: var(--danger-bg);
    color: var(--danger);
}

/* =====================================================
   Mobile Responsive Improvements (Comprehensive)
===================================================== */

@media (max-width: 768px) {

    /* 1. Header Layout */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-2);
        /* Reduced gap */
        margin-bottom: var(--space-2);
        /* Reduced margin bottom */
        padding-bottom: var(--space-2);
        /* Reduced padding bottom */
    }

    .page-header-left {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .page-header-left h2 {
        font-size: 1.25rem;
    }

    /* 2. Scrollable View Toggles */
    .view-toggle {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
        /* Space for scrollbar if visible */
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll on iOS */
    }

    .view-toggle::-webkit-scrollbar {
        height: 0;
        width: 0;
        display: none;
    }

    .toggle-btn {
        flex-shrink: 0;
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    /* 3. Date Picker & Filters */
    .page-header-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .date-picker-wrapper {
        flex-grow: 1;
    }

    /* 4. Filter Bar Chips */
    .list-view-filters {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
        margin-bottom: var(--space-4);
        padding-bottom: var(--space-2);
        border-bottom: 1px solid var(--slate-100);
    }

    .filter-group {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
        gap: var(--space-2);
        width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .filter-group::-webkit-scrollbar {
        height: 0;
        width: 0;
        display: none;
    }

    .filter-chip {
        flex-shrink: 0;
    }

    /* 5. List View Cards */
    .list-task-card {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-3);
    }

    .list-task-time {
        flex-direction: row;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--slate-100);
        padding-bottom: var(--space-2);
        padding-right: 0;
        justify-content: flex-start;
        gap: var(--space-3);
        text-align: left;
    }

    .list-task-time .date,
    .list-task-time .time {
        font-size: 0.85rem;
        margin: 0;
    }

    .list-task-time::after {
        content: "";
        /* Add separator if needed */
        display: none;
    }

    .list-task-info {
        width: 100%;
    }

    .list-task-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        margin-top: var(--space-1);
        padding-top: var(--space-2);
        border-top: 1px solid var(--slate-50);
    }

    /* 6. History View Cards */
    .history-task-card {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .history-task-status {
        width: 32px;
        height: 32px;
    }

    .history-task-info {
        width: 100%;
    }

    .history-task-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-1);
        margin-top: var(--space-2);
    }

    .history-task-badge {
        align-self: flex-start;
        margin-top: var(--space-1);
        font-size: 0.65rem;
    }

    /* 7. Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* 8. Fix dropdown position on mobile */
    .date-filter-dropdown {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90vw;
        max-width: 350px;
        max-height: 80vh;
        overflow-y: auto;
        z-index: 1000;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    }

    /* Overlay for dropdown */
    .dropdown-overlay {
        display: block;
        /* Managed by JS to show/hide */
    }
}

/* =====================================================
   ADDITIONAL MOBILE FIXES (Comprehensive)
===================================================== */

@media (max-width: 480px) {
    /* Extra Small Screens - Phones */

    /* 1. Modal Fixes */
    .modal {
        width: 95vw !important;
        max-width: none !important;
        max-height: 90vh !important;
        margin: 20px auto;
    }

    .modal-header {
        padding: var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .modal-header h3 {
        font-size: 1rem;
        flex: 1;
        min-width: 200px;
    }

    .modal-body {
        padding: var(--space-3);
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 100px;
        justify-content: center;
    }

    /* 2. Form Improvements */
    .form-group label {
        font-size: 0.8rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important;
        /* Prevents iOS zoom on focus */
        padding: var(--space-3);
        min-height: 44px;
        /* Touch-friendly */
    }

    .form-row {
        grid-template-columns: 1fr !important;
        gap: var(--space-3);
    }

    /* 3. Button Touch Targets */
    .btn {
        min-height: 44px;
        padding: var(--space-3) var(--space-4);
    }

    .btn-sm {
        min-height: 36px;
    }

    .icon-btn {
        width: 44px;
        height: 44px;
    }

    /* 4. Toast Notifications */
    .toast-container {
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 100px;
        /* Above bottom nav */
    }

    .toast {
        min-width: auto;
        max-width: none;
        width: 100%;
    }

    /* 5. Calendar View Mobile - uses flex from parent */

    .calendar-staff-header {
        min-width: 120px;
    }

    .calendar-staff-column {
        min-width: 120px;
        overflow: hidden;
    }

    .calendar-task-card {
        font-size: 0.65rem;
        padding: 3px 6px;
        max-width: 100%;
    }

    .calendar-task-card .task-title {
        font-size: 0.65rem;
    }

    /* 6. Task Detail Modal */
    .task-detail-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .task-detail-header h2 {
        font-size: 1.1rem;
        line-height: 1.3;
    }

    .task-detail-meta {
        width: 100%;
        flex-wrap: wrap;
    }

    .task-detail-meta>div {
        flex: 1 1 45%;
        min-width: 120px;
    }

    /* 7. Checklist Items */
    .checklist-item {
        padding: var(--space-3);
        gap: var(--space-2);
    }

    .checklist-item .checkbox {
        width: 24px;
        height: 24px;
    }

    .checklist-item .text {
        font-size: 0.8rem;
    }

    .checklist-time-log {
        font-size: 0.6rem;
        display: block;
        width: 100%;
        margin-top: 4px;
        margin-left: 32px;
    }

    /* 8. Attachment Form */
    .add-attachment-form {
        flex-wrap: wrap;
    }

    .add-attachment-form input {
        flex: 1 1 100%;
        margin-bottom: var(--space-2);
    }

    .add-attachment-form button {
        width: 100%;
    }

    /* 9. Comments Section */
    .comment-form {
        flex-direction: column;
    }

    .comment-form input {
        width: 100%;
    }

    .comment-form button {
        width: 100%;
        margin-top: var(--space-2);
    }

    /* 10. Users Table Responsive */
    .users-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .users-table th,
    .users-table td {
        padding: var(--space-2);
        font-size: 0.75rem;
    }

    /* 11. Day Selector Buttons */
    .routine-days {
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .day-btn {
        min-width: 40px;
        min-height: 40px;
        font-size: 0.7rem;
    }

    /* 12. Main Content Padding */
    .main-content {
        padding-left: var(--space-2);
        padding-right: var(--space-2);
    }

    /* 13. Login Page */
    .login-card {
        padding: var(--space-4);
    }

    .login-card h2 {
        font-size: 1.25rem;
    }
}

/* =====================================================
   Touch Device Optimizations
===================================================== */
@media (hover: none) and (pointer: coarse) {

    /* Remove hover effects that don't work well on touch */
    .task-card:hover {
        transform: none;
    }

    .calendar-task-card:hover {
        transform: none;
    }

    .btn:hover {
        transform: none;
    }

    /* Add active states instead */
    .task-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .btn:active {
        transform: scale(0.97);
    }

    /* Larger tap targets */
    .checklist-item {
        min-height: 48px;
    }

    .notif-item {
        min-height: 56px;
    }
}

/* =====================================================
   Landscape Phone Orientation
===================================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 85vh;
    }

    .modal-body {
        max-height: 50vh;
    }

    .calendar-wrapper {
        height: 300px;
    }

    .mobile-bottom-nav {
        padding: 8px 16px;
    }

    .nav-btn-mobile {
        height: 40px;
    }
}

/* =====================================================
   Safe Area Insets (iPhone X+)
===================================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
    }
}

/* =====================================================
   List View & History View Scroll Fix
===================================================== */

/* Container: Takes full height of parent and sets up flex column */
#list-view-container,
#history-view-container {
    display: flex;
    /* Override existing display if any */
    flex-direction: column;
    height: 100%;
    /* Fill main-content height */
    overflow: hidden;
    /* Prevent body scroll */
    min-height: 0;
    /* Important for flex child scrolling */
}

/* Header Area (Filters): Keeps its natural height */
.list-view-filters,
.history-view-header {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-4);
    /* Ensure padding */
    background: transparent;
    /* Or match background */
}

/* Content Area: Expands to fill remaining space and scrolls internally */
.list-view-content,
.history-view-content {
    flex: 1;
    /* Grow to fill space */
    overflow-y: auto;
    /* Enable internal scrolling */
    padding: var(--space-4);

    /* Smooth Scrolling */
    scroll-behavior: smooth;

    /* Custom Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: var(--slate-300) transparent;
}

/* Webkit Scrollbar Styling (Chrome, Safari, Edge) */
.list-view-content::-webkit-scrollbar,
.history-view-content::-webkit-scrollbar {
    width: 6px;
}

.list-view-content::-webkit-scrollbar-track,
.history-view-content::-webkit-scrollbar-track {
    background: transparent;
}

.list-view-content::-webkit-scrollbar-thumb,
.history-view-content::-webkit-scrollbar-thumb {
    background-color: var(--slate-300);
    border-radius: 99px;
}

.list-view-content::-webkit-scrollbar-thumb:hover,
.history-view-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--slate-400);
}

