:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --today: #ef4444;
    --bg: #f8fafc;
    --border: #cbd5e1;
    --sidebar-w: 260px;
    --task-col-w: 350px;
    --day-w: 50px;
    --row-h: 46px;
    --dept-header-h: 38px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }
body { display: flex; flex-direction: column; height: 100vh; background: var(--bg); overflow: hidden; color: #0f172a; }

/* Top Account Navigation Bar */
.top-account-bar {
    height: 38px;
    background: #0f172a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    font-size: 12px;
    border-bottom: 1px solid #334155;
    z-index: 50;
}
.brand-title { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.brand-title img { height: 22px; }
.account-selector { display: flex; align-items: center; gap: 10px; }
.account-selector select {
    background: #1e293b;
    color: white;
    border: 1px solid #475569;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.role-badge {
    background: #a78bfa;
    color: #1e1b4b;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 11px;
}
.ai-status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1e293b;
    padding: 3px 10px;
    border-radius: 14px;
    border: 1px solid #334155;
    font-size: 11px;
    font-weight: 600;
}
.ai-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px #10b981;
    animation: blink 1.5s infinite;
}
.ai-led.offline {
    background: #ef4444;
    box-shadow: 0 0 6px #ef4444;
    animation: none;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* App Main Body Layout */
.app-container { display: flex; flex: 1; overflow: hidden; }

/* Left Sidebar Dual Workspace */
.project-sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: #1e293b;
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    z-index: 30;
}
.sidebar-title {
    padding: 12px 15px;
    font-size: 14px;
    font-weight: bold;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid #334155;
}

.section-title {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: #0f172a;
    color: #38bdf8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.project-sublist {
    flex: 1;
    overflow-y: auto;
}

.project-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #334155;
    transition: 0.2s;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.project-item:hover, .project-item.active {
    background: #334155;
    border-left: 4px solid var(--primary);
}
.project-status-tag {
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 4px;
    background: #10b981;
    color: white;
}
.vault-link {
    padding: 12px 15px;
    background: #0f172a;
    border-top: 1px solid #334155;
    color: #94a3b8;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.vault-link:hover { background: #1e293b; color: white; }

/* Main Workspace Area */
.workspace { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.top-bar {
    height: 55px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    z-index: 28;
}
.actions { display: flex; gap: 6px; align-items: center; }

.date-range-picker {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
}
.date-range-picker input {
    border: 1px solid var(--border);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 11px;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}
.btn:hover { opacity: 0.9; }
.btn-success { background: #10b981; }
.btn-warning { background: #f59e0b; color: #1e293b; }
.btn-secondary { background: #64748b; }
.btn-danger { background: #ef4444; }
.btn-admin { background: #8b5cf6; }

/* Gantt Chart Grid Wrapper */
.gantt-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
    margin: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
}

.gantt-header {
    display: flex;
    background: #cbd5e1;
    border-bottom: 2px solid var(--border);
    height: 46px;
    font-weight: bold;
    font-size: 11px;
    z-index: 25;
}

/* Sticky Task Column Header */
.gantt-task-head {
    width: var(--task-col-w);
    min-width: var(--task-col-w);
    padding: 8px 12px;
    border-right: 1px solid var(--border);
    background: #94a3b8;
    color: #0f172a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    left: 0;
    z-index: 30;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}
.gantt-days-head-scroll {
    flex: 1;
    overflow-x: hidden;
    display: flex;
    position: relative;
}

.gantt-body-scroll {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* 10-Department Accordion Unified Row */
.dept-unified-row {
    display: flex;
    height: var(--dept-header-h);
    border-bottom: 1px solid var(--border);
    position: relative;
}

/* Sticky Department Tag Title Cell */
.dept-title-cell {
    width: var(--task-col-w);
    min-width: var(--task-col-w);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    position: sticky;
    left: 0;
    z-index: 25;
    box-shadow: 2px 0 5px rgba(0,0,0,0.08);
    cursor: pointer;
}

.dept-title-cell .toggle-btn {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: rgba(0,0,0,0.08);
    font-size: 12px;
}

.dept-timeline-bg {
    display: flex;
    height: 100%;
}

/* Department Color Palettes (Sleek Pastels) */
.dept-designer { background-color: #eff6ff; color: #1e40af; border-left: 4px solid #3b82f6; }
.dept-planning { background-color: #f0fdf4; color: #166534; border-left: 4px solid #22c55e; }
.dept-construction { background-color: #fff7ed; color: #9a3412; border-left: 4px solid #f97316; }
.dept-factory { background-color: #faf5ff; color: #6b21a8; border-left: 4px solid #a855f7; }
.dept-mep { background-color: #fdf2f8; color: #9d174d; border-left: 4px solid #ec4899; }
.dept-storage { background-color: #fefce8; color: #854d0e; border-left: 4px solid #eab308; }
.dept-purchasing { background-color: #f0fdfa; color: #115e59; border-left: 4px solid #14b8a6; }
.dept-accountant { background-color: #f8fafc; color: #334155; border-left: 4px solid #64748b; }

/* UNIFIED ROW INTEGRITY */
.gantt-unified-row {
    display: flex;
    height: var(--row-h);
    border-bottom: 1px solid var(--border);
    position: relative;
}
.gantt-unified-row:hover { background-color: #f8fafc; }

/* Sticky Task Title Cell */
.task-title-cell {
    width: var(--task-col-w);
    min-width: var(--task-col-w);
    padding: 0 12px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    background: white;
    position: sticky;
    left: 0;
    z-index: 25;
    box-shadow: 2px 0 5px rgba(0,0,0,0.08);
}
.timeline-cell-grid { display: flex; position: relative; height: 100%; }

.day-cell {
    min-width: var(--day-w);
    border-right: 1px solid #f1f5f9;
    text-align: center;
    font-size: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none;
}

/* Weekend Styling (Sat/Sun Bôi Đỏ) */
.day-cell.is-weekend {
    background-color: #fef2f2 !important;
    color: #dc2626 !important;
    font-weight: bold;
}
.day-cell.is-weekend .day-name {
    color: #b91c1c;
}

/* TODAY LINE */
.today-line {
    position: absolute;
    top: 0;
    width: 2px;
    background: #ef4444;
    z-index: 18;
    pointer-events: none;
    box-shadow: 0 0 8px #ef4444;
    animation: todayGlow 1.5s infinite alternate;
}

@keyframes todayGlow {
    from { opacity: 0.75; box-shadow: 0 0 4px #ef4444; }
    to { opacity: 1; box-shadow: 0 0 12px #ef4444; }
}

.today-line::before {
    content: 'TODAY';
    position: absolute;
    top: 2px;
    left: -18px;
    background: #ef4444;
    color: white;
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 3px;
    font-weight: bold;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.9);
}

/* SVG DEPENDENCY OVERLAY */
#dependency-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 15;
}

/* TASK BARS */
.task-bar {
    position: absolute;
    height: 28px;
    top: 8px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    white-space: nowrap;
    overflow: visible;
    z-index: 6;
    transition: transform 0.1s;
    user-select: none;
}

.task-bar.selected-task {
    outline: 2px solid #f97316;
    z-index: 17;
}

/* Alert Icons Distinction */
.alert-dot-predecessor {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 6px #ef4444;
    animation: alertPulse 1s infinite alternate;
}
@keyframes alertPulse { from { transform: scale(1); } to { transform: scale(1.35); } }

.alert-dot-successor {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    background: #f59e0b;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 4px #f59e0b;
}

/* Shadow Task styling */
.task-bar.shadow-task {
    opacity: 0.65;
    border: 2px dashed #64748b !important;
}

/* Handles for dragging link */
.handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #f97316;
    border: 2px solid white;
    border-radius: 50%;
    top: 8px;
    z-index: 20;
    cursor: crosshair;
    display: none;
}
.handle-left { left: -6px; }
.handle-right { right: -6px; }

.task-bar.selected-task .handle, .task-bar:hover .handle { display: block; }

/* Task status color classes */
.status-completed { background-color: #1e3a8a !important; color: #ffffff !important; border: 1px solid #1e40af; }
.status-completed::before { content: "✓ "; color: #4ade80; font-weight: bold; margin-right: 3px; }
.status-working { background-color: #86efac !important; color: #064e3b !important; border: 1px solid #4ade80; }
.status-pending { background-color: #fde047 !important; color: #713f12 !important; border: 1px solid #facc15; }
.status-overdue { background-color: #fca5a5 !important; color: #7f1d1d !important; border: 2px solid #ef4444 !important; box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    justify-content: center;
    align-items: center;
}
.modal-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 520px;
    max-width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.form-control { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }

.dept-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    background: #f8fafc;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
}

/* Vault Card Layout (archive.html) */
.vault-header {
    background: #1e293b;
    color: white;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.vault-banner {
    background: #f59e0b;
    color: #1e293b;
    padding: 12px 20px;
    font-size: 13px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}
.vault-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    padding: 25px;
    overflow-y: auto;
}
.vault-card {
    background: #1e293b;
    color: white;
    border-radius: 8px;
    padding: 20px;
    border: 1px solid #334155;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.vault-card h4 { font-size: 16px; color: #38bdf8; margin-bottom: 8px; }
.vault-card p { font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
.vault-card-footer {
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #334155;
    padding-top: 12px;
}
