/* ============================================================
   Vista Gantt (función activable `gantt`).

   Grilla propia, sin librería. La unidad atómica es el día: --gantt-day-w
   la fija gantt.js según el zoom, y --gantt-label-w es el ancho de la
   columna de títulos (sticky a la izquierda mientras el eje scrollea).
   ============================================================ */

.gantt-root {
    --gantt-label-w: 180px;
    --gantt-row-h: 34px;
    display: block;
}

.gantt-loading,
.gantt-error,
.gantt-empty {
    padding: 24px 16px;
    color: #6b7280;
    text-align: center;
}
.gantt-error { color: #b91c1c; }

/* ----- Toolbar ----- */
.gantt-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.gantt-zoom {
    display: inline-flex;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    overflow: hidden;
}
.gantt-zoom-btn {
    padding: 6px 12px;
    background: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: #374151;
}
.gantt-zoom-btn.active { background: #2563eb; color: #fff; }
.gantt-group-select,
.gantt-today-btn {
    padding: 6px 10px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
}
.gantt-hint {
    font-size: 0.8rem;
    color: #6b7280;
}

/* ----- Área scrolleable ----- */
.gantt-scroll {
    overflow: auto;
    max-height: calc(100vh - 260px);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    /* El scroll táctil es del contenedor; el arrastre se captura sólo en las
       asas (touch-action: none abajo). Mismo criterio que el tablero. */
    -webkit-overflow-scrolling: touch;
}
.gantt-grid {
    min-width: calc(var(--gantt-label-w) + var(--gantt-track-w));
    width: max-content;
}

/* ----- Encabezado ----- */
.gantt-header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.gantt-header-corner {
    flex: 0 0 var(--gantt-label-w);
    width: var(--gantt-label-w);
    position: sticky;
    left: 0;
    z-index: 4;
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
}
.gantt-header-bands { flex: 0 0 auto; }
.gantt-band { display: flex; }
.gantt-cell {
    flex: 0 0 auto;
    box-sizing: border-box;
    font-size: 0.72rem;
    color: #4b5563;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    border-right: 1px solid #eef0f3;
    padding: 2px 0;
}
.gantt-cell-macro {
    font-weight: 700;
    color: #111827;
    border-right-color: #d1d5db;
}
.gantt-cell-micro { border-bottom: none; }

/* ----- Filas ----- */
.gantt-rows { position: relative; }

.gantt-group-header {
    display: flex;
    position: sticky;
    left: 0;
    z-index: 2;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
}
.gantt-group-label {
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #374151;
    white-space: nowrap;
}
.gantt-group-count {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    border-radius: 9px;
    background: #e5e7eb;
    font-size: 0.7rem;
    color: #4b5563;
}

.gantt-row {
    display: flex;
    align-items: stretch;
    min-height: var(--gantt-row-h);
    border-bottom: 1px solid #f3f4f6;
}
.gantt-row-label {
    flex: 0 0 var(--gantt-label-w);
    width: var(--gantt-label-w);
    position: sticky;
    left: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    box-sizing: border-box;
}
.gantt-row-title {
    font-size: 0.82rem;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gantt-row-detail {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
}
.gantt-row-track {
    position: relative;
    flex: 0 0 auto;
    /* Trama de fondo: una línea por día, del ancho del zoom actual. */
    background-image: linear-gradient(to right, #f1f3f5 1px, transparent 1px);
    background-size: var(--gantt-day-w) 100%;
}

/* Marcador del día de hoy: una sola columna sobre toda la altura. */
.gantt-today-line {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 1;
    background: rgba(37, 99, 235, 0.08);
    border-left: 2px solid #2563eb;
    pointer-events: none;
}

/* ----- Barras ----- */
.gantt-bar {
    position: absolute;
    top: 5px;
    height: calc(var(--gantt-row-h) - 10px);
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 6px;
    border-radius: 5px;
    background: #64748b;
    color: #fff;
    font-size: 0.76rem;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    z-index: 2;
}
.gantt-bar-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}
.gantt-bar-chips {
    display: inline-flex;
    gap: 4px;
    flex: 0 0 auto;
}
.gantt-bar .stage-chip,
.gantt-bar .tag-chip,
.gantt-bar .card-nivel-badge { transform: scale(0.85); }

/* Recortada contra el borde de la ventana: se dibuja abierta de ese lado. */
.gantt-bar.is-clipped-start { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.gantt-bar.is-clipped-end   { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* Color por estado, en línea con las columnas del tablero. */
.gantt-bar.gantt-status-pending    { background: #6b7280; }
.gantt-bar.gantt-status-doing      { background: #2563eb; }
.gantt-bar.gantt-status-team-doing { background: #7c3aed; }
.gantt-bar.gantt-status-blocked    { background: #b91c1c; }
.gantt-bar.gantt-status-needs-work { background: #d97706; }
.gantt-bar.gantt-status-completed  { background: #15803d; }

.gantt-bar-readonly { opacity: 0.65; }

/* El asa es el ÚNICO punto que captura el gesto táctil: el resto de la barra
   deja pasar el scroll horizontal del contenedor (ver commit 92668fc). */
.gantt-bar-handle,
.gantt-tray-handle {
    flex: 0 0 auto;
    border: none;
    background: rgba(255, 255, 255, 0.22);
    color: inherit;
    border-radius: 3px;
    padding: 0 3px;
    cursor: grab;
    font-size: 0.72rem;
    line-height: 1.4;
    touch-action: none;
}
.gantt-tray-handle { background: #e5e7eb; color: #374151; }
.is-dragging .gantt-bar-handle { cursor: grabbing; }

.gantt-bar-grip {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    touch-action: none;
    background: rgba(255, 255, 255, 0.25);
}
.gantt-grip-start { left: 0; border-radius: 5px 0 0 5px; }
.gantt-grip-end   { right: 0; border-radius: 0 5px 5px 0; }

/* ----- Bandeja "Sin planificar" ----- */
.gantt-tray {
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px dashed #d0d7de;
    border-radius: 8px;
    background: #fafbfc;
}
.gantt-tray-header {
    font-weight: 700;
    font-size: 0.82rem;
    color: #374151;
    margin-bottom: 8px;
}
.gantt-tray-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.gantt-tray-card {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    font-size: 0.78rem;
    color: #111827;
    max-width: 260px;
}
.gantt-tray-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gantt-tray-detail {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.gantt-tray-readonly { opacity: 0.6; }
.gantt-tray-hint {
    margin: 8px 0 0;
    font-size: 0.75rem;
    color: #6b7280;
}

/* ----- Modal de fechas (camino táctil) ----- */
.gantt-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(17, 24, 39, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.gantt-modal {
    width: min(380px, 100%);
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.gantt-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #e5e7eb;
}
.gantt-modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gantt-modal-close {
    border: none;
    background: none;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
}
.gantt-modal-body { padding: 14px; }
.gantt-modal-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.gantt-modal-field span { font-size: 0.85rem; color: #374151; }
.gantt-modal-field input {
    padding: 6px 8px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
}
.gantt-modal-error {
    margin: 4px 0 0;
    font-size: 0.78rem;
    color: #b91c1c;
}
.gantt-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #e5e7eb;
}
.gantt-modal-footer button {
    padding: 8px 14px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
}
.gantt-modal-save {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.gantt-modal-clear { color: #b91c1c; border-color: #fecaca; }

/* ----- Responsive ----- */
@media (max-width: 640px) {
    .gantt-root { --gantt-label-w: 120px; }
    .gantt-hint { display: none; }
    .gantt-scroll { max-height: calc(100vh - 300px); }
}
