@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Dark Theme (Default) */
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --bg-sidebar: #0b0f19;
    --bg-header: #1e293b;
    
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-accent: #38bdf8;
    
    /* Gantt Chart Color Coding */
    --color-wbs: #475569;
    --color-task-planned: #0284c7;
    --color-task-actual: #16a34a;
    --color-task-critical: #dc2626;
    --color-milestone: #f59e0b;
    --color-relation-line: rgba(56, 189, 248, 0.4);
    --color-relation-hover: #38bdf8;
    
    --sidebar-width: 320px;
    --table-width: 550px;
    --row-height: 36px; /* Accommodate dual bars in compact layout */
}

[data-theme="light"] {
    /* Light Theme Toggle */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-sidebar: #f1f5f9;
    --bg-header: #e2e8f0;
    
    --border-color: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-accent: #0284c7;
    
    --color-wbs: #64748b;
    --color-task-planned: #0ea5e9;
    --color-task-actual: #22c55e;
    --color-task-critical: #ef4444;
    --color-milestone: #f59e0b;
    --color-relation-line: rgba(2, 132, 199, 0.4);
    --color-relation-hover: #0284c7;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 9px;
}

.sidebar-brand-copy {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.sidebar-logo-link {
    width: 54px;
    height: 54px;
    flex: 0 0 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #ffffff;
}

.sidebar-logo {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.sidebar-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.025em;
}

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background-color: var(--bg-hover);
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.search-box {
    padding: 0 15px;
}

.search-input {
    width: 100%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.search-input:focus {
    border-color: var(--text-accent);
}

.section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 15px 8px 15px;
}

/* SQLite Database Connection and Dropzone Styles */
.db-section {
    padding: 0 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.db-select {
    width: 100%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.db-select:focus {
    border-color: var(--text-accent);
}

.db-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 15px 10px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    background-color: var(--bg-card);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.db-dropzone:hover, .db-dropzone.dragover {
    border-color: var(--text-accent);
    color: var(--text-main);
    background-color: var(--bg-hover);
}

/* Project Selection List Styles */
.project-section {
    display: flex;
    flex-direction: column;
    padding: 0 10px;
}

.project-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    padding: 2px 5px;
}

.project-item {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    border-left: 3px solid #cbd5e1; /* Default gray indicator border */
}

.project-item:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-accent);
}

.project-item.active {
    background-color: var(--bg-hover);
    border-color: var(--text-accent);
    border-left-color: var(--text-accent);
}

.project-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-main);
}

.project-item-baseline {
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-item-date {
    font-size: 0.65rem;
    background-color: rgba(2, 132, 199, 0.15);
    color: var(--text-accent);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

/* EPS folders styling in projects list */
.eps-folder-node {
    margin-bottom: 2px;
}

.eps-folder-header {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--text-main);
    transition: background-color 0.2s, color 0.2s;
    user-select: none;
}

.eps-folder-header:hover {
    background-color: var(--bg-hover);
    color: var(--text-accent);
}

.eps-folder-toggle {
    display: inline-block;
    width: 12px;
    margin-right: 4px;
    font-size: 0.6rem;
    color: var(--text-muted);
}

.eps-folder-icon {
    margin-right: 6px;
    font-size: 0.8rem;
}

.eps-folder-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eps-folder-children {
    border-left: 1px dashed var(--border-color);
    margin-left: 14px;
    padding-left: 2px;
    display: block; /* default expanded */
}

.view-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 10px;
}

.view-btn {
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
}

.view-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.view-btn.active {
    background-color: var(--text-accent);
    color: #ffffff;
    font-weight: 500;
}

.view-btn-badge {
    font-size: 0.75rem;
    background-color: rgba(255,255,255,0.15);
    padding: 2px 6px;
    border-radius: 10px;
    color: inherit;
}

.filter-group {
    padding: 0 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.filter-checkbox-label:hover {
    color: var(--text-main);
}

.filter-checkbox {
    accent-color: var(--text-accent);
}

/* Main Display Area */
.main-display {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.main-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.main-header-title h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.main-header-title p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.main-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-btn {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: var(--font-main);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background-color: var(--bg-hover);
}

/* Schedule Grid Wrapper */
.schedule-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Scroll Synchronized Timeline Headers */
.timeline-header-container {
    display: flex;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.table-header {
    width: var(--table-width);
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 100px 1fr 100px 100px 60px;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 10px;
    height: 50px;
}

.table-header-cell {
    padding: 5px;
}

.gantt-header-viewport {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    height: 50px;
}

.gantt-header-content {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.gantt-header-year-row {
    height: 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
}

.gantt-header-year-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 100%;
}

.gantt-header-month-row {
    height: 20px;
    display: flex;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
}

.gantt-header-month-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 100%;
}

/* Unified Grid Scroll Layout */
.schedule-wrapper {
    flex-grow: 1;
    overflow: auto; /* Single horizontal and vertical scrollbar */
    max-height: calc(100vh - 85px);
    position: relative;
}

.timeline-header-container {
    display: flex;
    width: max-content;
    border-bottom: 1px solid var(--border-color);
}

.table-header {
    width: var(--table-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 30;
    background-color: var(--bg-header);
    border-right: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 100px 1fr 100px 100px 60px;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 10px;
    height: 38px;
}

.gantt-header-content {
    display: flex;
    flex-direction: column;
    height: 38px;
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: var(--bg-header);
}

/* Rows Container */
.schedule-rows-viewport {
    display: flex;
    flex-direction: column;
    width: max-content;
}

.schedule-row {
    display: flex;
    height: var(--row-height);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease;
    width: max-content;
}

.schedule-row:hover {
    background-color: var(--bg-hover);
}

/* Keep sticky column backgrounds synchronized with row hover states */
.schedule-row:hover .row-table-cells {
    background-color: var(--bg-hover) !important;
}

.row-table-cells {
    width: var(--table-width);
    flex-shrink: 0;
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 100px 1fr 100px 100px 60px;
    align-items: center;
    font-size: 0.72rem;
    padding: 0 10px;
    transition: background-color 0.15s ease;
}

.row-cell {
    padding: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-cell.code {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-accent);
}

.row-cell.name-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.row-cell.date {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.row-cell.float {
    text-align: right;
    font-family: monospace;
}

.wbs-row {
    font-weight: 600;
}

.wbs-row .row-cell.code {
    color: var(--text-main);
}

.toggle-arrow {
    cursor: pointer;
    font-size: 0.75rem;
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    user-select: none;
}

.toggle-arrow.collapsed {
    transform: rotate(-90deg);
}

/* Gantt Row Layout */
.row-gantt-strip {
    height: var(--row-height);
    position: relative;
    display: flex;
    align-items: center;
    background-color: transparent;
}

/* Gantt Bar Styles */
.gantt-bar-wrapper {
    position: absolute;
    height: 9px;
    top: 5px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.gantt-bar {
    height: 100%;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.25);
    position: relative;
    min-width: 4px;
    transition: transform 0.15s ease, filter 0.15s ease;
    background-color: var(--color-task-planned);
}

.gantt-bar-wrapper:hover .gantt-bar {
    transform: scaleY(1.1);
    filter: brightness(1.15);
}

/* Green-teal for normal schedule, red for critical */
.gantt-bar.planned, .gantt-bar.actual {
    background-color: #00a295; /* Vibrant green-teal */
}

.gantt-bar.critical {
    background-color: #ef4444; /* Vibrant red */
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.35);
}

/* Progress Overlay */
.gantt-progress-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background-color: #0b2f61; /* Dark blue progress */
    border-radius: 3px 0 0 3px;
    z-index: 2;
    pointer-events: none;
}

/* Baseline Bar Styles */
.gantt-bar-wrapper.baseline {
    top: 20px;
    height: 6px;
    opacity: 0.85;
}

.gantt-bar.baseline {
    background-color: #f1c40f; /* Gold/yellow */
    border: 1px solid #d68910;
    border-radius: 2px;
    box-shadow: none;
}

.gantt-bar-wrapper.baseline:hover .gantt-bar.baseline {
    transform: scaleY(1.15);
    filter: brightness(1.1);
}

.gantt-bar.wbs-summary {
    background-color: var(--color-wbs);
    height: 8px; /* Thicker current summary bar */
    border-radius: 2px;
}

/* WBS Summary Bracket Ends */
.gantt-bar.wbs-summary::before,
.gantt-bar.wbs-summary::after {
    content: '';
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
    border-style: solid;
}

.gantt-bar.wbs-summary::before {
    left: 0;
    border-width: 8px 0 0 6px; /* Fit 8px height summary bar */
    border-color: var(--color-wbs) transparent transparent transparent;
}

.gantt-bar.wbs-summary::after {
    right: 0;
    border-width: 8px 6px 0 0; /* Fit 8px height summary bar */
    border-color: var(--color-wbs) transparent transparent transparent;
}

/* Milestone Diamonds */
.gantt-milestone {
    width: 9px;
    height: 9px;
    background-color: #00a295;
    transform: rotate(45deg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.gantt-milestone.critical {
    background-color: #ef4444;
}

.gantt-milestone.baseline {
    width: 7px;
    height: 7px;
    background-color: #f1c40f;
    border: 1px solid #d68910;
    box-shadow: none;
}

.gantt-milestone-wrapper {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    top: 5px;
    height: 9px;
}

.gantt-milestone-wrapper.baseline {
    top: 20px;
    height: 6px;
    opacity: 0.85;
}

.gantt-milestone-wrapper:hover .gantt-milestone {
    transform: rotate(45deg) scale(1.25);
    filter: brightness(1.2);
}

/* Data Date Line */
.data-date-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: #ef4444;
    border-style: dashed;
    border-width: 0 1px;
    z-index: 5;
    pointer-events: none;
}

.data-date-label {
    position: absolute;
    top: 2px;
    transform: translateX(-50%);
    background-color: #ef4444;
    color: #ffffff;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
    z-index: 6;
}

/* SVG Relationships Overlay */
.gantt-svg-overlay {
    position: absolute;
    top: 0;
    left: var(--table-width);
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15; /* Render overlay on top of task bars but below tooltips */
}

.relation-path {
    fill: none;
    stroke: var(--color-relation-line);
    stroke-width: 1.5;
    pointer-events: visibleStroke;
    cursor: pointer;
    transition: stroke 0.2s, stroke-width 0.2s;
}

.relation-path:hover {
    stroke: var(--color-relation-hover);
    stroke-width: 2.5;
}

/* Details Side Drawer */
.detail-drawer {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 15px rgba(0,0,0,0.3);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.detail-drawer.open {
    right: 0;
}

.drawer-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.close-drawer-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

.close-drawer-btn:hover {
    color: var(--text-main);
}

.drawer-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.detail-val {
    font-size: 0.85rem;
    color: var(--text-main);
}

.detail-val.code {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-accent);
}

.relation-link-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.relation-link {
    font-size: 0.8rem;
    color: var(--text-accent);
    cursor: pointer;
    text-decoration: underline;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.relation-link:hover {
    color: var(--text-main);
}

/* Tooltips */
.gantt-tooltip {
    position: absolute;
    background-color: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--border-color);
    color: #f8fafc;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    z-index: 1000;
    pointer-events: none;
    display: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    max-width: 300px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Print CSS */
@media print {
    body {
        background-color: #ffffff;
        color: #000000;
    }
    
    .sidebar, .main-header, .detail-drawer, .theme-toggle-btn {
        display: none !important;
    }
    
    .main-display {
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }
    
    .schedule-wrapper {
        overflow: visible !important;
    }
    
    .schedule-rows-viewport {
        overflow: visible !important;
        height: auto !important;
    }
    
    .schedule-row {
        page-break-inside: avoid;
    }
}

/* Sortable column headers */
.table-header-cell.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px !important;
    transition: background-color 0.2s, color 0.2s;
}

.table-header-cell.sortable:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.sort-indicator {
    font-size: 0.65rem;
    margin-left: 4px;
    opacity: 0.8;
}
