/* Allow page to scroll; Gantt still manages its own inner scroll */
html, body { min-height: 100%; overflow-x: hidden; overflow-y: auto; }

/* Label column resizer */
.label-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 6px;
    margin-left: calc(var(--label-width) - 3px); /* center on boundary */
    cursor: col-resize;
    background: transparent;
    z-index: 6; /* above grid */
}
.label-resizer::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; left: 2px; width: 2px;
    background: rgba(2,6,23,0.08);
}
.label-resizer:hover::after, .label-resizer.dragging::after {
    background: rgba(37,99,235,0.35);
}

/* Gantt body owns internal scrolling */
.gantt-body {
    display: flex;
    margin-top: 8px;
    height: 600px; /* fixed height as requested */
    flex: 0 0 600px;
    /* Allow inner scrollbars to be visible */
    overflow: visible;
}

/* Only timelineBodyCol scrolls */
#timelineBodyCol {
    /* Enable both vertical and horizontal scrollbars */
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
    overscroll-behavior: contain; /* keep page from scrolling */
    height: 100%; /* fill gantt-body */
}

/* Prevent the page from scrolling when pointer is over the gantt body */
.gantt-body:hover,
.gantt-body:focus-within {
    overscroll-behavior: contain;
}

/* Minimal scrollbars inside the Gantt only */
#timelineBodyCol::-webkit-scrollbar { height: 8px; width: 8px; }
#timelineBodyCol::-webkit-scrollbar-track { background: transparent; }
#timelineBodyCol::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.15); border-radius: 8px; }
#timelineBodyCol::-webkit-scrollbar-thumb:hover { background-color: rgba(0,0,0,0.25); }

/* Firefox scrollbar */
#timelineBodyCol { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.25) transparent; }
.color-grid {
    display: grid;
    grid-template-columns: repeat(12, 18px);
    grid-auto-rows: 18px;
    gap: 4px;
}
.color-grid .break { grid-column: 1 / -1; height: 0; }
.color-grid .swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.12);
    padding: 0;
    cursor: pointer;
}
.color-grid .swatch.selected {
    outline: 2px solid #111827;
    outline-offset: 1px;
}

.color-grid .section-title {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--muted);
    margin: 2px 0 2px;
}
/* CSS Variables */
:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --accent: #2563eb;
    --muted: #6b7280;
    --radius: 12px;
    --border: #e6e9ef;
    --row-height: 68px;
    --label-width: 230px;
    --day-width: 56px;
}

/* Context menu */
.context-menu {
    position: fixed;
    z-index: 10000;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(16,24,40,0.16);
    padding: 4px;
    min-width: 160px;
}
.context-menu button { width: 100%; text-align: left; padding: 8px 10px; background: transparent; border: none; cursor: pointer; }
.context-menu button:hover { background: #f3f4f6; }

/* Mini slider inside task list */
.mini-track {
    position: relative;
    width: 320px;
    height: 24px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: #f9fafb;
    margin: 0 12px;
    flex-shrink: 0;
}
.mini-bar {
    position: absolute;
    top: 4px;
    height: 16px;
    border-radius: 4px;
    cursor: grab;
}
.mini-bar:active { cursor: grabbing; }
.mini-handle {
    position: absolute;
    top: 2px;
    width: 8px;
    height: 20px;
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
    cursor: ew-resize;
}
.mini-handle.left { left: -4px; }
.mini-handle.right { right: -4px; }

/* Resources modal */
.modal { position: fixed; inset: 0; display: none; z-index: 9999; }
.modal .modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); pointer-events: auto; }
.modal .modal-content {
    position: relative;
    z-index: 2;
    width: 480px;
    max-width: calc(100% - 24px);
    margin: 10vh auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(16,24,40,0.16);
    padding: 12px;
}
.modal-header { display:flex; justify-content: space-between; align-items: center; }
.modal-body { margin-top: 8px; }
.resources-list { list-style: none; margin: 0; padding: 0; }
.resources-list li { display:flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); }

/* Screen-reader-only text */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Base Styles */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: #0f172a;
    padding: 22px;
}

/* Layout */
.wrap {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

h1 {
    margin: 0 0 6px;
    font-size: 20px;
}

.sub {
    color: var(--muted);
    margin: 0 0 18px;
    font-size: 13px;
}

/* Card Component */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 14px;
    box-shadow: 0 4px 18px rgba(16, 24, 40, 0.04);
}

/* First controls card height */
.wrap > section.card:first-of-type { min-height: 95px; }

/* Form Styles */
form.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    align-items: end;
}

label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="date"],
select {
    width: 100%;
    padding: 9px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 14px;
}

input[type="color"] {
    width: 48px;
    height: 38px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Button Styles */
.btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

/* Success variant */
.btn.success {
    background: #16a34a;
}
.btn.success:hover { background: #15803d; }

.btn:hover {
    background: #1d4ed8;
}

.btn.ghost {
    background: transparent;
    color: var(--accent);
    border: 1px dashed var(--border);
    padding: 8px;
}

.btn.ghost:hover {
    background: #f8fafc;
    border-color: var(--accent);
}

.btn.secondary {
    background: #f3f4f6;
    color: #111827;
}

.btn.secondary:hover {
    background: #e5e7eb;
}

/* Controls */
.controls {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}

/* Gantt Chart Styles */
.gantt-card {
    padding: 12px;
    /* Do not clip inner scrollbars */
    overflow: visible;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    position: relative; /* position context for label-resizer */
}

/* Gantt toolbar */
.gantt-toolbar {
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, #fff, rgba(255,255,255,0.9));
    z-index: 5;
    padding-bottom: 8px;
}

.gantt-header {
    display: flex;
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, #fff, rgba(255, 255, 255, 0.9));
    z-index: 4;
    padding-bottom: 8px;
}

.label-col {
    width: var(--label-width);
    flex: 0 0 var(--label-width);
    padding-right: 12px;
    display: flex;
    align-items: center;
}

.timeline-col {
    flex: 1;
    min-width: 400px;
    position: relative;
    overflow: auto;
}

/* Disable scroll in the header timeline column only */
.gantt-header .timeline-col {
    overflow: hidden;
}

.timeline-grid {
    position: relative;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
    min-height: 220px;
    padding-bottom: 16px; /* ensure last row has breathing room */
    /* Subtle vertical gridlines aligned to day width */
    background-image: repeating-linear-gradient(
        to right,
        rgba(2,6,23,0.04) 0px,
        rgba(2,6,23,0.04) 1px,
        transparent 1px,
        transparent var(--day-width)
    );
}

/* Today marker */
#todayMarker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ef4444; /* red */
    opacity: 0.9;
    z-index: 3;
    pointer-events: none;
}

.grid-head {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border);
}

.grid-head-row {
    display: flex;
}
.grid-head-row.months {
    border-bottom: 1px solid var(--border);
}


.day-cell {
    flex: 0 0 var(--day-width);
    padding: 6px 8px;
    font-size: 12px;
    border-right: 1px solid var(--border);
    color: var(--muted);
    text-align: center;
    white-space: nowrap;
}
.day-cell.weekend {
    background: linear-gradient(180deg, rgba(254, 226, 226, 0.35), rgba(254, 226, 226, 0.18)); /* subtle red-tint */
}
.day-cell.week {
    background: linear-gradient(180deg, rgba(243, 244, 246, 0.5), rgba(243, 244, 246, 0.3));
    font-weight: 500;
}
.day-cell.month {
    background: linear-gradient(180deg, rgba(243, 244, 246, 0.5), rgba(243, 244, 246, 0.3));
    font-weight: 600;
}

/* Rows */
.rows {
    position: relative;
    padding-bottom: 24px; /* extra scrollable space so last row is fully visible */
}

.row {
    display: flex;
    border-bottom: 1px solid rgba(14, 20, 30, 0.03);
    height: var(--row-height);
    align-items: flex-start;
}

.row-label {
    width: var(--label-width);
    padding: 8px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    line-height: 1.25;
    /* Keep task names fixed while horizontally scrolling */
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 2;
    box-shadow: 4px 0 8px rgba(16, 24, 40, 0.04);
}

.row-track {
    flex: 1;
    position: relative;
    height: 100%;
    overflow: visible;
    padding: 6px 8px;
}

/* Task Bar Styles */
.bar {
    position: absolute;
    top: 14px;
    height: 36px;
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 6px rgba(2, 6, 23, 0.12);
    cursor: grab;
    user-select: none;
    transition: transform 0.1s ease, left 120ms ease, width 120ms ease;
    overflow: visible;
}

/* Progress fill inside the task bar */
.bar .progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: rgba(255,255,255,0.25);
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    pointer-events: none;
    z-index: 1;
}

.bar:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(2, 6, 23, 0.18);
}

.bar:active {
    cursor: grabbing;
}

.bar .bar-label {
    padding: 0 12px;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none; /* allow handle clicks to pass through */
}
.bar .bar-label .muted { color: #ffffff; opacity: 0.9; }

/* Inline editor overlay (appears on top of a bar when editing inline) */
.inline-editor {
    position: absolute;
    left: 0;
    right: 0;
    top: -4px;
    padding: 6px 8px;
    background: rgba(255,255,255,0.98);
    color: #111827;
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr repeat(3, max-content);
    gap: 6px;
    box-shadow: 0 6px 20px rgba(2,6,23,0.18);
}
.inline-editor input[type="text"],
.inline-editor input[type="date"],
.inline-editor input[type="number"],
.inline-editor select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
}
.inline-editor .btn { padding: 6px 8px; font-size: 12px; }

/* Milestone marker */
.milestone {
    position: absolute;
    width: 16px;
    height: 16px;
    transform: rotate(45deg);
    background: #fff;
    border: 2px solid var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 6px rgba(2, 6, 23, 0.12);
}
.milestone .milestone-label {
    position: absolute;
    transform: rotate(-45deg);
    left: 18px;
    top: -2px;
    white-space: nowrap;
    font-size: 12px;
    color: #0f172a;
    background: rgba(255,255,255,0.9);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Resize Handles */
.handle {
    position: absolute;
    top: 0;
    width: 16px;
    height: 100%;
    cursor: ew-resize;
    opacity: 0.95;
    transition: opacity 0.2s ease;
    z-index: 3; /* above label */
}

.handle:hover {
    opacity: 1;
}

.handle.left {
    left: -6px;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.handle.right {
    right: -6px;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* Visual feedback while resizing */
.bar.resizing-left .handle.left,
.bar.resizing-right .handle.right {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.6);
}

.handle:after {
    content: '';
    display: block;
    width: 4px;
    height: 24px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 2px;
    margin: auto;
    position: relative;
    top: 8px;
}

/* Task List */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.task-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    transition: box-shadow 0.2s ease;
}

.task-item:hover {
    box-shadow: 0 2px 8px rgba(16, 24, 40, 0.08);
}

/* Utility Classes */
.muted {
    color: var(--muted);
    font-size: 13px;
}

.small {
    font-size: 13px;
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    pointer-events: none;
    display: none;
    z-index: 9999;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Responsive Design */
@media (max-width: 880px) {
    :root {
        --label-width: 160px;
        --day-width: 56px;
    }
    
    /* Hide the outer label column header on small screens, but keep per-row sticky labels visible */
    .label-col { display: none; }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filters {
        justify-content: center;
    }
}

@media (max-width: 640px) {
    body {
        padding: 12px;
    }
    
    .card {
        padding: 12px;
    }
    
    form.grid {
        grid-template-columns: 1fr;
    }
    
    .filters {
        flex-direction: column;
        gap: 8px;
    }
}
